7
$\begingroup$

I tried to run a large scale linear programming with mathematica. I entered the code below:

Import["A,B.mat", "LabeledData"]
x = LinearProgramming[{0, 0, -1}, A, B, {{-1, 100}, {0, 100}, {0, 100}}];
c.x

where A, B are two large scale matrices. {{-1, 100}, {0, 100}, {0, 100}} are bounds of variabels of linear programming. The code doesn't work and I think there is sth wrong with importing matrices A and B. How can I fix that?

Edit: Data file access from here

$\endgroup$
7
  • 2
    $\begingroup$ Please provide the data file so we can see for ourselves. $\endgroup$
    – Mr.Wizard
    Commented Jan 28, 2014 at 9:43
  • $\begingroup$ @Mr.Wizard Sorry. How can I add it to post? It is a .mat file (344 KB) $\endgroup$ Commented Jan 28, 2014 at 11:54
  • $\begingroup$ You will need to upload it somewhere accessible. I'm sorry, but StackExchange does not provide that service. Nevertheless without the data I feel that this question is impossible to answer. $\endgroup$
    – Mr.Wizard
    Commented Jan 28, 2014 at 12:12
  • 1
    $\begingroup$ @Mr.Wizard data file added. $\endgroup$ Commented Jan 28, 2014 at 12:19
  • 1
    $\begingroup$ @user2667048 you can try imp = Import["A.mat", "LabeledData"]; AA = "A" /. imp ; BB = "B" /. imp ; x = LinearProgramming[{0, 0, -1}, AA, Flatten@BB, {{-1, 100}, {0, 100}, {0, 100}}]; $\endgroup$
    – s.s.o
    Commented Jan 28, 2014 at 12:47

1 Answer 1

6
$\begingroup$

If you carefully check what has been imported, you'll see that it imports matrix labels and the values.

imp = Import["A.mat", "LabeledData"];

{"A" -> {{-1.13043, 1., 1.50927}, {-1.13043, 1., 1.50927},...

(*Get A and B matrix values*)
AA = "A" /. imp ; 
BB = "B" /. imp ; 

And flatten BB so that it becomes a vector.

x = LinearProgramming[{0, 0, -1}, AA, Flatten@BB,
      {{-1, 100}, {0, 100}, {0, 100}}];
c x
$\endgroup$
1
  • 2
    $\begingroup$ That's work. It's amazing that definition of inequality constrained in Mathematica and MATLAB are not the same. (I can't vote up! Thanks +1) $\endgroup$ Commented Jan 28, 2014 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.