[FlopCpp] such_that functionality...
Vishy Jeet
vishv.jeet at gmail.com
Tue Dec 19 14:53:10 EST 2006
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20061219/242647f2/attachment.html
More information about the FlopCpp
mailing list