-1

I am trying to do some network programming around optimization. Here is a reduced sample:

f = Minimize[{q,


  a + b <= q
&& c + d <= q                  // These represent edges in a network
&& c <= q
&& a + b + c + d <= q 
&& a + b + d <= q

&& a + b >= 1                 // other restraints
&& c + d >= 1

&& 0 <= a <= 1
&& 0 <= b <= 1
&& 0 <= c <= 1
&& 0 <= d <= 1

&& 0 <= q <= 4}, { q, a, b, c, d}]

While I have answers and know what I'm doing. My question is I wish to speed things up. I wish to change this code from that to this:

f = Minimize[{q,


  a + b <= iq
&& c + d <= iq
&& c <= iq
&& a + b + c + d <= iq 
&& a + b + d <= iq

&& a + b >= 1
&& c + d >= 1

&& 0 <= a <= 1
&& 0 <= b <= 1
&& 0 <= c <= 1
&& 0 <= d <= 1

&& 0 <= q <= (i*4)}, { q, a, b, c, d}]

where "i" will be an incrementing number.

I've been reading Stephen Wolfram's Mathematica second edition (1991?) book which I loaned from my university library, whilst it's been a major help in guiding me this far. It is a little outdated and searching the internet has provided little help either. I'm working with Mathematica 8.0.0.0.

I'm taking a guess that each line with i*q cannot have the same i as this would prove difficult in linear optimization(?)... Please correct me if I'm wrong

I'm a beginner to Mathematica and I'm finding the language to be much more easier to understand that Matlab. I have the answers I want or know how to get the remaining answers. I just want to speed things up.

Many thanks in helping me become more efficient in this program

EDIT::

Hi, thanks for the feedback.

@David: This isn't the full constraint table. I've reduced it down so some are missing. I apologise for missing constraints.

@Jinxed: Basically I'm trying to figure out q for incrementing values of i. So in a loop:

 a + b <= iq
 && c + d <= iq
 && c <= iq
 && a + b + c + d <= iq 
 && a + b + d <= iq

becomes =>

 a + b <= 2q
 && c + d <= 2iq
 && c <= 2iq
 && a + b + c + d <= 1q 
 && a + b + d <= 2iq

Then =>

 a + b <= 3q
 && c + d <= 3q
 && c <= 3q
 && a + b + c + d <= 1q 
 && a + b + d <= 3q

up until "i" reaches a top. I'm trying to observe what happens when I bottleneck particular edges in a network and the effects of it.

As I've said before, I'm a total beginner on this program so please forgive me if there are obvious fallings in places.

  • If speed is what you are looking for then there is the built-in LinearProgramming function which provides access to lots of the classical linear programming algorithms and should be faster and easier to use than crafting a manual Minimize. Look it up in the documentation or Google for it. – Bill Apr 07 '15 at 17:30
  • Are there any constraints on your variables (such as all non-negative)? You have $c+d \leq q$ and $c \leq q$ when only one is needed (assuming non-negative variables). Simplify your constraints first. Also, is $iq$ a separate variable? – David G. Stork Apr 07 '15 at 17:30
  • 1
    Are you aware of the 1000's of pages of built-in documentation? A massive resource of Mathematica information can be found here. – Sjoerd C. de Vries Apr 07 '15 at 17:35
  • iq looks like a typo: Did you mean i*q? What is it exactly, that you want to speed up? If it is execution speed, look at Bill's comment. If it is your speed in working with Mathematica , look at Sjoerd's. – Jinxed Apr 07 '15 at 17:41
  • Hi, please see edit in original post. I'm trying to speed up the results yield from having to change each value then run to just having a script run each value and output the everything I need. – user3402370 Apr 07 '15 at 17:56
  • This question would be much clearer if you posted the code that actually takes too much time. I've tried your first two code blocks, and neither takes more than a few milliseconds. Without that, the only tip that comes to mind is use FindMinimum instead of Minimize. Minimize tries to solve the problem symbolically, which is in general more expensive. FindMinimum uses local optimization, which is usually fastest, and for an LP is guaranteed to find the global minimum. – Niki Estner Apr 07 '15 at 19:11
  • 1
    Also, // does not start a comment in Mathematica code! – Niki Estner Apr 07 '15 at 19:12

1 Answers1

0

You mean this?

{"For i= " ~~ ToString[#] , Minimize[{q, 
 a + b <= # q && c + d <= # q && c <= # q && 
  a + b + c + d <= # q && a + b + d <= # q && a + b >= 1 && 
  c + d >= 1 && 0 <= a <= 1 && 0 <= b <= 1 && 0 <= c <= 1 && 
  0 <= d <= 1 && 0 <= q <= 4}, {q, a, b, c, d}]} & /@ Range[8]

Gives:

enter image description here

Lou
  • 3,822
  • 23
  • 26