Decision Optimization

 View Only
Expand all | Collapse all

I can not set a starting point for an interval dvar using CP Optimizer

  • 1.  I can not set a starting point for an interval dvar using CP Optimizer

    Posted Mon September 28, 2020 07:44 AM
    Hello Community:

    I want to set a starting point for an openshop model. In the model I have (among others) the following decision variable:

    dvar interval itvs[j in Jobs][m in Mchs] size OpDurations[j][m];

    Using a greedy heuristic I calculated values for the start time of every operation startOf(itvs[j in Jobs][m in Mchs]). This value of startOf(itvs[j in Jobs][m in Mchs]) I want to use it as a starting point for continuing the search using CP solver.

    Below I include the .mod and .dat file (.dat file for an instance of 4 jobs and 4 machines). The previously calculated values for startOf(itvs[j in Jobs][m in Mchs]) I want to read it from an Excel sheet (in this example in a 4x4 matrix) as detailed in .dat file.

    But when I try to run my program I get two warnings that show in the following image:
    Could you please explain to me how can I fix that?. What piece of code do I need to adjust to the .mod and/or .dat file?

    Thanks in advance
    F. Yuraszeck

    // OPENSHOP .MOD FILE using CP; int nbJobs = ...; int nbMchs = ...; range Jobs = 0..nbJobs-1; range Mchs = 0..nbMchs-1; int OpDurations[j in Jobs][m in Mchs] = ...; dvar interval itvs[j in Jobs][m in Mchs] size OpDurations[j][m]; dvar sequence mchs[m in Mchs] in all(j in Jobs) itvs[j][m] types all(j in Jobs) j; dvar sequence jobs[j in Jobs] in all(m in Mchs) itvs[j][m]; int values[j in Jobs][m in Mchs] = ...; execute { cp.param.TimeLimit = 5; } minimize sum(j in Jobs) (max(m in Mchs) endOf(itvs[j][m])); subject to { forall (j in Jobs) noOverlap(jobs[j]); forall (m in Mchs) noOverlap(mchs[m]); } execute { for (j in Jobs) for (m in Mchs) write(Opl.startOf(itvs[j][m]), " "); writeln(); } main { thisOplModel.generate(); var sol = new IloOplCPSolution(); for (j in Jobs) for (m in Mchs) sol.setStart(thisOplModel.itvs[j][m],thisOplModel.values[j][m]); cp.solve; thisOplModel.postProcess(); cp.setStartingPoint(sol); cp.solve(); thisOplModel.postProcess(); } // OPENSHOP .DAT FILE nbJobs = 4; nbMchs = 4; OpDurations = [ [34, 2, 54, 61] [15, 89, 70, 9] [38, 19, 28, 87] [95, 7, 34, 29] ]; SheetConnection sheet("myExcelFile.xlsx"); values from SheetRead(sheet,"'st'!B2:E5");

    ------------------------------
    F. Yuraszeck
    ------------------------------

    #DecisionOptimization


  • 2.  RE: I can not set a starting point for an interval dvar using CP Optimizer

    Posted Tue September 29, 2020 03:03 AM
    Hi,
    instead of 

    for j in jobs

    you should rather write

    for j in thisOplModel.jobs

    since jobs is an object that belongs to the model.

    ------------------------------
    ALEX FLEISCHER
    ------------------------------



  • 3.  RE: I can not set a starting point for an interval dvar using CP Optimizer

    Posted Tue September 29, 2020 10:04 AM
    Thank you Alex.

    I made the following changes in my .mod file (BTW I think there is for j in thisOplModel.Jobs instead for j in thisOplModel.jobs):


    My .dat file is the same:


    But I'm still having a syntax issue:
    Do you see what is wrong with my code?

    Thanks again
    Francisco




    ------------------------------
    Francisco Yuraszeck
    Yuraszeck
    ------------------------------



  • 4.  RE: I can not set a starting point for an interval dvar using CP Optimizer

    Posted Tue September 29, 2020 10:30 AM
    Edited by System Fri January 20, 2023 04:11 PM
    Hi

    .mod

    using CP;

    int nbJobs = ...;
    int nbMchs = ...;

    range Jobs = 0..nbJobs-1;
    range Mchs = 0..nbMchs-1;

    int OpDurations[j in Jobs][m in Mchs] = ...;

    dvar interval itvs[j in Jobs][m in Mchs] size OpDurations[j][m];
    dvar sequence mchs[m in Mchs] in all(j in Jobs) itvs[j][m] types all(j in Jobs) j;
    dvar sequence jobs[j in Jobs] in all(m in Mchs) itvs[j][m];

    int values[j in Jobs][m in Mchs] = ...;

    execute {
    cp.param.TimeLimit = 5;
    }

    minimize sum(j in Jobs) (max(m in Mchs) endOf(itvs[j][m]));
    subject to {
    forall (j in Jobs)
    noOverlap(jobs[j]);
    forall (m in Mchs)
    noOverlap(mchs[m]);
    }

    execute {
    writeln("sol");
    for (j in Jobs)
    for (m in Mchs)
    write(Opl.startOf(itvs[j][m]), " ");
    writeln();
    }

    main {
    thisOplModel.generate();
    var sol = new IloOplCPSolution();
    for (j in thisOplModel.Jobs)
    for (m in thisOplModel.Mchs)
    sol.setStart(thisOplModel.itvs[j][m],thisOplModel.values[j][m]);
    if (cp.solve()!=0)
    thisOplModel.postProcess();
    cp.setStartingPoint(sol);
    cp.solve();
    if (cp.solve()!=0)
    thisOplModel.postProcess();
    }



    .dat

    // OPENSHOP .DAT FILE
    nbJobs = 4;
    nbMchs = 4;

    OpDurations = [
    [34, 2, 54, 61]
    [15, 89, 70, 9]
    [38, 19, 28, 87]
    [95, 7, 34, 29]
    ];


    values =[];

    // END OF .DAT FILE


    work fine



    ------------------------------
    ALEX FLEISCHER
    ------------------------------