Mercurial > octave-nkf
comparison scripts/optimization/glpk.m @ 10635:d1978e7364ad
Print name of function in error() string messages.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 22:26:54 -0700 |
parents | 95c3e38098bf |
children | be55736a0783 |
comparison
equal
deleted
inserted
replaced
10634:60542efcfa2c | 10635:d1978e7364ad |
---|---|
426 print_usage (); | 426 print_usage (); |
427 return; | 427 return; |
428 endif | 428 endif |
429 | 429 |
430 if (all (size (c) > 1) || iscomplex (c) || ischar (c)) | 430 if (all (size (c) > 1) || iscomplex (c) || ischar (c)) |
431 error ("C must be a real vector"); | 431 error ("glpk:C must be a real vector"); |
432 return; | 432 return; |
433 endif | 433 endif |
434 nx = length (c); | 434 nx = length (c); |
435 ## Force column vector. | 435 ## Force column vector. |
436 c = c(:); | 436 c = c(:); |
437 | 437 |
438 ## 2) Matrix constraint | 438 ## 2) Matrix constraint |
439 | 439 |
440 if (isempty (a)) | 440 if (isempty (a)) |
441 error ("A cannot be an empty matrix"); | 441 error ("glpk: A cannot be an empty matrix"); |
442 return; | 442 return; |
443 endif | 443 endif |
444 [nc, nxa] = size(a); | 444 [nc, nxa] = size(a); |
445 if (! isreal (a) || nxa != nx) | 445 if (! isreal (a) || nxa != nx) |
446 error ("A must be a real valued %d by %d matrix", nc, nx); | 446 error ("glpk: A must be a real valued %d by %d matrix", nc, nx); |
447 return; | 447 return; |
448 endif | 448 endif |
449 | 449 |
450 ## 3) RHS | 450 ## 3) RHS |
451 | 451 |
452 if (isempty (b)) | 452 if (isempty (b)) |
453 error ("B cannot be an empty vector"); | 453 error ("glpk: B cannot be an empty vector"); |
454 return; | 454 return; |
455 endif | 455 endif |
456 if (! isreal (b) || length (b) != nc) | 456 if (! isreal (b) || length (b) != nc) |
457 error ("B must be a real valued %d by 1 vector", nc); | 457 error ("glpk: B must be a real valued %d by 1 vector", nc); |
458 return; | 458 return; |
459 endif | 459 endif |
460 | 460 |
461 ## 4) Vector with the lower bound of each variable | 461 ## 4) Vector with the lower bound of each variable |
462 | 462 |
463 if (nargin > 3) | 463 if (nargin > 3) |
464 if (isempty (lb)) | 464 if (isempty (lb)) |
465 lb = zeros (nx, 1); | 465 lb = zeros (nx, 1); |
466 elseif (! isreal (lb) || all (size (lb) > 1) || length (lb) != nx) | 466 elseif (! isreal (lb) || all (size (lb) > 1) || length (lb) != nx) |
467 error ("LB must be a real valued %d by 1 column vector", nx); | 467 error ("glpk: LB must be a real valued %d by 1 column vector", nx); |
468 return; | 468 return; |
469 endif | 469 endif |
470 else | 470 else |
471 lb = zeros (nx, 1); | 471 lb = zeros (nx, 1); |
472 endif | 472 endif |
475 | 475 |
476 if (nargin > 4) | 476 if (nargin > 4) |
477 if (isempty (ub)) | 477 if (isempty (ub)) |
478 ub = Inf (nx, 1); | 478 ub = Inf (nx, 1); |
479 elseif (! isreal (ub) || all (size (ub) > 1) || length (ub) != nx) | 479 elseif (! isreal (ub) || all (size (ub) > 1) || length (ub) != nx) |
480 error ("UB must be a real valued %d by 1 column vector", nx); | 480 error ("glpk: UB must be a real valued %d by 1 column vector", nx); |
481 return; | 481 return; |
482 endif | 482 endif |
483 else | 483 else |
484 ub = Inf (nx, 1); | 484 ub = Inf (nx, 1); |
485 endif | 485 endif |
488 | 488 |
489 if (nargin > 5) | 489 if (nargin > 5) |
490 if (isempty (ctype)) | 490 if (isempty (ctype)) |
491 ctype = repmat ("S", nc, 1); | 491 ctype = repmat ("S", nc, 1); |
492 elseif (! ischar (ctype) || all (size (ctype) > 1) || length (ctype) != nc) | 492 elseif (! ischar (ctype) || all (size (ctype) > 1) || length (ctype) != nc) |
493 error ("CTYPE must be a char valued vector of length %d", nc); | 493 error ("glpk: CTYPE must be a char valued vector of length %d", nc); |
494 return; | 494 return; |
495 elseif (! all (ctype == "F" | ctype == "U" | ctype == "S" | 495 elseif (! all (ctype == "F" | ctype == "U" | ctype == "S" |
496 | ctype == "L" | ctype == "D")) | 496 | ctype == "L" | ctype == "D")) |
497 error ("CTYPE must contain only F, U, S, L, or D"); | 497 error ("glpk: CTYPE must contain only F, U, S, L, or D"); |
498 return; | 498 return; |
499 endif | 499 endif |
500 else | 500 else |
501 ctype = repmat ("S", nc, 1); | 501 ctype = repmat ("S", nc, 1); |
502 endif | 502 endif |
506 if (nargin > 6) | 506 if (nargin > 6) |
507 if (isempty (vartype)) | 507 if (isempty (vartype)) |
508 vartype = repmat ("C", nx, 1); | 508 vartype = repmat ("C", nx, 1); |
509 elseif (! ischar (vartype) || all (size (vartype) > 1) | 509 elseif (! ischar (vartype) || all (size (vartype) > 1) |
510 || length (vartype) != nx) | 510 || length (vartype) != nx) |
511 error ("VARTYPE must be a char valued vector of length %d", nx); | 511 error ("glpk: VARTYPE must be a char valued vector of length %d", nx); |
512 return; | 512 return; |
513 elseif (! all (vartype == "C" | vartype == "I")) | 513 elseif (! all (vartype == "C" | vartype == "I")) |
514 error ("VARTYPE must contain only C or I"); | 514 error ("glpk: VARTYPE must contain only C or I"); |
515 return; | 515 return; |
516 endif | 516 endif |
517 else | 517 else |
518 ## As default we consider continuous vars | 518 ## As default we consider continuous vars |
519 vartype = repmat ("C", nx, 1); | 519 vartype = repmat ("C", nx, 1); |
523 | 523 |
524 if (nargin > 7) | 524 if (nargin > 7) |
525 if (isempty (sense)) | 525 if (isempty (sense)) |
526 sense = 1; | 526 sense = 1; |
527 elseif (ischar (sense) || all (size (sense) > 1) || ! isreal (sense)) | 527 elseif (ischar (sense) || all (size (sense) > 1) || ! isreal (sense)) |
528 error ("SENSE must be an integer value"); | 528 error ("glpk: SENSE must be an integer value"); |
529 elseif (sense >= 0) | 529 elseif (sense >= 0) |
530 sense = 1; | 530 sense = 1; |
531 else | 531 else |
532 sense = -1; | 532 sense = -1; |
533 endif | 533 endif |
537 | 537 |
538 ## 9) Parameters vector | 538 ## 9) Parameters vector |
539 | 539 |
540 if (nargin > 8) | 540 if (nargin > 8) |
541 if (! isstruct (param)) | 541 if (! isstruct (param)) |
542 error ("PARAM must be a structure"); | 542 error ("glpk: PARAM must be a structure"); |
543 return; | 543 return; |
544 endif | 544 endif |
545 else | 545 else |
546 param = struct (); | 546 param = struct (); |
547 endif | 547 endif |