22 namespace lemon { |
22 namespace lemon { |
23 |
23 |
24 int LpCplex::_addCol() |
24 int LpCplex::_addCol() |
25 { |
25 { |
26 int i = CPXgetnumcols (env, lp); |
26 int i = CPXgetnumcols (env, lp); |
27 int lb[1],ub[1]; |
27 Value lb[1],ub[1]; |
28 lb[0]=-INF;//-CPX_INFBOUND; |
28 lb[0]=-INF;//-CPX_INFBOUND; |
29 ub[0]=INF;//CPX_INFBOUND; |
29 ub[0]=INF;//CPX_INFBOUND; |
30 status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL); |
30 status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL); |
31 return i; |
31 return i; |
32 } |
32 } |
33 |
33 |
34 int LpCplex::_addRow() |
34 int LpCplex::_addRow() |
35 { |
35 { |
|
36 //We want a ranged row |
|
37 char sense[1]; |
|
38 sense[0]='R'; |
|
39 |
36 int i = CPXgetnumrows (env, lp); |
40 int i = CPXgetnumrows (env, lp); |
37 status = CPXnewrows (env, lp, 1, NULL, NULL, NULL, NULL, NULL); |
41 status = CPXnewrows (env, lp, 1, NULL, sense, NULL, NULL); |
38 return i; |
42 return i; |
39 } |
43 } |
40 |
44 |
41 ///\warning Data at index 0 is ignored iin the arrays. |
45 ///\warning Data at index 0 is ignored iin the arrays. |
42 void LpCplex::_setRowCoeffs(int i, |
46 void LpCplex::_setRowCoeffs(int i, |
43 int length, |
47 int length, |
44 int const * indices, |
48 int const * indices, |
45 Value const * values ) |
49 Value const * values ) |
46 { |
50 { |
47 int rowlist[length+1]; |
51 int rowlist[length+1]; |
|
52 int* p=rowlist; |
48 for (int k=1;k<=length;++k){ |
53 for (int k=1;k<=length;++k){ |
49 rowlist[k]=i; |
54 rowlist[k]=i; |
50 } |
55 } |
51 status = CPXchgcoeflist(env, lp, |
56 status = CPXchgcoeflist(env, lp, |
52 length, |
57 length, |
53 rowlist++, |
58 p++, |
54 inices++, |
59 const_cast<int * >(indices++), |
55 values++); |
60 const_cast<Value * >(values++)); |
56 } |
61 } |
57 |
62 |
58 void LpCplex::_setColCoeffs(int i, |
63 void LpCplex::_setColCoeffs(int i, |
59 int length, |
64 int length, |
60 int const * indices, |
65 int const * indices, |
61 Value const * values) |
66 Value const * values) |
62 { |
67 { |
63 int collist[length+1]; |
68 int collist[length+1]; |
|
69 int* p=collist; |
64 for (int k=1;k<=length;++k){ |
70 for (int k=1;k<=length;++k){ |
65 collist[k]=i; |
71 collist[k]=i; |
66 } |
72 } |
67 status = CPXchgcoeflist(env, lp, |
73 status = CPXchgcoeflist(env, lp, |
68 length, |
74 length, |
69 inices++, |
75 const_cast<int * >(indices++), |
70 collist++, |
76 p++, |
71 values++); |
77 const_cast<Value * >(values++)); |
72 } |
78 } |
73 |
79 |
74 void LpCplex::_setColLowerBound(int i, Value value) |
80 void LpCplex::_setColLowerBound(int i, Value value) |
75 { |
81 { |
|
82 int indices[1]; |
|
83 indices[0]=i; |
|
84 char lu[1]; |
|
85 lu[0]='L'; |
|
86 Value bd[1]; |
|
87 bd[0]=value; |
|
88 status = CPXchgbds (env, lp, 1, indices, lu, bd); |
|
89 |
76 } |
90 } |
77 |
91 |
78 void LpCplex::_setColUpperBound(int i, Value value) |
92 void LpCplex::_setColUpperBound(int i, Value value) |
79 { |
93 { |
|
94 int indices[1]; |
|
95 indices[0]=i; |
|
96 char lu[1]; |
|
97 lu[0]='U'; |
|
98 Value bd[1]; |
|
99 bd[0]=value; |
|
100 status = CPXchgbds (env, lp, 1, indices, lu, bd); |
80 } |
101 } |
81 |
102 |
82 void LpCplex::_setRowLowerBound(int i, Value value) |
103 void LpCplex::_setRowLowerBound(int i, Value value) |
83 { |
104 { |
|
105 status = CPXchgcoef (env, lp, i, -1, value); |
|
106 |
84 } |
107 } |
85 |
108 |
86 void LpCplex::_setRowUpperBound(int i, Value value) |
109 void LpCplex::_setRowUpperBound(int i, Value value) |
87 { |
110 { |
|
111 //TODO Ezt kell meg megirni |
|
112 // Value lo=CPX |
88 } |
113 } |
89 |
114 |
90 void LpCplex::_setObjCoeff(int i, Value obj_coef) |
115 void LpCplex::_setObjCoeff(int i, Value obj_coef) |
91 { |
116 { |
|
117 status = CPXchgcoef (env, lp, -1, i, obj_coef); |
|
118 } |
|
119 |
|
120 LpCplex::SolveExitStatus LpCplex::_solve() |
|
121 { |
|
122 return SOLVED; |
|
123 // int i= lpx_simplex(lp); |
|
124 // switch (i) { |
|
125 // case LPX_E_OK: |
|
126 // return SOLVED; |
|
127 // break; |
|
128 // default: |
|
129 // return UNSOLVED; |
|
130 // } |
92 } |
131 } |
93 |
132 |
94 LpCplex::SolutionStatus LpCplex::_solve() |
133 LpCplex::Value LpCplex::_getPrimal(int i) |
95 { |
|
96 return OPTIMAL; |
|
97 } |
|
98 |
|
99 LpCplex::Value LpCplex::_getSolution(int i) |
|
100 { |
134 { |
101 return 0; |
135 return 0; |
102 } |
136 } |
103 |
137 |
|
138 LpCplex::Value LpCplex::_getPrimalValue() |
|
139 { |
|
140 return 0; |
|
141 } |
|
142 |
|
143 |
|
144 LpCplex::SolutionStatus LpCplex::_getPrimalStatus() |
|
145 { |
|
146 return OPTIMAL; |
|
147 // int stat= lpx_get_status(lp); |
|
148 // switch (stat) { |
|
149 // case LPX_UNDEF://Undefined (no solve has been run yet) |
|
150 // return UNDEFINED; |
|
151 // break; |
|
152 // case LPX_NOFEAS://There is no feasible solution (primal, I guess) |
|
153 // case LPX_INFEAS://Infeasible |
|
154 // return INFEASIBLE; |
|
155 // break; |
|
156 // case LPX_UNBND://Unbounded |
|
157 // return INFINITE; |
|
158 // break; |
|
159 // case LPX_FEAS://Feasible |
|
160 // return FEASIBLE; |
|
161 // break; |
|
162 // case LPX_OPT://Feasible |
|
163 // return OPTIMAL; |
|
164 // break; |
|
165 // default: |
|
166 // return UNDEFINED; //to avoid gcc warning |
|
167 // //FIXME error |
|
168 // } |
|
169 } |
|
170 |
|
171 |
|
172 void LpCplex::_setMax() |
|
173 { |
|
174 CPXchgobjsen (env, lp, CPX_MAX); |
|
175 } |
|
176 void LpCplex::_setMin() |
|
177 { |
|
178 CPXchgobjsen (env, lp, CPX_MIN); |
|
179 } |
|
180 |
104 } //namespace lemon |
181 } //namespace lemon |
105 |
182 |