equal
deleted
inserted
replaced
35 |
35 |
36 LpGlpk::LpGlpk(const LpGlpk &glp) : Parent() { |
36 LpGlpk::LpGlpk(const LpGlpk &glp) : Parent() { |
37 rows = _lp_bits::LpId(1); |
37 rows = _lp_bits::LpId(1); |
38 cols = _lp_bits::LpId(1); |
38 cols = _lp_bits::LpId(1); |
39 lp = lpx_create_prob(); |
39 lp = lpx_create_prob(); |
|
40 lpx_create_index(lp); |
40 ///\todo control function for this: |
41 ///\todo control function for this: |
41 lpx_set_int_parm(lp, LPX_K_DUAL, 1); |
42 lpx_set_int_parm(lp, LPX_K_DUAL, 1); |
42 messageLevel(0); |
43 messageLevel(0); |
43 //Coefficient matrix, row bounds |
44 //Coefficient matrix, row bounds |
44 lpx_add_rows(lp, lpx_get_num_rows(glp.lp)); |
45 lpx_add_rows(lp, lpx_get_num_rows(glp.lp)); |
110 int rows[2]; |
111 int rows[2]; |
111 rows[1]=i; |
112 rows[1]=i; |
112 lpx_del_rows(lp, 1, rows); |
113 lpx_del_rows(lp, 1, rows); |
113 } |
114 } |
114 |
115 |
115 void LpGlpk::_getColName(int col, std::string & name) |
116 void LpGlpk::_getColName(int col, std::string & name) const |
116 { |
117 { |
117 |
118 |
118 char *n = lpx_get_col_name(lp,col); |
119 char *n = lpx_get_col_name(lp,col); |
119 name = n?n:""; |
120 name = n?n:""; |
120 } |
121 } |
123 void LpGlpk::_setColName(int col, const std::string & name) |
124 void LpGlpk::_setColName(int col, const std::string & name) |
124 { |
125 { |
125 lpx_set_col_name(lp,col,const_cast<char*>(name.c_str())); |
126 lpx_set_col_name(lp,col,const_cast<char*>(name.c_str())); |
126 |
127 |
127 } |
128 } |
|
129 |
|
130 int LpGlpk::_colByName(const std::string& name) const |
|
131 { |
|
132 int k = lpx_find_col(lp, const_cast<char*>(name.c_str())); |
|
133 return k > 0 ? k : -1; |
|
134 } |
|
135 |
128 |
136 |
129 void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) |
137 void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) |
130 { |
138 { |
131 std::vector<int> indices; |
139 std::vector<int> indices; |
132 std::vector<Value> values; |
140 std::vector<Value> values; |
140 } |
148 } |
141 |
149 |
142 lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]); |
150 lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]); |
143 } |
151 } |
144 |
152 |
145 void LpGlpk::_getRowCoeffs(int i, RowIterator b) |
153 void LpGlpk::_getRowCoeffs(int i, RowIterator b) const |
146 { |
154 { |
147 int length = lpx_get_mat_row(lp, i, 0, 0); |
155 int length = lpx_get_mat_row(lp, i, 0, 0); |
148 |
156 |
149 std::vector<int> indices(length + 1); |
157 std::vector<int> indices(length + 1); |
150 std::vector<Value> values(length + 1); |
158 std::vector<Value> values(length + 1); |
171 } |
179 } |
172 |
180 |
173 lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]); |
181 lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]); |
174 } |
182 } |
175 |
183 |
176 void LpGlpk::_getColCoeffs(int i, ColIterator b) |
184 void LpGlpk::_getColCoeffs(int i, ColIterator b) const |
177 { |
185 { |
178 int length = lpx_get_mat_col(lp, i, 0, 0); |
186 int length = lpx_get_mat_col(lp, i, 0, 0); |
179 |
187 |
180 std::vector<int> indices(length + 1); |
188 std::vector<int> indices(length + 1); |
181 std::vector<Value> values(length + 1); |
189 std::vector<Value> values(length + 1); |
245 |
253 |
246 lpx_set_mat_col(lp, col, length, &indices[0], &values[0]); |
254 lpx_set_mat_col(lp, col, length, &indices[0], &values[0]); |
247 } |
255 } |
248 } |
256 } |
249 |
257 |
250 LpGlpk::Value LpGlpk::_getCoeff(int row, int col) |
258 LpGlpk::Value LpGlpk::_getCoeff(int row, int col) const |
251 { |
259 { |
252 |
260 |
253 int length=lpx_get_mat_row(lp, row, 0, 0); |
261 int length=lpx_get_mat_row(lp, row, 0, 0); |
254 |
262 |
255 std::vector<int> indices(length + 1); |
263 std::vector<int> indices(length + 1); |
310 } |
318 } |
311 } |
319 } |
312 |
320 |
313 } |
321 } |
314 |
322 |
315 LpGlpk::Value LpGlpk::_getColLowerBound(int i) |
323 LpGlpk::Value LpGlpk::_getColLowerBound(int i) const |
316 { |
324 { |
317 int b=lpx_get_col_type(lp, i); |
325 int b=lpx_get_col_type(lp, i); |
318 switch (b) { |
326 switch (b) { |
319 case LPX_LO: |
327 case LPX_LO: |
320 case LPX_DB: |
328 case LPX_DB: |
367 //FIXME error |
375 //FIXME error |
368 } |
376 } |
369 } |
377 } |
370 } |
378 } |
371 |
379 |
372 LpGlpk::Value LpGlpk::_getColUpperBound(int i) |
380 LpGlpk::Value LpGlpk::_getColUpperBound(int i) const |
373 { |
381 { |
374 int b=lpx_get_col_type(lp, i); |
382 int b=lpx_get_col_type(lp, i); |
375 switch (b) { |
383 switch (b) { |
376 case LPX_UP: |
384 case LPX_UP: |
377 case LPX_DB: |
385 case LPX_DB: |
412 } |
420 } |
413 } |
421 } |
414 |
422 |
415 } |
423 } |
416 |
424 |
417 void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) |
425 void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) const |
418 { |
426 { |
419 |
427 |
420 int b=lpx_get_row_type(lp, i); |
428 int b=lpx_get_row_type(lp, i); |
421 switch (b) { |
429 switch (b) { |
422 case LPX_FR: |
430 case LPX_FR: |
442 { |
450 { |
443 //i=0 means the constant term (shift) |
451 //i=0 means the constant term (shift) |
444 lpx_set_obj_coef(lp, i, obj_coef); |
452 lpx_set_obj_coef(lp, i, obj_coef); |
445 } |
453 } |
446 |
454 |
447 LpGlpk::Value LpGlpk::_getObjCoeff(int i){ |
455 LpGlpk::Value LpGlpk::_getObjCoeff(int i) const { |
448 //i=0 means the constant term (shift) |
456 //i=0 means the constant term (shift) |
449 return lpx_get_obj_coef(lp, i); |
457 return lpx_get_obj_coef(lp, i); |
450 } |
458 } |
451 |
459 |
452 void LpGlpk::_clearObj() |
460 void LpGlpk::_clearObj() |
470 default: |
478 default: |
471 return UNSOLVED; |
479 return UNSOLVED; |
472 } |
480 } |
473 } |
481 } |
474 |
482 |
475 LpGlpk::Value LpGlpk::_getPrimal(int i) |
483 LpGlpk::Value LpGlpk::_getPrimal(int i) const |
476 { |
484 { |
477 return lpx_get_col_prim(lp,i); |
485 return lpx_get_col_prim(lp,i); |
478 } |
486 } |
479 |
487 |
480 LpGlpk::Value LpGlpk::_getDual(int i) |
488 LpGlpk::Value LpGlpk::_getDual(int i) const |
481 { |
489 { |
482 return lpx_get_row_dual(lp,i); |
490 return lpx_get_row_dual(lp,i); |
483 } |
491 } |
484 |
492 |
485 LpGlpk::Value LpGlpk::_getPrimalValue() |
493 LpGlpk::Value LpGlpk::_getPrimalValue() const |
486 { |
494 { |
487 return lpx_get_obj_val(lp); |
495 return lpx_get_obj_val(lp); |
488 } |
496 } |
489 bool LpGlpk::_isBasicCol(int i) { |
497 bool LpGlpk::_isBasicCol(int i) const |
|
498 { |
490 return (lpx_get_col_stat(lp, i)==LPX_BS); |
499 return (lpx_get_col_stat(lp, i)==LPX_BS); |
491 } |
500 } |
492 |
501 |
493 |
502 |
494 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() |
503 LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() const |
495 { |
504 { |
496 int stat= lpx_get_status(lp); |
505 int stat= lpx_get_status(lp); |
497 switch (stat) { |
506 switch (stat) { |
498 case LPX_UNDEF://Undefined (no solve has been run yet) |
507 case LPX_UNDEF://Undefined (no solve has been run yet) |
499 return UNDEFINED; |
508 return UNDEFINED; |
510 return UNDEFINED; //to avoid gcc warning |
519 return UNDEFINED; //to avoid gcc warning |
511 //FIXME error |
520 //FIXME error |
512 } |
521 } |
513 } |
522 } |
514 |
523 |
515 LpGlpk::SolutionStatus LpGlpk::_getDualStatus() |
524 LpGlpk::SolutionStatus LpGlpk::_getDualStatus() const |
516 { |
525 { |
517 // std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl; |
|
518 // std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl; |
|
519 |
|
520 switch (lpx_get_dual_stat(lp)) { |
526 switch (lpx_get_dual_stat(lp)) { |
521 case LPX_D_UNDEF://Undefined (no solve has been run yet) |
527 case LPX_D_UNDEF://Undefined (no solve has been run yet) |
522 return UNDEFINED; |
528 return UNDEFINED; |
523 case LPX_D_NOFEAS://There is no dual feasible solution |
529 case LPX_D_NOFEAS://There is no dual feasible solution |
524 // case LPX_D_INFEAS://Infeasible |
530 // case LPX_D_INFEAS://Infeasible |
536 return UNDEFINED; //to avoid gcc warning |
542 return UNDEFINED; //to avoid gcc warning |
537 //FIXME error |
543 //FIXME error |
538 } |
544 } |
539 } |
545 } |
540 |
546 |
541 LpGlpk::ProblemTypes LpGlpk::_getProblemType() |
547 LpGlpk::ProblemTypes LpGlpk::_getProblemType() const |
542 { |
548 { |
543 //int stat= lpx_get_status(lp); |
549 //int stat= lpx_get_status(lp); |
544 int statp= lpx_get_prim_stat(lp); |
550 int statp= lpx_get_prim_stat(lp); |
545 int statd= lpx_get_dual_stat(lp); |
551 int statd= lpx_get_dual_stat(lp); |
546 if (statp==LPX_P_FEAS && statd==LPX_D_FEAS) |
552 if (statp==LPX_P_FEAS && statd==LPX_D_FEAS) |
563 void LpGlpk::_setMin() |
569 void LpGlpk::_setMin() |
564 { |
570 { |
565 lpx_set_obj_dir(lp, LPX_MIN); |
571 lpx_set_obj_dir(lp, LPX_MIN); |
566 } |
572 } |
567 |
573 |
568 bool LpGlpk::_isMax() |
574 bool LpGlpk::_isMax() const |
569 { |
575 { |
570 return (lpx_get_obj_dir(lp)==LPX_MAX); |
576 return (lpx_get_obj_dir(lp)==LPX_MAX); |
571 } |
577 } |
572 |
578 |
573 |
579 |