[Flopcpp] A FlopC++ Bug?

Tim Hultberg Tim.Hultberg at eumetsat.int
Mon Feb 27 08:00:02 EST 2006


I dont see why you wouldnt expect x(0,0,0,1) to be assigned,
because DG(0,1) is not inserted.

After all

AP_AlleEinplan(d,g).such_that(DG(d,g)) = sum(r,sum(t,  x(r,t,d,g)))==1;

,with DG(0,1) not inserted, means that x(0,0,0,1) is not present in any constraint and can therefore take any value (0 or 1).
(In your cost function x(0,0,0,1) doesnt enter either)

Hope this helps,
                             Tim


Tim Hultberg


>>> <WoelliUSM at aol.com> 27/02/2006 13:01 >>>
Dear all, 
 
somehow, this constraint doesn't work, because "x", a binary variable, is  
assigned where it shouldn't!!! To my mind, the ".such_that"-Statement is  
damaged.
 
The constraint is:
..
MP_constraint
AP_AlleEinplan(d,g);
..
AP_AlleEinplan(d,g).such_that(DG(d,g)) = sum(r,sum(t,  x(r,t,d,g)))==1;
..
 
This is the only constraint!! x is a binary variable. x is restricted by  
this constraint  to the set (r*t*d*g.such_that(DG)). How can it happen,  that x 
is assigned to one outside this set?
 
For example,
 
DG(0,0).insert;
 
DG(0,1), DG(0,2), DG(0,3), DG(0,4) are NOT inserted! They are not part of  
the subset DG!!
 
If I solve the model, I get the answer, that for example x(0,0,0,1) is  
assigned, that means, that DG(0,1) is inserted !? 
 
If I change that constraint to an equivalent constraint, everything runs  
fine!
 
The alternate constraint is:
 
..    
MP_constraint AP_AlleEinplan(d);
 
AP_AlleEinplan(d) = sum(r,sum(t, sum(g.such_that(DG(d,g)),  x(r,t,d,g))))==1;
 
The subset DG is now respected!
 
Is it maybe, that, as for example ".such_that(DG(dg)*DC(d,c))" doesn't  work, 
"such_that(DG(d,g)" is also affected?
 
I put the really small programm at the end of this message. I manipulated  
the code in that way, that the correct assignment are marked with a "1", the  
wrong assignments with a "4000".
 
Thanks for your help,
 
Greetings from cologne,
 
Christian
 
#include <OsiCbcSolverInterface.hpp>
#include  <flopc.hpp>
using namespace flopc;
 
main() {
MP_model m1(new OsiCbcSolverInterface);
 
MP_set t(6);
MP_set r(5);
MP_set d(5);
MP_set c(1);
MP_set  g(5);
 
MP_subset<2> DC(d,c); 
MP_subset<2> DG(d,g);
 
DG.insert(0,0);
DG.insert(1,1);
DG.insert(2,2);
DG.insert(3,3);
DG.insert(4,4);
 
forall(d, DC.insert(d,0));
 
MP_data pt(g), pr(g), pi(r,t,d,g);
 
pr(0)=0;
pr(1)=1;
pr(2)=3;
pr(3)=2;
pr(4)=2;
 
pt(0)=0;
pt(1)=1;
pt(2)=2;
pt(3)=3;
pt(4)=4;
 
for (int rr=0; rr<r.size(); rr++)
{ for (int tt=0;  tt<t.size(); tt++)
{ for (int dd=0; dd<d.size();  dd++)
{ for (int gg=0; gg<g.size();  gg++)
{ if  (DG(dd,gg)>-2)
{ if(tt==pt(gg))
{ pi(rr,tt,dd,gg)=1; }
else  
{ pi(rr,tt,dd,gg)=5; }
if  (rr <=  pr(gg))
{ pi(rr,tt,dd,gg)=pi(rr,tt,dd,gg)+5*(pr(gg)-rr); }
else
{ pi(rr,tt,dd,gg)=pi(rr,tt,dd,gg)+100*(rr-pr(gg)); }}
else
{ pi(rr,tt,dd,gg)=4000; } 
}
}
}
}
 
MP_binary_variable x(r,t,d,g);
 
MP_expression F;
 
MP_constraint AP_AlleEinplan(d,g);
 
AP_AlleEinplan(d,g).such_that(DG(d,g)) = sum(r,sum(t,x(r,t,DG)))==1;
 
F=(sum(r,sum(t,sum(c,sum(d.such_that(DC(d,c)),sum(g.such_that(DG(d,g)),  
pi(r,t,d,g)*x(r,t,d,g)))))));
 
m1.minimize(F);
 
for (int rr=0; rr<r.size(); rr++)
{ for (int tt=0;  tt<t.size(); tt++)
{ for (int dd=0; dd<d.size();  dd++)
{ for (int gg=0; gg<g.size();  gg++)
{ if (x.level(rr,tt,dd,gg)  ==1)
{ cout<<rr<<"  "<<tt<<" "<<dd<<" "<<gg<<"  "<<pi(rr,tt,dd,gg)<<endl; }   
}
}
}
}
 
}




More information about the Flopcpp mailing list