Topic
  • 3 replies
  • Latest Post - ‏2013-07-02T09:44:12Z by Philippe_Refalo
Hosssein
Hosssein
26 Posts

Pinned topic Correcting the objective function iteratively

‏2013-06-20T19:03:58Z |

Hi,

I am solving a CP model iteratively with same variables and constraints but different objective functions. The structure of the objective function does not change. The only things that change, from an iteration to the next, are the data arrays based on which the objective function is created in each iteration.

In my current implementation, in each iteration I delete the previous objective function and add a new objective function with new data arrays which is very time consuming.  Actually the objective is very huge and its deletion is the source of long run time.

Is it possible just to change the data arrays in each iteration inside of the objective expression to correct the objective function rather than deleting the previous objective function and adding the new objective function?

An example of such objective function is as follows:

// W and S are variables
// D, P and L are data arrays
for (i = 0; i < n; i++){
       for (j = 0; j < m; j++){
               // D, P and L are updated here
               OBJECTIVE = -((S[i]+D[W[i]]>j)&&(S[i]<j))*P[L[W[i]]*j];
               //CP model is solved here
               OBJECTIVE.end();
       }
}


Thanks in advance for your comments.

Updated on 2013-06-20T19:23:28Z at 2013-06-20T19:23:28Z by Hosssein
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: Correcting the objective function iteratively

    ‏2013-06-25T16:36:22Z  

    It is not possible to change only the cofficient of these expression since they are encoded in a special way inside. They are not shared. So changing the values in an array will not have any effect. If this memory release take too much time, and if the objective is an important part of the model (in terms of number of subexpressions) then you should consider destroying the whole model and even the environment and recreate everything at each iteration.

     

    Philippe

  • Hosssein
    Hosssein
    26 Posts

    Re: Correcting the objective function iteratively

    ‏2013-06-25T17:29:06Z  

    It is not possible to change only the cofficient of these expression since they are encoded in a special way inside. They are not shared. So changing the values in an array will not have any effect. If this memory release take too much time, and if the objective is an important part of the model (in terms of number of subexpressions) then you should consider destroying the whole model and even the environment and recreate everything at each iteration.

     

    Philippe

    Thank you for your reply. It is actually what I am doing currently in my model. The problem is that deleting environment with .end() is very time consuming. Is there any special command in c++ to delete the environment faster than .end() ?

    Thank you for all of your helps.

  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: Correcting the objective function iteratively

    ‏2013-07-02T09:44:12Z  
    • Hosssein
    • ‏2013-06-25T17:29:06Z

    Thank you for your reply. It is actually what I am doing currently in my model. The problem is that deleting environment with .end() is very time consuming. Is there any special command in c++ to delete the environment faster than .end() ?

    Thank you for all of your helps.

    Unless your model is really huge (can you give us its size ?) env.end() should not take long, but unfortunately, there is no other way to release the memory.

    Philippe