[FlopCpp] Deleting a model

gemiel at impa.br gemiel at impa.br
Tue Sep 14 12:58:49 EDT 2010


Thanks Christian,

Unfortunatly I still observe the same phenomena : the memory used by  
the program is still increasing after each loop.
Maybe one should explicitely delete the MP_data, MP_var and  
MP_constraints after each loop-iteration ?

Gregory
_________________________________________________
#include "flopc.hpp"
using namespace flopc;
#include "OsiCbcSolverInterface.hpp"

int main() {

for (int i=1; i<100000 ; i++)
{
	MP_model loopModel(new OsiCbcSolverInterface() );
  	 loopModel.silent();
   	enum {nw,ne,se,sw,numK};

   	MP_set l(4);  // identfiers for level row and column labels  / 1*4 /;

   	MP_index i,j;

   	MP_data conc(l,l,l);

   conc(0,0,0) =  1.5;
   conc(0,0,1) =  1.5;
   conc(0,0,2) =  1.5;
   conc(0,0,3) =  0.75;

   conc(0,1,0) =  1.5;
   conc(0,1,1) =  2.0;
   conc(0,1,2) =  1.5;
   conc(0,1,3) =  0.75;

   conc(0,2,0) =  1.0;
   conc(0,2,1) =  1.0;
   conc(0,2,2) =  0.75;
   conc(0,2,3) =  0.50;

   conc(0,3,0) =  0.75;
   conc(0,3,1) =  0.75;
   conc(0,3,2) =  0.5;
   conc(0,3,3) =  0.25;

   conc(1,0,0) =  4;
   conc(1,0,1) =  4;
   conc(1,0,2) =  2;

   conc(1,1,0) =  3;
   conc(1,1,1) =  3;
   conc(1,1,2) =  1;

   conc(1,2,0) =  2;
   conc(1,2,1) =  2;
   conc(1,2,2) =  0.5;

   conc(2,0,0) =  12;
   conc(2,0,1) =  6;

   conc(2,1,0) =  5;
   conc(2,1,1) =  4;

   conc(3,0,0) =  6;

   MP_set  k(numK); //  location of four neighbouring blocks / nw,  
"ne", se, sw /
   MP_subset<3> c(l,l,l); //  neighbouring blocks related to  
extraction feasibility
   MP_subset<3> d(l,l,l); //  complete set of block identifiers

   MP_data li(k), // lead for i  / (se,sw)  = 1 /
     lj(k),     // lead for j  / ("ne",se) = 1 /
     cost(l);   // block extraction cost  / 1=3000, 2=6000, 3=8000, 4=10000 /

   li(se) = 1;
   li(sw) = 1;
   lj(ne) = 1;
   lj(se) = 1;

   cost(0) = 3000;
   cost(1) = 6000;
   cost(2) = 8000;
   cost(3) =10000;

   double value = 200000;

   forall(l*l(i)*l(j).such_that( l+i<l.size()-1 && l+j<l.size()-1 ),
	 c.insert(l,i,j)
	 );

  // c.display("c");

   forall(l*l(i)*l(j).such_that( l+i<l.size() && l+j<l.size() ),
	 d.insert(l,i,j)
	 );

   MP_variable x(l,l,l); //   extraction of blocks
   MP_constraint pr(k,c); //  precedence relationships

   pr(k,c(l,i,j)) = x(l,i+li(k),j+lj(k)) >= x(l+1,i,j);
   x.upperLimit(l,i,j) = 1;

   loopModel.maximize( sum(d(l,i,j), (conc(l,i,j)*value/100 -  
cost(l))*x(l,i,j)) );
  // loopModel.detach() ;
   cout<<"Test mine  passed."<<endl;
	}
}

Quoting Christian Wolf <kalmar at uni-paderborn.de>:

>  Hi Gregory,
>
> you could define a new MP_model for every loop.
> If you do it like this, you can not use the MP_model::getDefaultModel
> anymore to get access to the MP_model, but either the loopModel defined
> below or MP_model::getCurrentModel, which points to the last MP_model
> created.
>
>
> for (int i=1; i<100000 ; i++)
> {
>    MP_model loopModel(new OsiCbcSolverInterface() );
>
>    enum {nw,ne,se,sw,numK};
>    MP_set l(4);  // identfiers for level row and column labels  / 1*4 /;
>    MP_index i,j;
>    MP_data conc(l,l,l);
>
> ... etc ...
>
>    maximize( sum(d(l,i,j), (conc(l,i,j)*value/100 - cost(l))*x(l,i,j)) );
>    cout<<"Test mine "<<  i<<  " passed."<<endl;
>   }
>
>
> Please let me know if this helps,
> Christian
>
>
> Am 13.09.2010 23:25, schrieb gemiel at impa.br:
>> Hi,
>>
>> I have a question regarding memory management in FlopCPP.
>> Basically I am defining and solving many LPs in a loop and I would
>> like to be sure that everything is deleted after each loop iteration.
>> It does not seem to be the case since the memory used by the program
>> keeps increasing.
>>
>> I reproduced this behavior with the 'mine.cpp' example:
>> _____________________________________________________
>> for (int i=1; i<100000 ; i++)
>> {
>>    MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
>>
>>    enum {nw,ne,se,sw,numK};
>>    MP_set l(4);  // identfiers for level row and column labels  / 1*4 /;
>>    MP_index i,j;
>>    MP_data conc(l,l,l);
>>
>> ... etc ...
>>
>>    maximize( sum(d(l,i,j), (conc(l,i,j)*value/100 - cost(l))*x(l,i,j)) );
>>    cout<<"Test mine "<<  i<<  " passed."<<endl;
>> }
>> ________________________________________________________
>>
>> I tried to add ' MP_model::getDefaultModel().detach(); ' but it did  
>>  not help.
>> What should I do to be sure to delete all objects that are
>> instantiated in the loop ?
>>
>> Thanks.
>>
>> Regards.
>>
>> Gregory
>>
>> ----------------------------------------------------------------
>> This message was sent using IMP, the Internet Messaging Program.
>>
>>
>>
>> _______________________________________________
>> FlopCpp mailing list
>> FlopCpp at list.coin-or.org
>> http://list.coin-or.org/mailman/listinfo/flopcpp



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.





More information about the FlopCpp mailing list