Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  optimization insde a "for all" cicle

    Posted 02/06/14 06:28 AM

    Originally posted by: pdst12005


    Hello everyone.

    I have a huge matrix of decision variables (binary). To each variable there is a date associated thus I would like to run the optimization for each day (it is 6 years so I would need it automated).

    I though I could maybe use a for all cicle, e.g:

    Xij (1 if record i connects with record j, 0 if not)

    Di (date of records i)

    Dj (date of records j)

    For all Di=Dj

        Max Sum Xij*

        constrains:

        (...)

    end for all.

     

    But I am not sure if this is possible, or if there is a simpler way. For instances, programing several optimizations, one for each day.

     

    Thanks in advance


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: optimization insde a "for all" cicle

    Posted 02/06/14 12:32 PM

    Originally posted by: davidoff


    Look at the mulprod sample in the opl examples that illustrate how you change the model and relaunch successive optimization. Basically, there are two ways to do this in OPL,

    1) change the data, regenerate a new model from the same definition and an updated data elements.

    2) change the coefficients or bounds directly in the extracted model and re run

    Hope this helps

    David

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: optimization insde a "for all" cicle

    Posted 02/06/14 04:12 PM

    Originally posted by: pdst12005


    Thanks. I though of this but the problem is that I have 365*6 days to individualy optimize thus I wondered if there was a way to automaticaly do this from the main data.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: optimization insde a "for all" cicle

    Posted 02/06/14 02:13 PM

    Originally posted by: fbahr


    Basically... what @davidoff already said -- just adding an OPL script example.

    Assuming you had your model in "model.mod", general data definitions in "data.dat", and day-specific inputs in files "day1.dat" .. "day7.dat", you would create a new .mod file, say main.mod, with:

    main
    {
        var cplex       = new IloCplex();
        var data_common = new IloOplDataSource("data.dat");
        var model_def   = new IloOplModelDefinition(new IloOplModelSource("model.mod"));
        var oplmodel;
        for (var run = 1; run <= 7; run++)
        {
            cplex.clearModel();
            oplmodel = new IloOplModel(model_def,cplex);
            oplmodel.addDataSource(data_common);
            oplmodel.addDataSource(new IloOplDataSource("day" + run + ".dat"));
            oplmodel.generate();
            if (cplex.solve())
                writeln(cplex.getBestObjValue());
            oplmodel.end();
        }
        // data_common.end();
        // ...
        cplex.end();
    }
    

    --fbahr

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: optimization insde a "for all" cicle

    Posted 02/06/14 04:27 PM

    Originally posted by: pdst12005


    And is there a scrip to generate the individual data files?

    What I have is a excel sheet with records in each lines and columns would be date and other parameters. So I would need to add a scrip for cplex doing this.

    (I could do it using other program but my point is if there is a way to do it with cplex, and reproduce in case I would get a diferent dataset).

     

    Still I am already very thankful for yours and @davidoff help.

    additional information:

    What I need to do is not so hard. Simply a max function with decision variable being if record i match record j. But I have like 50k reocrds in each i and j sets, thus this would be huge computing amount. What I try to do is to use a blocking variable to reduce the number "comparisons" that is the date (day). This means if day i is different from day j there will be no match for sure. But adding it as constrain would it be enough to reduce the computing?

     

    Either way I will try making the full model and give it some tries and consider your solution by using just a simple exemple with few days.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: optimization insde a "for all" cicle

    Posted 02/08/14 10:47 AM

    Originally posted by: fbahr


    > What I have is a excel sheet with records in each lines and columns would be date and other parameters

    In that particular case, I'd probably let Excel do the preprocessing for me -- something like the VBA script below will split your worksheet (given that its entries are ordered by date) into multiple worksheets (one for each day, labelled 'Day_1', 'Day_2', ..., 'Day_2190', and with cell(A1) = # entries per day).

    Sub SplitData()
        Application.ScreenUpdating = False
    
        Dim Days As Collection
        Set Days = New Collection
        Dim WSID As Integer
        WSID = 1
    
        Dim SourceSheet, TargetSheet As Worksheet
    
        Set SourceSheet = Worksheets( ... ) '< worksheet name
        Dim SourceRow, TargetRow As Long
        Const Col As String = "A"
        Const FirstRow As Integer = 1 '< offset
        Dim LastRow As Long
    
        LastRow = SourceSheet.Cells(SourceSheet.Rows.Count, Col).End(xlUp).Row
        Dim DayStr As String
    
        For SourceRow = FirstRow To LastRow
            Set TargetSheet = Nothing
    
            DayStr = SourceSheet.Cells(SourceRow, Col).Value
    
            On Error Resume Next
            Set TargetSheet = Worksheets("Day_" & Days.Item(DayStr))
            On Error GoTo 0
    
            If TargetSheet Is Nothing Then
                Days.Add CStr(WSID), DayStr
    
                Set TargetSheet = Worksheets.Add(After:=Worksheets(Worksheets.Count))
                TargetSheet.Name = "Day_" & CStr(WSID)
                TargetSheet.Range("A1").Value = 0
                WSID = WSID + 1
    
            End If
    
            TargetRow = TargetSheet.Cells(TargetSheet.Rows.Count, Col).End(xlUp).Row + 1
            SourceSheet.Rows(SourceRow).Copy Destination:=TargetSheet.Rows(TargetRow)
            TargetSheet.Range("A1").Value = TargetSheet.Range("A1").Value + 1
    
        Next SourceRow
    
        Application.ScreenUpdating = True
    End Sub
    

    Then, main.mod can be updated as follows:

    main
    {
        var cplex       = new IloCplex();
        var model_def   = new IloOplModelDefinition(new IloOplModelSource("model.mod"));
        var model_dat   = new IloOplDataSource("data.dat");   
        var basic_model = new IloOplModel(model_def,cplex);
        basic_model.addDataSource(model_dat);
        basic_model.generate();
        for (var run = 1; run <= 2190; run++)
        {
            cplex.clearModel();
            var custom_def = basic_model.modelDefinition;
            var custom_dat = basic_model.dataElements;
            var custom_mod = new IloOplModel(custom_def,cplex);
            custom_dat.wsid = "Day_" + run;
            custom_mod.addDataSource(custom_dat);
            custom_mod.generate();
            if (cplex.solve())
                writeln(cplex.getBestObjValue(<wbr>));
            custom_mod.end();
        }
        basic_model.end();
        cplex.end();
    }
    

    with [model.mod]

    string wsid = "Day_1";
    string rows = ...;
    ...
    

    and [data.dat]

    SheetConnection sheet(" ... ");
    rows from SheetRead(sheet,wsid + '!A1");
    tuples from SheetRead(sheet,"wsid + '!A2:Z" + rows);
    ...
    

    --fbahr


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: optimization insde a "for all" cicle

    Posted 02/08/14 10:57 AM

    Originally posted by: pdst12005


    Thank you very much for your important help.

     

    Best regards,

    Marco Amorim


    #DecisionOptimization
    #OPLusingCPLEXOptimizer