Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__glpk__.cc @ 5237:652e8aa49fa7
[project @ 2005-03-23 21:28:45 by jwe]
author | jwe |
---|---|
date | Wed, 23 Mar 2005 21:28:46 +0000 |
parents | 5f0ad69b5c8c |
children | d432b7809fe5 |
comparison
equal
deleted
inserted
replaced
5236:6879f10db3a4 | 5237:652e8aa49fa7 |
---|---|
376 { | 376 { |
377 OCTERR<<"Use the script glpk for the optimization\n"; | 377 OCTERR<<"Use the script glpk for the optimization\n"; |
378 return retval; | 378 return retval; |
379 } | 379 } |
380 | 380 |
381 //-- 1st Input. Sense of optimization. | 381 //-- 1nd Input. A column array containing the objective function |
382 volatile int sense; | |
383 double SENSE = args(0).scalar_value (); | |
384 if (SENSE >= 0) | |
385 sense = 1; | |
386 else | |
387 sense = -1; | |
388 | |
389 //-- 2nd Input. A column array containing the objective function | |
390 //-- coefficients. | 382 //-- coefficients. |
391 int mrowsc = args(1).rows(); | 383 int mrowsc = args(0).rows(); |
392 | 384 |
393 Matrix C (args(1).matrix_value ()); | 385 Matrix C (args(0).matrix_value ()); |
394 double *c = C.fortran_vec (); | 386 double *c = C.fortran_vec (); |
395 | 387 |
396 //-- 3rd Input. A matrix containing the constraints coefficients. | 388 //-- 2nd Input. A matrix containing the constraints coefficients. |
397 // If matrix A is NOT a sparse matrix | 389 // If matrix A is NOT a sparse matrix |
398 // if(!mxIsSparse(A_IN)){ | 390 // if(!mxIsSparse(A_IN)){ |
399 int mrowsA = args(2).rows(); | 391 int mrowsA = args(1).rows(); |
400 Matrix A (args(2).matrix_value ()); // get the matrix | 392 Matrix A (args(1).matrix_value ()); // get the matrix |
401 Array<int> rn (mrowsA*mrowsc+1); | 393 Array<int> rn (mrowsA*mrowsc+1); |
402 Array<int> cn (mrowsA*mrowsc+1); | 394 Array<int> cn (mrowsA*mrowsc+1); |
403 ColumnVector a (mrowsA*mrowsc+1, 0.0); | 395 ColumnVector a (mrowsA*mrowsc+1, 0.0); |
404 | 396 |
405 volatile int nz = 0; | 397 volatile int nz = 0; |
447 // row++; | 439 // row++; |
448 // } | 440 // } |
449 // } | 441 // } |
450 // } | 442 // } |
451 | 443 |
452 //-- 4th Input. A column array containing the right-hand side value | 444 //-- 3rd Input. A column array containing the right-hand side value |
453 // for each constraint in the constraint matrix. | 445 // for each constraint in the constraint matrix. |
454 Matrix B (args(3).matrix_value ()); | 446 Matrix B (args(2).matrix_value ()); |
455 double *b = B.fortran_vec (); | 447 double *b = B.fortran_vec (); |
456 | 448 |
457 //-- 5th Input. A column array containing the sense of each constraint | 449 //-- 4th Input. An array of length mrowsc containing the lower |
458 //-- in the constraint matrix. | |
459 charMatrix CTYPE (args(4).char_matrix_value ()); | |
460 char *ctype = CTYPE.fortran_vec (); | |
461 | |
462 //-- 6th Input. An array of length mrowsc containing the lower | |
463 //-- bound on each of the variables. | 450 //-- bound on each of the variables. |
464 Matrix LB (args(5).matrix_value ()); | 451 Matrix LB (args(3).matrix_value ()); |
465 double *lb = LB.fortran_vec (); | 452 double *lb = LB.fortran_vec (); |
466 | 453 |
467 //-- LB argument, default: Free | 454 //-- LB argument, default: Free |
468 Array<int> freeLB (mrowsc); | 455 Array<int> freeLB (mrowsc); |
469 for (int i = 0; i < mrowsc; i++) | 456 for (int i = 0; i < mrowsc; i++) |
475 } | 462 } |
476 else | 463 else |
477 freeLB(i) = 0; | 464 freeLB(i) = 0; |
478 } | 465 } |
479 | 466 |
480 //-- 7th Input. An array of at least length numcols containing the upper | 467 //-- 5th Input. An array of at least length numcols containing the upper |
481 //-- bound on each of the variables. | 468 //-- bound on each of the variables. |
482 Matrix UB (args(6).matrix_value ()); | 469 Matrix UB (args(4).matrix_value ()); |
483 | 470 |
484 double *ub = UB.fortran_vec (); | 471 double *ub = UB.fortran_vec (); |
485 | 472 |
486 Array<int> freeUB (mrowsc); | 473 Array<int> freeUB (mrowsc); |
487 for (int i = 0; i < mrowsc; i++) | 474 for (int i = 0; i < mrowsc; i++) |
493 } | 480 } |
494 else | 481 else |
495 freeUB(i) = 0; | 482 freeUB(i) = 0; |
496 } | 483 } |
497 | 484 |
498 //-- 8th Input. A column array containing the types of the variables. | 485 //-- 6th Input. A column array containing the sense of each constraint |
499 charMatrix VTYPE (args(7).char_matrix_value ()); | 486 //-- in the constraint matrix. |
487 charMatrix CTYPE (args(5).char_matrix_value ()); | |
488 char *ctype = CTYPE.fortran_vec (); | |
489 | |
490 //-- 7th Input. A column array containing the types of the variables. | |
491 charMatrix VTYPE (args(6).char_matrix_value ()); | |
500 | 492 |
501 Array<int> vartype (mrowsc); | 493 Array<int> vartype (mrowsc); |
502 volatile int isMIP = 0; | 494 volatile int isMIP = 0; |
503 for (int i = 0; i < mrowsc ; i++) | 495 for (int i = 0; i < mrowsc ; i++) |
504 { | 496 { |
509 } | 501 } |
510 else | 502 else |
511 vartype(i) = LPX_CV; | 503 vartype(i) = LPX_CV; |
512 } | 504 } |
513 | 505 |
506 //-- 8th Input. Sense of optimization. | |
507 volatile int sense; | |
508 double SENSE = args(7).scalar_value (); | |
509 if (SENSE >= 0) | |
510 sense = 1; | |
511 else | |
512 sense = -1; | |
513 | |
514 //-- 9th Input. A structure containing the control parameters. | 514 //-- 9th Input. A structure containing the control parameters. |
515 Octave_map PARAM = args(8).map_value (); | 515 Octave_map PARAM = args(8).map_value (); |
516 | 516 |
517 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 517 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
518 //-- Integer parameters | 518 //-- Integer parameters |
643 return retval; | 643 return retval; |
644 } | 644 } |
645 lpxIntParam[16] = static_cast<int> (numtmp); | 645 lpxIntParam[16] = static_cast<int> (numtmp); |
646 } | 646 } |
647 | 647 |
648 //-- LPsolver option | |
649 volatile int lpsolver = 1; | |
650 if (PARAM.contains ("lpsolver")) | |
651 { | |
652 octave_value tmp = PARAM.contents (PARAM.seek ("lpsolver"))(0); | |
653 double numtmp = tmp.scalar_value (); | |
654 if (numtmp != 1 && numtmp != 2) | |
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 } | |
661 | |
662 //-- Save option | |
663 volatile int save_pb = 0; | |
664 if (PARAM.contains ("save")) | |
665 { | |
666 octave_value tmp = PARAM.contents (PARAM.seek ("save"))(0); | |
667 save_pb = (tmp.scalar_value () != 0); | |
668 } | |
669 | |
648 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 670 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
649 //-- Real parameters | 671 //-- Real parameters |
650 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 672 //-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
651 | 673 |
652 //-- Ratio test option | 674 //-- Ratio test option |
713 if (PARAM.contains ("tolobj")) | 735 if (PARAM.contains ("tolobj")) |
714 { | 736 { |
715 octave_value tmp = PARAM.contents (PARAM.seek ("tolobj"))(0); | 737 octave_value tmp = PARAM.contents (PARAM.seek ("tolobj"))(0); |
716 lpxRealParam[9] = tmp.scalar_value (); | 738 lpxRealParam[9] = tmp.scalar_value (); |
717 } | 739 } |
718 | |
719 //-- 10th Input. If the problem is a LP problem you may select which solver | |
720 //-- use: RSM (Revised Simplex Method) or IPM (Interior Point Method). | |
721 //-- If the problem is a MIP problem this field will be ignored. | |
722 octave_value tmp = args(9).scalar_value (); | |
723 int lpsolver = static_cast<int> (tmp.scalar_value ()); | |
724 | |
725 //-- 11th Input. Saves a copy of the problem if SAVE<>0. | |
726 tmp = args(10).scalar_value(); | |
727 int save_pb = (tmp.scalar_value() != 0); | |
728 | 740 |
729 //-- Assign pointers to the output parameters | 741 //-- Assign pointers to the output parameters |
730 ColumnVector xmin (mrowsc); | 742 ColumnVector xmin (mrowsc); |
731 ColumnVector fmin (1); | 743 ColumnVector fmin (1); |
732 ColumnVector status (1); | 744 ColumnVector status (1); |