Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Export Interval Variable to Excel

    Posted Sat May 30, 2015 05:36 PM

    Originally posted by: Mclovin


    Hi community, I am new to CP.

    I need export interval variable to excel from CPLEX. 

    How write the code for export this to excel "modes[m].start" 

    Thanks

    The model is:

     

    using CP;

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

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

    tuple Operation {
      int id;    // Operation id
      int jobId; // Job id
      int pos;   // Position in job
    };

    tuple Mode {
      int opId; // Operation id
      int mch;  // Machine
      int pt;   // Processing time
    };

    {Operation} Ops   = ...;
    {Mode}      Modes = ...;

    // Position of last operation of job j
    int jlast[j in Jobs] = max(o in Ops: o.jobId==j) o.pos;

    dvar interval ops  [Ops]; 
    dvar interval modes[md in Modes] optional size md.pt;
    dvar sequence mchs[m in Mchs] in all(md in Modes: md.mch == m) modes[md];

    execute {
              cp.param.FailLimit = 10000;
    }

    minimize max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
    subject to {
      forall (j in Jobs, o1 in Ops, o2 in Ops: o1.jobId==j && o2.jobId==j && o2.pos==1+o1.pos)
        endBeforeStart(ops[o1],ops[o2]);
      forall (o in Ops)
        alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
      forall (m in Mchs)
        noOverlap(mchs[m]);
    }

    execute {
      for (var m in Modes) {
        if (modes[m].present)
          writeln("Operation " + m.opId + " on machine " + m.mch + " starting at " + modes[m].start);
      }
    }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Export Interval Variable to Excel

    Posted Sun May 31, 2015 03:24 PM

    Hi,

    you should write all useful data in a tupleset and then in the .dat you could use SheetWrite to have this as output to excel.

    Have a look at the oil example in examples/opl

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Export Interval Variable to Excel

    Posted Mon June 01, 2015 08:13 AM

    Originally posted by: Mclovin


    Hi,

    I tried with this but i need export  the results for modes.[m].start.

    How write a tupleset for this?

    Regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Export Interval Variable to Excel

    Posted Mon June 01, 2015 03:33 PM

    Hi,

    for example if you take the example sched_alloc, you see

    dvar interval worker[Workers];

    and then in the postprocess you may add

    tuple resType
    {
    string worker;
    int st;
    }

    {resType} res={ <w,startOf(worker[w])> | w in Workers};

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 10:26 AM

    Originally posted by: Mclovin


    Hi alex,

    I tried with this code :

    dvar interval ops  [Ops]; 
    tuple resultado{
        int ops;
        int inicio;
    }
    {resultado} res = {<o,startOf(ops[o])> | o in Ops}; 

     

    But Cplex throw a error  "Decision variable (or expression) "ops" not allowed." Can you help me with the creation of the tupleset, because I need the start time for operation(Model in Cplex is sched_jobshopflexible) and then export to excel.

    Regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 11:19 AM

     

    Hi,

    Hi,

    when I wrote you should write the following in the postprocess I meant after the subject to block. Have you done that ?

    regards

    tuple resType
    {
    string worker;
    int st;
    }

    {resType} res={ <w,startOf(worker[w])> | w in Workers};

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 11:30 AM

    Originally posted by: Mclovin


    yes, like this: 

    using CP;
    int nbJobs = ...;
    int nbMchs = ...;
    range Jobs = 1..nbJobs;
    range Mchs = 1..nbMchs;

     

    tuple Operation {
      int id;    // Operation id
      int jobId; // Job id
      int pos;   // Position in job
    };
    tuple Mode {
      int opId; // Operation id
      int mch;  // Machine
      int pt;   // Processing time
    };
    {Operation} Ops   = ...;
    {Mode}      Modes = ...;

     

    // Position of last operation of job j
    int jlast[j in Jobs] = max(o in Ops: o.jobId==j) o.pos;

     
    dvar interval ops  [Ops]; 
    tuple resultado{
        int ops;
        int opId;
    }
    {resultado} res = {<o,startOf(ops[o])> | o in Ops};

    dvar interval modes[md in Modes] optional size md.pt;
    dvar sequence mchs[m in Mchs] in all(md in Modes: md.mch == m) modes[md];

    execute {
              cp.param.FailLimit = 10000;
    }

    minimize max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
    subject to {
      forall (j in Jobs, o1 in Ops, o2 in Ops: o1.jobId==j && o2.jobId==j && o2.pos==1+o1.pos)
        endBeforeStart(ops[o1],ops[o2]);
      forall (o in Ops)
        alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
      forall (m in Mchs)
        noOverlap(mchs[m]);

        
    }

    execute {
      for (var m in Modes) {
        if (modes[m].present)
          writeln("Operation " + m.opId + " on machine " + m.mch + " starting at " + modes[m].start);
      }
    }

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 12:09 PM

    Hi,

    so please write

    {resultado} res = {<o,startOf(ops[o])> | o in Ops};

     

    after the subject to block and not before as you did.

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 02:41 PM

    Originally posted by: Mclovin


    Hi, 

    When put  this {resultado} res = {<o,startOf(ops[o])> | o in Ops}; after the subject to, Cplex throw a new error "syntax error, unexpected (identifier)". Help me please.

     

    For model :

     

    using CP;
    int nbJobs = ...;
    int nbMchs = ...;
    range Jobs = 1..nbJobs;
    range Mchs = 1..nbMchs;

    tuple Operation {
      int id;    // Operation id
      int jobId; // Job id
      int pos;   // Position in job
    };
    tuple Mode {
      int opId; // Operation id
      int mch;  // Machine
      int pt;   // Processing time
    };

    {Operation} Ops   = ...;
    {Mode}      Modes = ...;

    // Position of last operation of job j
    int jlast[j in Jobs] = max(o in Ops: o.jobId==j) o.pos;

     
    dvar interval ops  [Ops]; 
    tuple resultado{
        int ops;
        int opId;
    }


    dvar interval modes[md in Modes] optional size md.pt;
    dvar sequence mchs[m in Mchs] in all(md in Modes: md.mch == m) modes[md];

    execute {
              cp.param.FailLimit = 10000;
    }

    minimize max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
    subject to {
      {resultado}res={<o,startOf(ops[o])> | o in Ops};
      
      forall (j in Jobs, o1 in Ops, o2 in Ops: o1.jobId==j && o2.jobId==j && o2.pos==1+o1.pos)
        endBeforeStart(ops[o1],ops[o2]);
      forall (o in Ops)
        alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
      forall (m in Mchs)
        noOverlap(mchs[m]);

        }

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 02:58 PM

    Hi,

    I meant

    minimize max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
    subject to {
     
      
      forall (j in Jobs, o1 in Ops, o2 in Ops: o1.jobId==j && o2.jobId==j && o2.pos==1+o1.pos)
        endBeforeStart(ops[o1],ops[o2]);
      forall (o in Ops)
        alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
      forall (m in Mchs)
        noOverlap(mchs[m]);

        }

    {resultado}res={<o,startOf(ops[o])> | o in Ops};

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 03:18 PM

    Originally posted by: Mclovin


    Hi

    I have the same problem but now is "Cannot use type {<<id:int,jobId:int,pos:int>,dexpr int>} for {resultado}." 

    for model:

     

    using CP;
    int nbJobs = ...;
    int nbMchs = ...;
    range Jobs = 1..nbJobs;
    range Mchs = 1..nbMchs;


    tuple Operation {
      int id;    // Operation id
      int jobId; // Job id
      int pos;   // Position in job
    };
    tuple Mode {
      int opId; // Operation id
      int mch;  // Machine
      int pt;   // Processing time
    };

    {Operation} Ops   = ...;
    {Mode}      Modes = ...;

    // Position of last operation of job j
    int jlast[j in Jobs] = max(o in Ops: o.jobId==j) o.pos;

     
    dvar interval ops  [Ops]; 
    tuple resultado{
        int ops;
        int opId;
    }


    dvar interval modes[md in Modes] optional size md.pt;
    dvar sequence mchs[m in Mchs] in all(md in Modes: md.mch == m) modes[md];

    execute {
              cp.param.FailLimit = 10000;
    }

    minimize max(j in Jobs, o in Ops: o.pos==jlast[j]) endOf(ops[o]);
    subject to {
      forall (j in Jobs, o1 in Ops, o2 in Ops: o1.jobId==j && o2.jobId==j && o2.pos==1+o1.pos)
        endBeforeStart(ops[o1],ops[o2]);
      forall (o in Ops)
        alternative(ops[o], all(md in Modes: md.opId==o.id) modes[md]);
      forall (m in Mchs)
        noOverlap(mchs[m]);

    }

    {resultado}res={<o,startOf(ops[o])> | o in Ops};  

    execute {
      for (var m in Modes) {
        if (modes[m].present)
          writeln("Operation " + m.opId + " on machine " + m.mch + " starting at " + modes[m].start);
      }
    }

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: Export Interval Variable to Excel

    Posted Tue June 02, 2015 03:28 PM

    Hi

    instead of

    {resultado}res={<o,startOf(ops[o])> | o in Ops};  

    you should write

    {resultado}res={<o.id,startOf(ops[o])> | o in Ops};  

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: Export Interval Variable to Excel

    Posted Wed June 03, 2015 10:13 AM

    Originally posted by: Mclovin


    Hi Alex

     

    Now is working.

    Thanks so much


    #DecisionOptimization
    #OPLusingCPLEXOptimizer