Topic
  • 6 replies
  • Latest Post - ‏2014-03-20T08:54:42Z by xoftmade
khan49
khan49
3 Posts

Pinned topic Modifying constraints ??

‏2013-12-30T15:35:23Z |

Hello  All!

I am using CP optimizer to get multiple solution of a constraint satisfaction problem. but due its size I am interested to solve sequentially i.e. get an a solution for first period and then fixed the binary variables that are assigned to the first period and then to move to the next period and so on. I know there are modifiers for fixing the extracted variables values , but I am interested to know that

 

it it possible to modify a constraint as well

 

like just modify the RHS of a an extracted constraint 

 

or

delete a constraint and add a new constraint with the desired RHS to engine directly  

 

Kindly let me know if know you know something about it.

 

Kind regards 

  • AlexFleischer
    AlexFleischer
    15 Posts

    Re: Modifying constraints ??

    ‏2013-12-31T10:59:01Z  

    Hi,

    let me give you a small example:

     

    using CP;
     
     dvar int x in 0..4;
     
     maximize x;
     subject to
     {
      ct:x<=2;
     }  
     
     execute
     {
     writeln(x);
    }  
     
     main
     
     {
       thisOplModel.generate();
       cp.solve();
       writeln(thisOplModel.x);
       thisOplModel.ct.UB=3;
       cp.solve();
        writeln(thisOplModel.x);
       
     }   
     
     

     

    gives

     

    2

     

    and then

    3

    Regards

    Updated on 2013-12-31T11:01:25Z at 2013-12-31T11:01:25Z by AlexFleischer
  • khan49
    khan49
    3 Posts

    Re: Modifying constraints ??

    ‏2013-12-31T13:20:05Z  

    Hi,

    let me give you a small example:

     

    using CP;
     
     dvar int x in 0..4;
     
     maximize x;
     subject to
     {
      ct:x<=2;
     }  
     
     execute
     {
     writeln(x);
    }  
     
     main
     
     {
       thisOplModel.generate();
       cp.solve();
       writeln(thisOplModel.x);
       thisOplModel.ct.UB=3;
       cp.solve();
        writeln(thisOplModel.x);
       
     }   
     
     

     

    gives

     

    2

     

    and then

    3

    Regards

    Hi Alex!

     

    Thanks for the reply , Basically I am writing my code using C++ concert technology . While doing different experiments I found out that  the value of variable can only be changed only one time using the engine variables corresponding to a decision variable.

    so then I thought there might be some way by using which I can remove a constraint and add a new constraint without extracting the whole model again and again by using the engine constraint .

     

    IloModel mod(env);
     
    // 1D Array of Variables
     
    IloNumVarArray B(env,Nblocks,0,1, ILOINT);
     
    IloExpr total_blocks(env);
     
    int i = 0;
     
    for(InputIterator current = start; current!= end ; current ++,i++){
     
    total_blocks += B[i]*BLOCK_TONNAGE;   
     
    }  
     
     
    mod.add(total_blocks <= upper_limmit);
    mod.add(total_blocks >= lower_limmit);
     
     
     
     
    // Slope Constraint
     
    for(int i = 0; i<Nblocks;i++){
     
        for(int j = 0; j < max_successor ; j++){
     
       if((Pre_deccessor_Matrix [i][j]!= -1)){
     
    mod.add(B[i] - B[j] <= 0);
     
    }
    }
     
    }
     
     
    IloCP cp(env);
    cp.extract(mod);
     
    cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet);
     
    int sol = 0;
    int t = 1;
     
    cp.startNewSearch();
    while(cp.next() && sol < N_Solutions && t < 3){
     
    for(int i = 0; i<Nblocks; i++){
     
      if (cp.getValue(B[i])>0){
     
      initial_solutions[sol][i] = t; 
     
    (cp.getIntVar(B[i])).setValue(1);
     
          }
    }
     
     
    t++;
     
    }

     

    after getting each solution I want to modify the RHS of capacity constraints to accommodate the variables already fixed to 1.

     

    Kindly let me know if there is any way to change the value of a variable multiple time using the engine variable if not 

     

    is there any procedure to delete a constraint or modify it using IlcConstraint .

     

    Kind regards 

  • GGR
    GGR
    62 Posts

    Re: Modifying constraints ??

    ‏2013-12-31T15:51:46Z  
    • khan49
    • ‏2013-12-31T13:20:05Z

    Hi Alex!

     

    Thanks for the reply , Basically I am writing my code using C++ concert technology . While doing different experiments I found out that  the value of variable can only be changed only one time using the engine variables corresponding to a decision variable.

    so then I thought there might be some way by using which I can remove a constraint and add a new constraint without extracting the whole model again and again by using the engine constraint .

     

    IloModel mod(env);
     
    // 1D Array of Variables
     
    IloNumVarArray B(env,Nblocks,0,1, ILOINT);
     
    IloExpr total_blocks(env);
     
    int i = 0;
     
    for(InputIterator current = start; current!= end ; current ++,i++){
     
    total_blocks += B[i]*BLOCK_TONNAGE;   
     
    }  
     
     
    mod.add(total_blocks <= upper_limmit);
    mod.add(total_blocks >= lower_limmit);
     
     
     
     
    // Slope Constraint
     
    for(int i = 0; i<Nblocks;i++){
     
        for(int j = 0; j < max_successor ; j++){
     
       if((Pre_deccessor_Matrix [i][j]!= -1)){
     
    mod.add(B[i] - B[j] <= 0);
     
    }
    }
     
    }
     
     
    IloCP cp(env);
    cp.extract(mod);
     
    cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet);
     
    int sol = 0;
    int t = 1;
     
    cp.startNewSearch();
    while(cp.next() && sol < N_Solutions && t < 3){
     
    for(int i = 0; i<Nblocks; i++){
     
      if (cp.getValue(B[i])>0){
     
      initial_solutions[sol][i] = t; 
     
    (cp.getIntVar(B[i])).setValue(1);
     
          }
    }
     
     
    t++;
     
    }

     

    after getting each solution I want to modify the RHS of capacity constraints to accommodate the variables already fixed to 1.

     

    Kindly let me know if there is any way to change the value of a variable multiple time using the engine variable if not 

     

    is there any procedure to delete a constraint or modify it using IlcConstraint .

     

    Kind regards 

    Hi

    There is no way to remove a constraint in a model without re-extracting. The reason why is that after extraction and initial propagation the engine has taken account the to be removed constraints and must be totally reinitialized.

    Anyway in your case you could think in designing a model that iteratively solve a problem period by period.

    E.g for the first period having a model that work on affection on the first period or not and solve it. (basically there is two case for each affection). then the following period is a similar model with additional constraints that may come from the  affectation form the past period.

    That is a common practice in Mixed Integer Programming that you could exploit.

    Hope that helps

     

     

  • khan49
    khan49
    3 Posts

    Re: Modifying constraints ??

    ‏2014-01-07T12:44:53Z  
    • GGR
    • ‏2013-12-31T15:51:46Z

    Hi

    There is no way to remove a constraint in a model without re-extracting. The reason why is that after extraction and initial propagation the engine has taken account the to be removed constraints and must be totally reinitialized.

    Anyway in your case you could think in designing a model that iteratively solve a problem period by period.

    E.g for the first period having a model that work on affection on the first period or not and solve it. (basically there is two case for each affection). then the following period is a similar model with additional constraints that may come from the  affectation form the past period.

    That is a common practice in Mixed Integer Programming that you could exploit.

    Hope that helps

     

     

    Hi!

     

    Thanks for the reply, can you please explain the procedure you have proposed.

    with an example as I am unable to understand it.

     

    Kind regards 

  • rdumeur
    rdumeur
    109 Posts

    Re: Modifying constraints ??

    ‏2014-01-08T10:13:17Z  
    • khan49
    • ‏2014-01-07T12:44:53Z

    Hi!

     

    Thanks for the reply, can you please explain the procedure you have proposed.

    with an example as I am unable to understand it.

     

    Kind regards 

    Hi,

    I believe GGR suggests that you generate multiple models (one per period) and "stitch" them by adding in model of period t+1 constraints that assign variables of this model that were assigned by the previously solved model for period t.

    Am I right GGR?

     

    Cheers,

  • GGR
    GGR
    62 Posts

    Re: Modifying constraints ??

    ‏2014-01-10T17:24:11Z  
    • rdumeur
    • ‏2014-01-08T10:13:17Z

    Hi,

    I believe GGR suggests that you generate multiple models (one per period) and "stitch" them by adding in model of period t+1 constraints that assign variables of this model that were assigned by the previously solved model for period t.

    Am I right GGR?

     

    Cheers,

    Hi

    You have got the point. Anyway, I suggest to relax the far away problem,  being correct by only considering the next open periods.For example, you may want to make optional the demand that are not urgent and iteratively repeat the process.

    Anyway my proposal is not necessarely a solution for the problem of Khan49. It is only the classical way big timetatble constraints are made tractable.

     

    Hope that helps