cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Optimization problem using minimize function

SOLVED
Highlighted
Level 8

Optimization problem using minimize function

Hello everyone!

This is my first post, I'm glad to be here. Let's cut to the chase. 

 

I have created  an objective function  which has 5 variables. I gave 5 constraints. Probably a typical problem. But when i try to optimize it with the minimize function mathcad spent all night calculating it and it did not come up with anything. I am new to this, so probably missing the point Smiley Happy I will be thankful for any piece of advice.opt.png

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Optimization problem using minimize function

OK, as promised here is my speeded up version.

Hope the my first interpretation of the function Y is the one you need - otherwise we would have to invest some more work to make the solve block respect ALL constraints (if possible at all).

I also include a pdf-print of the sheet.

As you see your original Y-function evaluates in about 12 seconds. The 51 sec of what I wrote earlier came about the fact that my machine was busy with some video recoding which eat up nearly all my CPU power ;-)

So your reduction from 583 points to somewhat over 400 seems not to be necessary at all.

Note that because of the various use of the time() function the sheet will recalculate every time before printing or saving which is annoying. You might want to get rid of tall the unnecessary regions as soon as possible.

 

22 REPLIES 22

Re: Optimization problem using minimize function

Attach please Mathcad-sheet!

Ans second!

Call please your objective function OF after the giving guess values of aa, ab etc!

Use please the Minimize function without constrains and than in put constrains step-by-step!

Good luck!

Re: Optimization problem using minimize function

Thanks for the reply! I have enclosed the mathcad sheet with excel files, since it reads directly from them. I switched OF function with exact values as you said, but still it doesn't wish to calculate Smiley Very Happy

Re: Optimization problem using minimize function

Have you ever tried to call your function OF just ONE TIME?

I did, using your initial values, and after e few minutes it was still calculating and I cancelled the operation.

When trying to minimize, Mathcads algorithm would change your five arguments very often ever so slightly and will then call OF every time. If even one single call of OF takes that long, you can't expect the solve block to finish within a reasonable time.

The first thing to do is to look closer at the objective function if you can find a way to avoid that many nested loops which cost that many time in calculation.

Debugging of your sheet (if someone would be willing to take the time) is made more difficult and hindered by the fact, that the definition of some vital variables (Vol11, T0,..) is not visible as its hidden in a locked area.

 

Re: Optimization problem using minimize function

Just one additional observation:

You used the same variable name i for a loop and a sum within this loop.

I guess thats not an error and that Mathcad can handle this correct but its sure bad style and irritating. You may want to change the name of one of those variables as seen in the attached picture.

 

Re: Optimization problem using minimize function

Here is a first suggestion for an optimization of your sheet.

The way you had defined OF, the function Y is called for every summand of your sum, meaning it is called 583 times!

One single call to Y takes 51 seconds on my machine, so one single call to OF would take approx. 8 and a half hour!!

With the modification you see in the attached picture Y is called only once a one single call to OF takes a bit more than 51 seconds now.

Not sure if this is enough to make the solve block finish in reasonable time - I did not try as I suppose that it still will take quite some time as OF would be called many many times when trying to minimize it. At least it will now be about 580 times faster ;-)

Re: Optimization problem using minimize function

Thank you very much ! I reduced the number from 583 to 470. I cannot go lower unfortunately. Now it should theoretically calculate the case in 2 hours, since OF for one data gives me the result in 15 seconds.

Re: Optimization problem using minimize function

Why do you think it should solve in 2 hours?

We do not know how many changes the algorithm used for "minimize" will make and so we don't know how often OF will be called by the algorithm.

 

I guess you simply divided the 8 hours I mentioned by 4.

But those 8 hours simply were a guess how long it would take for ONE call to OF with the way you defined OF originally.

 

We can hardly guess how long the solve block would need to finish. The number of iterations done there depends on the algorithm used and is depended on how fast the convergence will be.

 

Re: Optimization problem using minimize function

I am sorry I blocked the  area in mathcad. I just had so many things there I thought It would be unreadable. I enclose it once again. But still from your experience having such a function with let's say 5 variables would it be possible to obtain the solution within 10 minutes for instance? 

Re: Optimization problem using minimize function


@Murarz wrote:

I am sorry I blocked the  area in mathcad. I just had so many things there I thought It would be unreadable. I enclose it once again. But still from your experience having such a function with let's say 5 variables would it be possible to obtain the solution within 10 minutes for instance? 


Yes it is possible.

I was just working on it and depending on the interpretation of your function Y it takes 1,5 to 3 minutes ;-)

I was able to speed up your function Y significantly and in combination of the aforementioned speeded up function OF this means that OF will now work with a 50000 times faster speed.

 

I'll upload the modified worksheet in a few minutes - just have to clean up one thing or another.

 

I'll upload the modified file in a few minutes.