[FlopCpp] such_that functionality...
Vishy Jeet
vishv.jeet at gmail.com
Wed Dec 20 19:14:44 EST 2006
Thanks Tim, that worked.
For the benefit of those who are reading this thread in future: you must run
the following three commands all over again anytime you make changes in
source code:
>> make
>> make test
>> make install
this would reinstall the affected libraries...
Once again Tim, this was really great help.
regards,
vishy
On 12/20/06, Tim Hultberg <Tim.Hultberg at eumetsat.int> wrote:
>
> Hi Vishy,
>
> a) you probably want to use: such_that(N < N.size()-1) (since N
> implicitly counts from zero)
>
> b) the bad news is that this wont work either with the current version.
> (it used to though) To correct it go to MP_constraint.cpp
> and find the lines:
> left->generate(
> S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,1.0);
> right->generate(
> S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,-1.0);
> and change them to:
> left->generate(
> (S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5)).such_that(B),v,f,1.0);
> right->generate(
> (S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5)).such_that(B),v,f,-1.0);
> I will correct it in the next release. Sorry for the inconvenience.
>
> Let me know if you get any more problems with this.
>
> Cheesr, Tim
>
>
> Tim Hultberg
>
> >>> "Vishy Jeet" <vishv.jeet at gmail.com> 12/19/06 8:53 PM >>>
> I have written the following small prograg to solve GAP on size (3, 10)
>
> 1 // $Id$
> 2 #include "flopc.hpp"
> 3 using namespace flopc;
> 4 #include "OsiCbcSolverInterface.hpp"
> 5
> 6 /* Generalized Assignment Problem */
> 7
> 8 class Gap : public MP_model {
> 9 public:
> 10 MP_set M,N;
> 11 MP_data c;
> 12 MP_data a;
> 13 MP_data b;
> 14 MP_variable x;
> 15 MP_constraint cap, feas;
> 16
> 17 Gap(int numM, int numN) : MP_model(new OsiCbcSolverInterface),
> 18 M(numM), N(numN),
> 19 c(M,N), a(M,N), b(M),
> 20 x(M,N),
> 21 cap(M), feas(N)
> 22 {
> 23 x.binary();
> 24 cap(M) = sum(N, a(M,N)*x(M,N)) <= b(M);
> 25 feas(N).*such_that(N < N.size())* = sum(M, x(M,N)) == 1;
> 26 add(cap); add(feas);
> 27 setObjective( sum(M*N, c(M,N)*x(M,N)));
> 28 }
> 29 };
> 30
> 31 int main() {
> 32 double cost[3][11] = {{47,16,27,21,25,12,55,31,40,40,1000},
> 33 {45,18,56,33,36,46,11,17,31,50,1000},
> 34 {50,23,22,59,31,35,40,41,40,11,1000}};
> 35
> 36 double req[3][11] = {{24,12,8,12,16,14,13,15,23,5,100},
> 37 {7,17,8,5,6,19,20,7,22,9,100},
> 38 {23,18,14,8,18,23,19,11,15,11,100}};
> 39
> 40 double capc[3] = {37,32,42};
> 41
> 42 Gap instance(3,11);
> 43
> 44 instance.c.value(&cost[0][0]);
> 45 instance.a.value(&req[0][0]);
> 46 instance.b.value(&capc[0]);
> 47
> 48 instance.minimize();
> 49
> 50 cout<<"numRow:="<<instance->getNumRows()<<"\n";
> 51 cout<<"numCols:="<<instance->getNumCols()<<"\n";
> 52 cout<<"numEle:="<<instance->getNumElements()<<"\n";
> 53 cout<<"obj:="<<instance->getObjValue()<<"\n";
> 54 instance.x.display("Solution of first instance (x)");
> 55 }
>
> To learn how the such_that statement works, I introduced the 11th job
> with
> very high cost of assignment and infeasible
> requirement on any of the machines...to prevent infeasibility I write
> the
> "feas" constraints using such_that statement so
> that 11th job doesn't have to be assigned....but I am not able to see
> whats
> wrong with the code that it doesn't work.
> Any help on this is much appreciated..
>
> regards,
> vishy
>
>
--
--vishy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20061220/7b201de2/attachment.html
More information about the FlopCpp
mailing list