Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__glpk__.cc @ 5235:5f0ad69b5c8c
[project @ 2005-03-22 19:48:16 by jwe]
author | jwe |
---|---|
date | Tue, 22 Mar 2005 19:48:46 +0000 |
parents | a791b8b777e4 |
children | 652e8aa49fa7 |
comparison
equal
deleted
inserted
replaced
5234:a791b8b777e4 | 5235:5f0ad69b5c8c |
---|---|
28 #include <csetjmp> | 28 #include <csetjmp> |
29 #include <ctime> | 29 #include <ctime> |
30 | 30 |
31 #include "defun-dld.h" | 31 #include "defun-dld.h" |
32 #include "error.h" | 32 #include "error.h" |
33 #include "gripes.h" | |
34 #include "oct-map.h" | |
33 #include "oct-obj.h" | 35 #include "oct-obj.h" |
36 #include "pager.h" | |
37 | |
38 #if defined (HAVE_GLPK) | |
34 | 39 |
35 extern "C" { | 40 extern "C" { |
36 #include <glpk.h> | 41 #include <glpk.h> |
37 } | 42 } |
38 | 43 |
111 jmp_buf mark; //-- Address for long jump to jump to | 116 jmp_buf mark; //-- Address for long jump to jump to |
112 int fperr; //-- Global error number | 117 int fperr; //-- Global error number |
113 | 118 |
114 | 119 |
115 int | 120 int |
116 glpk_fault_hook (void *info, char *msg) | 121 glpk_fault_hook (void * /* info */, char *msg) |
117 { | 122 { |
118 OCTERR << "*** SEVERE CRITICAL ERROR *** from GLPK !\n\n"<<msg<<" %s\n"; | 123 OCTERR << "*** SEVERE CRITICAL ERROR *** from GLPK !\n\n"<<msg<<" %s\n"; |
119 longjmp (mark, -1); | 124 longjmp (mark, -1); |
120 } | 125 } |
121 | 126 |
122 int | 127 int |
123 glpk_print_hook (void *info, char *msg) | 128 glpk_print_hook (void * /* info */, char *msg) |
124 { | 129 { |
125 OCTERR << msg << "\n"; | 130 OCTERR << msg << "\n"; |
126 return 1; | 131 return 1; |
127 } | 132 } |
128 | 133 |
265 method = 'I'; | 270 method = 'I'; |
266 error = lpx_simplex (lp); | 271 error = lpx_simplex (lp); |
267 error = lpx_integer (lp); | 272 error = lpx_integer (lp); |
268 } | 273 } |
269 else | 274 else |
270 error=lpx_simplex(lp); | 275 error = lpx_simplex(lp); |
271 } | 276 } |
272 break; | 277 break; |
273 | 278 |
274 case 'T': | 279 case 'T': |
275 error = lpx_interior(lp); | 280 error = lpx_interior(lp); |
352 *status= static_cast<double> (error); | 357 *status= static_cast<double> (error); |
353 | 358 |
354 return error; | 359 return error; |
355 } | 360 } |
356 | 361 |
357 DEFUN_DLD (__glpk__, args, nlhs, | 362 #endif |
363 | |
364 DEFUN_DLD (__glpk__, args, , | |
358 "__glpk__: internal interface for the GLPK library.\n\ | 365 "__glpk__: internal interface for the GLPK library.\n\ |
359 You should be using using glpk instead") | 366 You should be using using glpk instead") |
360 { | 367 { |
361 // The list of values to return. See the declaration in oct-obj.h | 368 // The list of values to return. See the declaration in oct-obj.h |
362 octave_value_list retval; | 369 octave_value_list retval; |
363 | 370 |
371 #if defined (HAVE_GLPK) | |
372 | |
364 int nrhs = args.length (); | 373 int nrhs = args.length (); |
365 | 374 |
366 if (nrhs < 1) | 375 if (nrhs < 1) |
367 { | 376 { |
368 OCTERR<<"Use the script glpk for the optimization\n"; | 377 OCTERR<<"Use the script glpk for the optimization\n"; |
369 return retval; | 378 return retval; |
370 } | 379 } |
371 | 380 |
372 //-- 1st Input. Sense of optimization. | 381 //-- 1st Input. Sense of optimization. |
373 int sense; | 382 volatile int sense; |
374 double SENSE = args(0).scalar_value (); | 383 double SENSE = args(0).scalar_value (); |
375 if (SENSE> = 0) | 384 if (SENSE >= 0) |
376 sense = 1; | 385 sense = 1; |
377 else | 386 else |
378 sense = -1; | 387 sense = -1; |
379 | 388 |
380 //-- 2nd Input. A column array containing the objective function | 389 //-- 2nd Input. A column array containing the objective function |
391 Matrix A (args(2).matrix_value ()); // get the matrix | 400 Matrix A (args(2).matrix_value ()); // get the matrix |
392 Array<int> rn (mrowsA*mrowsc+1); | 401 Array<int> rn (mrowsA*mrowsc+1); |
393 Array<int> cn (mrowsA*mrowsc+1); | 402 Array<int> cn (mrowsA*mrowsc+1); |
394 ColumnVector a (mrowsA*mrowsc+1, 0.0); | 403 ColumnVector a (mrowsA*mrowsc+1, 0.0); |
395 | 404 |
396 int nz = 0; | 405 volatile int nz = 0; |
397 for (int i = 0; i < mrowsA; i++) | 406 for (int i = 0; i < mrowsA; i++) |
398 { | 407 { |
399 for (int j = 0; j < mrowsc; j++) | 408 for (int j = 0; j < mrowsc; j++) |
400 { | 409 { |
401 if (A(i,j) != 0) | 410 if (A(i,j) != 0) |
488 | 497 |
489 //-- 8th Input. A column array containing the types of the variables. | 498 //-- 8th Input. A column array containing the types of the variables. |
490 charMatrix VTYPE (args(7).char_matrix_value ()); | 499 charMatrix VTYPE (args(7).char_matrix_value ()); |
491 | 500 |
492 Array<int> vartype (mrowsc); | 501 Array<int> vartype (mrowsc); |
493 int isMIP; | 502 volatile int isMIP = 0; |
494 for (int i = 0; i < mrowsc ; i++) | 503 for (int i = 0; i < mrowsc ; i++) |
495 { | 504 { |
496 if (VTYPE(i,0) == 'I') | 505 if (VTYPE(i,0) == 'I') |
497 { | 506 { |
498 isMIP = 1; | 507 isMIP = 1; |
499 vartype(i) = LPX_IV; | 508 vartype(i) = LPX_IV; |
500 } | 509 } |
501 else | 510 else |
502 { | 511 vartype(i) = LPX_CV; |
503 vartype(i) = LPX_CV; | |
504 } | |
505 } | 512 } |
506 | 513 |
507 //-- 9th Input. A structure containing the control parameters. | 514 //-- 9th Input. A structure containing the control parameters. |
508 Octave_map PARAM = args(8).map_value (); | 515 Octave_map PARAM = args(8).map_value (); |
509 | 516 |
727 ColumnVector redcosts (mrowsc); | 734 ColumnVector redcosts (mrowsc); |
728 ColumnVector time (1); | 735 ColumnVector time (1); |
729 ColumnVector mem (1); | 736 ColumnVector mem (1); |
730 | 737 |
731 int jmpret = setjmp (mark); | 738 int jmpret = setjmp (mark); |
739 | |
732 if (jmpret == 0) | 740 if (jmpret == 0) |
733 { | 741 glpk (sense, mrowsc, mrowsA, c, nz, rn.fortran_vec (), |
734 int error = glpk (sense, mrowsc, mrowsA, c, nz, rn.fortran_vec (), | 742 cn.fortran_vec (), a.fortran_vec (), b, ctype, |
735 cn.fortran_vec (), a.fortran_vec (), b, ctype, | 743 freeLB.fortran_vec (), lb, freeUB.fortran_vec (), |
736 freeLB.fortran_vec (), lb, freeUB.fortran_vec (), | 744 ub, vartype.fortran_vec (), isMIP, lpsolver, |
737 ub, vartype.fortran_vec (), isMIP, lpsolver, | 745 save_pb, xmin.fortran_vec (), fmin.fortran_vec (), |
738 save_pb, xmin.fortran_vec (), fmin.fortran_vec (), | 746 status.fortran_vec (), lambda.fortran_vec (), |
739 status.fortran_vec (), lambda.fortran_vec (), | 747 redcosts.fortran_vec (), time.fortran_vec (), |
740 redcosts.fortran_vec (), time.fortran_vec (), | 748 mem.fortran_vec ()); |
741 mem.fortran_vec ()); | |
742 } | |
743 | 749 |
744 Octave_map extra; | 750 Octave_map extra; |
745 | 751 |
746 extra.assign ("lambda", octave_value (lambda)); | 752 extra.assign ("lambda", octave_value (lambda)); |
747 extra.assign ("redcosts", octave_value (redcosts)); | 753 extra.assign ("redcosts", octave_value (redcosts)); |
751 retval(3) = extra; | 757 retval(3) = extra; |
752 retval(2) = octave_value(status); | 758 retval(2) = octave_value(status); |
753 retval(1) = octave_value(fmin); | 759 retval(1) = octave_value(fmin); |
754 retval(0) = octave_value(xmin); | 760 retval(0) = octave_value(xmin); |
755 | 761 |
762 #else | |
763 | |
764 gripe_not_supported ("glpk"); | |
765 | |
766 #endif | |
767 | |
756 return retval; | 768 return retval; |
757 } | 769 } |