Debian Codegraph @

SYMPHONY/Examples/FLOPC++/tap.cpp

raw
1 #include "flopc.hpp"
2 using namespace flopc;
3 #include "OsiSymSolverInterface.hpp"
4
5 /* Teacher Assignment Problem
6
7 T. H. Hultberg and D. M. Cardoso, "The teacher assignment problem: A special
8 case of the fixed charge transportation problem", European Journal of
9 Operational Research, 101(3):463-474,1997.
10 */
11
12 class Tap : public MP_model {
13 public:
14 MP_set S,D;
15 MP_data s;
16 MP_data d;
17 MP_variable x;
18 MP_variable y;
19 MP_constraint supply, demand, def_y;
20
21 Tap(int numS, int numD) : MP_model(new OsiSymSolverInterface),
22 S(numS), D(numD),
23 s(S), d(D),
24 x(S,D), y(S,D),
25 supply(S), demand(D), def_y(S,D) {
26 y.binary();
27
28 supply(S) = sum(D, x(S,D)) <= s(S);
29
30 demand(D) = sum(S, x(S,D)) >= d(D) ;
31
32 def_y(S,D) = d(D)*y(S,D) >= x(S,D);
33
34 add(supply); add(demand); add(def_y);
35
36 setObjective( sum(S*D, y(S,D)) );
37
38 }
39 };
40
41 main() {
42 double stab_1[6] = {5,5,6,6,6,6};
43 double dtab_1[4] = {4, 7, 10, 11};
44 double stab_2[7] = {9,9,10,12,12,12,16};
45 double dtab_2[5] = {6, 14, 17, 21, 22};
46
47 Tap first_instance(6,4);
48 Tap second_instance(7,5);
49
50 first_instance.s.value(stab_1);
51 first_instance.d.value(dtab_1);
52
53 second_instance.s.value(stab_2);
54 second_instance.d.value(dtab_2);
55
56 first_instance.minimize();
57 first_instance.x.display("Solution of first instance (x)");
58 first_instance.y.display("Solution of first instance (y)");
59
60 second_instance.minimize();
61 second_instance.x.display("Solution of second instance");
62 }