Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__glpk__.cc @ 5240:2bb31f40c339
[project @ 2005-03-24 02:34:13 by jwe]
author | jwe |
---|---|
date | Thu, 24 Mar 2005 02:34:13 +0000 |
parents | d432b7809fe5 |
children | ab89f95de831 |
comparison
equal
deleted
inserted
replaced
5239:8a7224914e16 | 5240:2bb31f40c339 |
---|---|
39 | 39 |
40 extern "C" { | 40 extern "C" { |
41 #include <glpk.h> | 41 #include <glpk.h> |
42 } | 42 } |
43 | 43 |
44 #define OCTOUT octave_stdout | |
45 #define OCTERR octave_stdout | |
46 #define NIntP 17 | 44 #define NIntP 17 |
47 #define NRealP 10 | 45 #define NRealP 10 |
48 | 46 |
49 int lpxIntParam[NIntP] = { | 47 int lpxIntParam[NIntP] = { |
50 1, | 48 0, |
51 1, | 49 1, |
52 0, | 50 0, |
53 1, | 51 1, |
54 0, | 52 0, |
55 -1, | 53 -1, |
118 | 116 |
119 | 117 |
120 int | 118 int |
121 glpk_fault_hook (void * /* info */, char *msg) | 119 glpk_fault_hook (void * /* info */, char *msg) |
122 { | 120 { |
123 OCTERR << "*** SEVERE CRITICAL ERROR *** from GLPK !\n\n"<<msg<<" %s\n"; | 121 error ("CRITICAL ERROR in GLPK: %s", msg); |
124 longjmp (mark, -1); | 122 longjmp (mark, -1); |
125 } | 123 } |
126 | 124 |
127 int | 125 int |
128 glpk_print_hook (void * /* info */, char *msg) | 126 glpk_print_hook (void * /* info */, char *msg) |
129 { | 127 { |
130 OCTERR << msg << "\n"; | 128 message (0, "%s\n", msg); |
131 return 1; | 129 return 1; |
132 } | 130 } |
133 | 131 |
134 | 132 |
135 int | 133 int |
137 double *a, double *b, char *ctype, int *freeLB, double *lb, | 135 double *a, double *b, char *ctype, int *freeLB, double *lb, |
138 int *freeUB, double *ub, int *vartype, int isMIP, int lpsolver, | 136 int *freeUB, double *ub, int *vartype, int isMIP, int lpsolver, |
139 int save_pb, double *xmin, double *fmin, double *status, | 137 int save_pb, double *xmin, double *fmin, double *status, |
140 double *lambda, double *redcosts, double *time, double *mem) | 138 double *lambda, double *redcosts, double *time, double *mem) |
141 { | 139 { |
142 int error; | 140 int errnum; |
143 int typx = 0; | 141 int typx = 0; |
144 int method; | 142 int method; |
145 | 143 |
146 clock_t t_start = clock(); | 144 clock_t t_start = clock(); |
147 | 145 |
233 | 231 |
234 if (save_pb) | 232 if (save_pb) |
235 { | 233 { |
236 if (lpx_write_cpxlp (lp, "outpb.lp") != 0) | 234 if (lpx_write_cpxlp (lp, "outpb.lp") != 0) |
237 { | 235 { |
238 OCTERR << "Unable to write problem\n"; | 236 error ("__glpk__: unable to write problem"); |
239 longjmp (mark, -1); | 237 longjmp (mark, -1); |
240 } | 238 } |
241 } | 239 } |
242 | 240 |
243 //-- scale the problem data (if required) | 241 //-- scale the problem data (if required) |
266 case 'S': | 264 case 'S': |
267 { | 265 { |
268 if (isMIP) | 266 if (isMIP) |
269 { | 267 { |
270 method = 'I'; | 268 method = 'I'; |
271 error = lpx_simplex (lp); | 269 errnum = lpx_simplex (lp); |
272 error = lpx_integer (lp); | 270 errnum = lpx_integer (lp); |
273 } | 271 } |
274 else | 272 else |
275 error = lpx_simplex(lp); | 273 errnum = lpx_simplex(lp); |
276 } | 274 } |
277 break; | 275 break; |
278 | 276 |
279 case 'T': | 277 case 'T': |
280 error = lpx_interior(lp); | 278 errnum = lpx_interior(lp); |
281 break; | 279 break; |
282 | 280 |
283 default: | 281 default: |
284 insist (method != method); | 282 insist (method != method); |
285 } | 283 } |
286 | 284 |
287 /* error assumes the following results: | 285 /* errnum assumes the following results: |
288 error=0 <=> No errors | 286 errnum = 0 <=> No errors |
289 error=1 <=> Iteration limit exceeded. | 287 errnum = 1 <=> Iteration limit exceeded. |
290 error=2 <=> Numerical problems with basis matrix. | 288 errnum = 2 <=> Numerical problems with basis matrix. |
291 */ | 289 */ |
292 if (error == LPX_E_OK) | 290 if (errnum == LPX_E_OK) |
293 { | 291 { |
294 if (isMIP) | 292 if (isMIP) |
295 { | 293 { |
296 *status = static_cast<double> (lpx_mip_status (lp)); | 294 *status = static_cast<double> (lpx_mip_status (lp)); |
297 *fmin = lpx_mip_obj_val (lp); | 295 *fmin = lpx_mip_obj_val (lp); |
352 return 0; | 350 return 0; |
353 } | 351 } |
354 | 352 |
355 lpx_delete_prob (lp); | 353 lpx_delete_prob (lp); |
356 | 354 |
357 *status= static_cast<double> (error); | 355 *status= static_cast<double> (errnum); |
358 | 356 |
359 return error; | 357 return errnum; |
360 } | 358 } |
361 | 359 |
362 #endif | 360 #endif |
361 | |
362 #define OCTAVE_GLPK_GET_REAL_PARAM(NAME, IDX) \ | |
363 do \ | |
364 { \ | |
365 if (PARAM.contains (NAME)) \ | |
366 { \ | |
367 Cell tmp = PARAM.contents (NAME); \ | |
368 \ | |
369 if (! tmp.is_empty ()) \ | |
370 { \ | |
371 lpxRealParam[IDX] = tmp(0).scalar_value (); \ | |
372 \ | |
373 if (error_state) \ | |
374 { \ | |
375 error ("glpk: invalid value in param." NAME); \ | |
376 return retval; \ | |
377 } \ | |
378 } \ | |
379 else \ | |
380 { \ | |
381 error ("glpk: invalid value in param." NAME); \ | |
382 return retval; \ | |
383 } \ | |
384 } \ | |
385 } \ | |
386 while (0) | |
387 | |
388 #define OCTAVE_GLPK_GET_INT_PARAM(NAME, VAL) \ | |
389 do \ | |
390 { \ | |
391 if (PARAM.contains (NAME)) \ | |
392 { \ | |
393 Cell tmp = PARAM.contents (NAME); \ | |
394 \ | |
395 if (! tmp.is_empty ()) \ | |
396 { \ | |
397 VAL = tmp(0).int_value (); \ | |
398 \ | |
399 if (error_state) \ | |
400 { \ | |
401 error ("glpk: invalid value in param." NAME); \ | |
402 return retval; \ | |
403 } \ | |
404 } \ | |
405 else \ | |
406 { \ | |
407 error ("glpk: invalid value in param." NAME); \ | |
408 return retval; \ | |
409 } \ | |
410 } \ | |
411 } \ | |
412 while (0) | |
363 | 413 |
364 DEFUN_DLD (__glpk__, args, , | 414 DEFUN_DLD (__glpk__, args, , |
365 "__glpk__: internal interface for the GLPK library.\n\ | 415 "__glpk__: internal interface for the GLPK library.\n\ |
366 You should be using using glpk instead") | 416 You should be using using glpk instead") |
367 { | 417 { |
370 | 420 |
371 #if defined (HAVE_GLPK) | 421 #if defined (HAVE_GLPK) |
372 | 422 |
373 int nrhs = args.length (); | 423 int nrhs = args.length (); |
374 | 424 |
375 if (nrhs < 1) | 425 if (nrhs != 9) |
376 { | 426 { |
377 OCTERR<<"Use the script glpk for the optimization\n"; | 427 print_usage ("__glpk__"); |
378 return retval; | 428 return retval; |
379 } | 429 } |
380 | 430 |
381 //-- 1nd Input. A column array containing the objective function | 431 //-- 1nd Input. A column array containing the objective function |
382 //-- coefficients. | 432 //-- coefficients. |
383 int mrowsc = args(0).rows(); | 433 int mrowsc = args(0).rows(); |
384 | 434 |
385 Matrix C (args(0).matrix_value ()); | 435 Matrix C (args(0).matrix_value ()); |
436 | |
437 if (error_state) | |
438 { | |
439 error ("__glpk__: invalid value of C"); | |
440 return retval; | |
441 } | |
442 | |
386 double *c = C.fortran_vec (); | 443 double *c = C.fortran_vec (); |
387 | 444 |
388 //-- 2nd Input. A matrix containing the constraints coefficients. | 445 //-- 2nd Input. A matrix containing the constraints coefficients. |
389 // If matrix A is NOT a sparse matrix | 446 // If matrix A is NOT a sparse matrix |
390 // if(!mxIsSparse(A_IN)){ | 447 // if(!mxIsSparse(A_IN)){ |
391 int mrowsA = args(1).rows(); | |
392 Matrix A (args(1).matrix_value ()); // get the matrix | 448 Matrix A (args(1).matrix_value ()); // get the matrix |
449 | |
450 if (error_state) | |
451 { | |
452 error ("__glpk__: invalid value of A"); | |
453 return retval; | |
454 } | |
455 | |
456 int mrowsA = A.rows (); | |
393 Array<int> rn (mrowsA*mrowsc+1); | 457 Array<int> rn (mrowsA*mrowsc+1); |
394 Array<int> cn (mrowsA*mrowsc+1); | 458 Array<int> cn (mrowsA*mrowsc+1); |
395 ColumnVector a (mrowsA*mrowsc+1, 0.0); | 459 ColumnVector a (mrowsA*mrowsc+1, 0.0); |
396 | 460 |
397 volatile int nz = 0; | 461 volatile int nz = 0; |
442 // } | 506 // } |
443 | 507 |
444 //-- 3rd Input. A column array containing the right-hand side value | 508 //-- 3rd Input. A column array containing the right-hand side value |
445 // for each constraint in the constraint matrix. | 509 // for each constraint in the constraint matrix. |
446 Matrix B (args(2).matrix_value ()); | 510 Matrix B (args(2).matrix_value ()); |
511 | |
512 if (error_state) | |
513 { | |
514 error ("__glpk__: invalid value of b"); | |
515 return retval; | |
516 } | |
517 | |
447 double *b = B.fortran_vec (); | 518 double *b = B.fortran_vec (); |
448 | 519 |
449 //-- 4th Input. An array of length mrowsc containing the lower | 520 //-- 4th Input. An array of length mrowsc containing the lower |
450 //-- bound on each of the variables. | 521 //-- bound on each of the variables. |
451 Matrix LB (args(3).matrix_value ()); | 522 Matrix LB (args(3).matrix_value ()); |
523 | |
524 if (error_state) | |
525 { | |
526 error ("__glpk__: invalid value of lb"); | |
527 return retval; | |
528 } | |
529 | |
452 double *lb = LB.fortran_vec (); | 530 double *lb = LB.fortran_vec (); |
453 | 531 |
454 //-- LB argument, default: Free | 532 //-- LB argument, default: Free |
455 Array<int> freeLB (mrowsc); | 533 Array<int> freeLB (mrowsc); |
456 for (int i = 0; i < mrowsc; i++) | 534 for (int i = 0; i < mrowsc; i++) |
466 | 544 |
467 //-- 5th Input. An array of at least length numcols containing the upper | 545 //-- 5th Input. An array of at least length numcols containing the upper |
468 //-- bound on each of the variables. | 546 //-- bound on each of the variables. |
469 Matrix UB (args(4).matrix_value ()); | 547 Matrix UB (args(4).matrix_value ()); |
470 | 548 |
549 if (error_state) | |
550 { | |
551 error ("__glpk__: invalid value of ub"); | |
552 return retval; | |
553 } | |
554 | |
471 double *ub = UB.fortran_vec (); | 555 double *ub = UB.fortran_vec (); |
472 | 556 |
473 Array<int> freeUB (mrowsc); | 557 Array<int> freeUB (mrowsc); |
474 for (int i = 0; i < mrowsc; i++) | 558 for (int i = 0; i < mrowsc; i++) |
475 { | 559 { |
483 } | 567 } |
484 | 568 |
485 //-- 6th Input. A column array containing the sense of each constraint | 569 //-- 6th Input. A column array containing the sense of each constraint |
486 //-- in the constraint matrix. | 570 //-- in the constraint matrix. |
487 charMatrix CTYPE (args(5).char_matrix_value ()); | 571 charMatrix CTYPE (args(5).char_matrix_value ()); |
572 | |
573 if (error_state) | |
574 { | |
575 error ("__glpk__: invalid value of ctype"); | |
576 return retval; | |
577 } | |
578 | |
488 char *ctype = CTYPE.fortran_vec (); | 579 char *ctype = CTYPE.fortran_vec (); |
489 | 580 |
490 //-- 7th Input. A column array containing the types of the variables. | 581 //-- 7th Input. A column array containing the types of the variables. |
491 charMatrix VTYPE (args(6).char_matrix_value ()); | 582 charMatrix VTYPE (args(6).char_matrix_value ()); |
583 | |
584 if (error_state) | |
585 { | |
586 error ("__glpk__: invalid value of vtype"); | |
587 return retval; | |
588 } | |
492 | 589 |
493 Array<int> vartype (mrowsc); | 590 Array<int> vartype (mrowsc); |
494 volatile int isMIP = 0; | 591 volatile int isMIP = 0; |
495 for (int i = 0; i < mrowsc ; i++) | 592 for (int i = 0; i < mrowsc ; i++) |
496 { | 593 { |
504 } | 601 } |
505 | 602 |
506 //-- 8th Input. Sense of optimization. | 603 //-- 8th Input. Sense of optimization. |
507 volatile int sense; | 604 volatile int sense; |
508 double SENSE = args(7).scalar_value (); | 605 double SENSE = args(7).scalar_value (); |
606 | |
607 if (error_state) | |
608 { | |
609 error ("__glpk__: invalid value of sense"); | |
610 return retval; | |
611 } | |
612 | |
509 if (SENSE >= 0) | 613 if (SENSE >= 0) |
510 sense = 1; | 614 sense = 1; |
511 else | 615 else |
512 sense = -1; | 616 sense = -1; |
513 | 617 |
514 //-- 9th Input. A structure containing the control parameters. | 618 //-- 9th Input. A structure containing the control parameters. |
515 Octave_map PARAM = args(8).map_value (); | 619 Octave_map PARAM = args(8).map_value (); |
516 | 620 |
621 if (error_state) | |
622 { | |
623 error ("__glpk__: invalid value of param"); | |
624 return retval; | |
625 } | |
626 | |
517 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 627 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
518 //-- Integer parameters | 628 //-- Integer parameters |
519 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 629 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
520 | 630 |
521 //-- Level of messages output by the solver | 631 //-- Level of messages output by the solver |
522 if (PARAM.contains ("msglev")) | 632 OCTAVE_GLPK_GET_INT_PARAM ("msglev", lpxIntParam[0]); |
523 { | 633 if (lpxIntParam[0] < 0 || lpxIntParam[0] > 3) |
524 octave_value tmp = PARAM.contents (PARAM.seek ("msglev"))(0); | 634 { |
525 | 635 error ("__glpk__: param.msglev must be 0 (no output [default]) or 1 (error messages only) or 2 (normal output) or 3 (full output)"); |
526 double numtmp = tmp.scalar_value (); | 636 return retval; |
527 if (numtmp != 0 && numtmp != 1 && numtmp != 2 && numtmp != 3) | 637 } |
528 { | |
529 OCTOUT << "'msglev' parameter must be only:\n\t0 - no output,\n\t1 - error messages only),\n\t2 - normal output,\n\t3 - full output [default]\n"; | |
530 return retval; | |
531 } | |
532 | |
533 lpxIntParam[0] = static_cast<int> (numtmp); | |
534 } | |
535 | 638 |
536 //-- scaling option | 639 //-- scaling option |
537 if (PARAM.contains ("scale")) | 640 OCTAVE_GLPK_GET_INT_PARAM ("scale", lpxIntParam[1]); |
538 { | 641 if (lpxIntParam[1] < 0 || lpxIntParam[1] > 2) |
539 octave_value tmp = PARAM.contents (PARAM.seek ("scale"))(0); | 642 { |
540 double numtmp = tmp.scalar_value (); | 643 error ("__glpk__: param.scale must be 0 (no scaling) or 1 (equilibration scaling [default]) or 2 (geometric mean scaling)"); |
541 if (numtmp != 0 && numtmp != 1 && numtmp != 2) | 644 return retval; |
542 { | |
543 OCTOUT << "'scale' parameter must be only:\n\t0 - no scaling,\n\t1 - equilibration scaling,\n\t2 - geometric mean scaling\n"; | |
544 return retval; | |
545 } | |
546 lpxIntParam[1] = static_cast<int> (numtmp); | |
547 } | 645 } |
548 | 646 |
549 //-- Dual dimplex option | 647 //-- Dual dimplex option |
550 if (PARAM.contains ("dual")) | 648 OCTAVE_GLPK_GET_INT_PARAM ("dual", lpxIntParam[2]); |
551 { | 649 if (lpxIntParam[2] < 0 || lpxIntParam[2] > 1) |
552 octave_value tmp = PARAM.contents (PARAM.seek ("dual"))(0); | 650 { |
553 double numtmp = tmp.scalar_value (); | 651 error ("__glpk__: param.dual must be 0 (do NOT use dual simplex [default]) or 1 (use dual simplex)"); |
554 if (numtmp != 0 && numtmp != 1) | 652 return retval; |
555 { | |
556 OCTOUT<<"'dual' parameter must be only:\n\t0 - do not use the dual simplex [default],\n\t1 - use dual simplex\n"; | |
557 return retval; | |
558 } | |
559 lpxIntParam[2] = static_cast<int> (numtmp); | |
560 } | 653 } |
561 | 654 |
562 //-- Pricing option | 655 //-- Pricing option |
563 if (PARAM.contains ("price")) | 656 OCTAVE_GLPK_GET_INT_PARAM ("price", lpxIntParam[3]); |
564 { | 657 if (lpxIntParam[3] < 0 || lpxIntParam[3] > 1) |
565 octave_value tmp = PARAM.contents (PARAM.seek ("price"))(0); | 658 { |
566 double numtmp = tmp.scalar_value(); | 659 error ("__glpk__: param.price must be 0 (textbook pricing) or 1 (steepest edge pricing [default])"); |
567 if (numtmp != 0 && numtmp != 1) | 660 return retval; |
568 { | 661 } |
569 OCTOUT << "'price' parameter must be only:\n\t0 - textbook pricing,\n\t1 - steepest edge pricing [default]\n"; | |
570 return retval; | |
571 } | |
572 lpxIntParam[3] = static_cast<int> (numtmp); | |
573 } | |
574 | 662 |
575 //-- Solution rounding option | 663 //-- Solution rounding option |
576 if (PARAM.contains ("round")) | 664 OCTAVE_GLPK_GET_INT_PARAM ("round", lpxIntParam[4]); |
577 { | 665 if (lpxIntParam[4] < 0 || lpxIntParam[4] > 1) |
578 octave_value tmp = PARAM.contents (PARAM.seek ("round"))(0); | 666 { |
579 double numtmp = tmp.scalar_value (); | 667 error ("__glpk__: param.round must be 0 (report all primal and dual values [default]) or 1 (replace tiny primal and dual values by exact zero)"); |
580 if (numtmp != 0 && numtmp != 1) | 668 return retval; |
581 { | |
582 OCTOUT << "'round' parameter must be only:\n\t0 - report all primal and dual values [default],\n\t1 - replace tiny primal and dual values by exact zero\n"; | |
583 return retval; | |
584 } | |
585 lpxIntParam[4] = static_cast<int> (numtmp); | |
586 } | 669 } |
587 | 670 |
588 //-- Simplex iterations limit | 671 //-- Simplex iterations limit |
589 if (PARAM.contains ("itlim")) | 672 OCTAVE_GLPK_GET_INT_PARAM ("itlim", lpxIntParam[5]); |
590 { | |
591 octave_value tmp = PARAM.contents (PARAM.seek ("itlim"))(0); | |
592 lpxIntParam[5] = static_cast<int> (tmp.scalar_value ()); | |
593 } | |
594 | 673 |
595 //-- Simplex iterations count | 674 //-- Simplex iterations count |
596 if (PARAM.contains ("itcnt")) | 675 OCTAVE_GLPK_GET_INT_PARAM ("itcnt", lpxIntParam[6]); |
597 { | |
598 octave_value tmp = PARAM.contents (PARAM.seek ("itcnt"))(0); | |
599 lpxIntParam[6] = static_cast<int> (tmp.scalar_value ()); | |
600 } | |
601 | 676 |
602 //-- Output frequency, in iterations | 677 //-- Output frequency, in iterations |
603 if (PARAM.contains ("outfrq")) | 678 OCTAVE_GLPK_GET_INT_PARAM ("outfrq", lpxIntParam[7]); |
604 { | |
605 octave_value tmp = PARAM.contents (PARAM.seek ("outfrq"))(0); | |
606 lpxIntParam[7] = static_cast<int> (tmp.scalar_value ()); | |
607 } | |
608 | 679 |
609 //-- Branching heuristic option | 680 //-- Branching heuristic option |
610 if (PARAM.contains("branch")) | 681 OCTAVE_GLPK_GET_INT_PARAM ("branch", lpxIntParam[14]); |
611 { | 682 if (lpxIntParam[14] < 0 || lpxIntParam[14] > 2) |
612 octave_value tmp = PARAM.contents (PARAM.seek ("branch"))(0); | 683 { |
613 double numtmp = tmp.scalar_value (); | 684 error ("__glpk__: param.branch must be (MIP only) 0 (branch on first variable) or 1 (branch on last variable) or 2 (branch using a heuristic by Driebeck and Tomlin [default]"); |
614 if (numtmp != 0 && numtmp != 1 && numtmp != 2) | 685 return retval; |
615 { | 686 } |
616 OCTOUT << "'branch' parameter must be only (for MIP only):\n\t0 - branch on the first variable,\n\t1 - branch on the last variable,\n\t2 - branch using a heuristic by Driebeck and Tomlin [default]\n"; | |
617 return retval; | |
618 } | |
619 lpxIntParam[14] = static_cast<int> (numtmp); | |
620 } | |
621 | 687 |
622 //-- Backtracking heuristic option | 688 //-- Backtracking heuristic option |
623 if (PARAM.contains ("btrack")) | 689 OCTAVE_GLPK_GET_INT_PARAM ("btrack", lpxIntParam[15]); |
624 { | 690 if (lpxIntParam[15] < 0 || lpxIntParam[15] > 2) |
625 octave_value tmp = PARAM.contents (PARAM.seek ("btrack"))(0); | 691 { |
626 double numtmp = tmp.scalar_value (); | 692 error ("__glpk__: param.btrack must be (MIP only) 0 (depth first search) or 1 (breadth first search) or 2 (backtrack using the best projection heuristic [default]"); |
627 if (numtmp != 0 && numtmp != 1 && numtmp != 2) | 693 return retval; |
628 { | 694 } |
629 OCTOUT << "'btrack' parameter must be only (for MIP only):\n\t0 - depth first search,\n\t1 - breadth first search,\n\t2 - backtrack using the best projection heuristic\n"; | |
630 return retval; | |
631 } | |
632 lpxIntParam[15] = static_cast<int> (numtmp); | |
633 } | |
634 | 695 |
635 //-- Presolver option | 696 //-- Presolver option |
636 if (PARAM.contains ("presol")) | 697 OCTAVE_GLPK_GET_INT_PARAM ("presol", lpxIntParam[16]); |
637 { | 698 if (lpxIntParam[16] < 0 || lpxIntParam[16] > 1) |
638 octave_value tmp = PARAM.contents (PARAM.seek ("presol"))(0); | 699 { |
639 double numtmp = tmp.scalar_value (); | 700 error ("__glpk__: param.presol must be 0 (do NOT use LP presolver) or 1 (use LP presolver [default])"); |
640 if (numtmp != 0 && numtmp != 1) | 701 return retval; |
641 { | |
642 OCTOUT << "'presol' parameter must be only:\n\t0 - LP presolver is ***NOT*** used,\n\t1 - LP presol is used\n"; | |
643 return retval; | |
644 } | |
645 lpxIntParam[16] = static_cast<int> (numtmp); | |
646 } | 702 } |
647 | 703 |
648 //-- LPsolver option | 704 //-- LPsolver option |
649 volatile int lpsolver = 1; | 705 volatile int lpsolver = 1; |
650 if (PARAM.contains ("lpsolver")) | 706 OCTAVE_GLPK_GET_INT_PARAM ("lpsolver", lpsolver); |
651 { | 707 if (lpsolver < 1 || lpsolver > 2) |
652 octave_value tmp = PARAM.contents (PARAM.seek ("lpsolver"))(0); | 708 { |
653 double numtmp = tmp.scalar_value (); | 709 error ("__glpk__: param.lpsolver must be 1 (simplex method) or 2 (interior point method)"); |
654 if (numtmp != 1 && numtmp != 2) | 710 return retval; |
655 { | |
656 OCTOUT << "'lpsolver' parameter must be only:\n\t1 - simplex method,\n\t2 - interior point method\n"; | |
657 return retval; | |
658 } | |
659 lpsolver = static_cast<int> (numtmp); | |
660 } | 711 } |
661 | 712 |
662 //-- Save option | 713 //-- Save option |
663 volatile int save_pb = 0; | 714 volatile int save_pb = 0; |
664 if (PARAM.contains ("save")) | 715 OCTAVE_GLPK_GET_INT_PARAM ("save", save_pb); |
665 { | 716 save_pb = save_pb != 0; |
666 octave_value tmp = PARAM.contents (PARAM.seek ("save"))(0); | |
667 save_pb = (tmp.scalar_value () != 0); | |
668 } | |
669 | 717 |
670 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 718 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
671 //-- Real parameters | 719 //-- Real parameters |
672 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 720 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
673 | 721 |
674 //-- Ratio test option | 722 //-- Ratio test option |
675 if (PARAM.contains ("relax")) | 723 OCTAVE_GLPK_GET_REAL_PARAM ("relax", 0); |
676 { | |
677 octave_value tmp = PARAM.contents (PARAM.seek ("relax"))(0); | |
678 lpxRealParam[0] = tmp.scalar_value (); | |
679 } | |
680 | 724 |
681 //-- Relative tolerance used to check if the current basic solution | 725 //-- Relative tolerance used to check if the current basic solution |
682 //-- is primal feasible | 726 //-- is primal feasible |
683 if (PARAM.contains ("tolbnd")) | 727 OCTAVE_GLPK_GET_REAL_PARAM ("tolbnd", 1); |
684 { | |
685 octave_value tmp = PARAM.contents (PARAM.seek ("tolbn"))(0); | |
686 lpxRealParam[1] = tmp.scalar_value (); | |
687 } | |
688 | 728 |
689 //-- Absolute tolerance used to check if the current basic solution | 729 //-- Absolute tolerance used to check if the current basic solution |
690 //-- is dual feasible | 730 //-- is dual feasible |
691 if (PARAM.contains ("toldj")) | 731 OCTAVE_GLPK_GET_REAL_PARAM ("toldj", 2); |
692 { | |
693 octave_value tmp = PARAM.contents (PARAM.seek ("toldj"))(0); | |
694 lpxRealParam[2] = tmp.scalar_value(); | |
695 } | |
696 | 732 |
697 //-- Relative tolerance used to choose eligible pivotal elements of | 733 //-- Relative tolerance used to choose eligible pivotal elements of |
698 //-- the simplex table in the ratio test | 734 //-- the simplex table in the ratio test |
699 if (PARAM.contains ("tolpiv")) | 735 OCTAVE_GLPK_GET_REAL_PARAM ("tolpiv", 3); |
700 { | 736 |
701 octave_value tmp = PARAM.contents (PARAM.seek ("tolpiv"))(0); | 737 OCTAVE_GLPK_GET_REAL_PARAM ("objll", 4); |
702 lpxRealParam[3] = tmp.scalar_value (); | 738 |
703 } | 739 OCTAVE_GLPK_GET_REAL_PARAM ("objul", 5); |
704 | 740 |
705 if (PARAM.contains ("objll")) | 741 OCTAVE_GLPK_GET_REAL_PARAM ("tmlim", 6); |
706 { | 742 |
707 octave_value tmp = PARAM.contents (PARAM.seek ("objll"))(0); | 743 OCTAVE_GLPK_GET_REAL_PARAM ("outdly", 7); |
708 lpxRealParam[4] = tmp.scalar_value (); | 744 |
709 } | 745 OCTAVE_GLPK_GET_REAL_PARAM ("tolint", 8); |
710 | 746 |
711 if (PARAM.contains ("objul")) | 747 OCTAVE_GLPK_GET_REAL_PARAM ("tolobj", 9); |
712 { | |
713 octave_value tmp = PARAM.contents (PARAM.seek ("objul"))(0); | |
714 lpxRealParam[5] = tmp.scalar_value (); | |
715 } | |
716 | |
717 if (PARAM.contains ("tmlim")) | |
718 { | |
719 octave_value tmp = PARAM.contents (PARAM.seek ("tmlim"))(0); | |
720 lpxRealParam[6] = tmp.scalar_value (); | |
721 } | |
722 | |
723 if (PARAM.contains ("outdly")) | |
724 { | |
725 octave_value tmp = PARAM.contents (PARAM.seek ("outdly"))(0); | |
726 lpxRealParam[7] = tmp.scalar_value (); | |
727 } | |
728 | |
729 if (PARAM.contains ("tolint")) | |
730 { | |
731 octave_value tmp = PARAM.contents (PARAM.seek ("tolint"))(0); | |
732 lpxRealParam[8] = tmp.scalar_value (); | |
733 } | |
734 | |
735 if (PARAM.contains ("tolobj")) | |
736 { | |
737 octave_value tmp = PARAM.contents (PARAM.seek ("tolobj"))(0); | |
738 lpxRealParam[9] = tmp.scalar_value (); | |
739 } | |
740 | 748 |
741 //-- Assign pointers to the output parameters | 749 //-- Assign pointers to the output parameters |
742 ColumnVector xmin (mrowsc); | 750 ColumnVector xmin (mrowsc); |
743 ColumnVector fmin (1); | 751 ColumnVector fmin (1); |
744 ColumnVector status (1); | 752 ColumnVector status (1); |