[Flopcpp] A FlopC++ Bug?

WoelliUSM at aol.com WoelliUSM at aol.com
Mon Feb 27 07:01:43 EST 2006


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; }   
}
}
}
}
 
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20060227/df541ec6/attachment.html


More information about the Flopcpp mailing list