[FlopCpp] basic question about constraint from GNU Math
Prog to Flopcpp
Tim Hultberg
Tim.Hultberg at eumetsat.int
Mon Dec 18 08:36:19 EST 2006
I think the cleanest way to expres this constraint would be to have
three constraints indexed over three different subsets of N*K.
But if you want to translate your constraint directly to flopc++ you
must first add the following:
in MP_constant.hpp:
class MP_boolean;
Constant mpif(const MP_boolean& c, const Constant& a, const Constant& b);
in MP_constant.cpp:
class Constant_if : public Constant_exp {
friend Constant mpif(const MP_boolean& c, const Constant& a, const Constant& b);
private:
Constant_if(const MP_boolean b, const Constant& i, const Constant& j) : Constant_exp(i,j), B(b) {};
double evaluate() const {
if (B->evaluate()==true) {
return left->evaluate();
} else {
return right->evaluate();
}
}
MP_boolean B;
};
Constant mpif(const MP_boolean& c, const Constant& a, const Constant& b) {
return new Constant_if(c,a,b);
}
Now you can write your constraint as:
r1(i,ka) =
sum(N(j), f(i,j,ka)) - sum(N(l), f(l,i,ka)) ==
mpif(i==MP_index_exp(O(ka)), R(ka), mpif(i==MP_index_exp(D(ka)), Constant(0)-R(ka), 0 )) ;
(off course you are free to choose another name instead of "mpif")
Note:
a) the explicit conversion to MP_index_exp
b) that unary minus is not (yet) implemented for Constant.
This can (and will) be implemented similarly to the mpif above.
As mentioned above, I do not particularly like this mpif construct,
but if there is a "popular demand", I will consider to include it in
"standard" flopc++.
Cheers, Tim
>>> "marcos.roberto.silva" <marcos.roberto.silva at uol.com.br> 14/12/2006 21:28 >>>
Hi all,
I have a model written in GNU MathProg (GLPK) for the
Network Design Problem with the following constraint:
s.t. r1 {i in N, ka in K} : sum{j in N} f[i,j,ka] - sum{l in
N} f[l,i,ka] = (if i==O[ka] then R[ka] else (if i==D[ka]
then -R[ka] else 0));
How can I represent this constraint in Flopcpp?
Thank you.
Best Regards.
Marcos Roberto Silva
Brazil
_______________________________________________
FlopCpp mailing list
FlopCpp at list.coin-or.org
http://list.coin-or.org/mailman/listinfo/flopcpp
More information about the FlopCpp
mailing list