Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.9K Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Use a proper optimization function for a profit model?

Posted 9 years ago
Attachments:
POSTED BY: Scott T
6 Replies

Scott,

There is no need to "introduce" variables -- just use them. All the variable assignments you do are unnecessary and can lead to problems.

You seem to be very confused about when to use = and when to use ==. The single equal is an assignment -- think of it as a shortcut -- when you use it, Mathematica will immediately replace the left hand name with the right side.

The == is used to construct equations -- you only use this if you need an equation -- most of your model does not need equations and you only need them for the constraints in Minimize.

This is the cause of your errors. When you do

rawResourceAllocation = 
  rawAllocation == {{r1p1, r2p1, r3p1}, {r1p2, r2p2, r3p2}, {r1p3, 
     r2p3, r3p3}};

you believe that you can take parts of rawAllocation -- you cannot! it is only a variable in an equation. If you want to take parts, you must do this:

rawAllocation = {{r1p1, r2p1, r3p1}, {r1p2, r2p2, r3p2}, {r1p3, 
     r2p3, r3p3}};

You repeat this mistake throughout your model. You really never need == in this application. In this type of problem you will ONLY use == if you have a constraint such as

variable == 50, or variable1 + variable2==50.

Otherwise you do not need it in your problem.

You are very close. Send me an email at neils at the domain in my profile. I can give you better suggestions that way.

Regards

POSTED BY: Neil Singer
Posted 9 years ago

Neil, thank you so much for all your help!

I managed to modify my original optimization problem thanks to the input you gave. One final issue I'm having appears to be when I try to reference my matrices. I've attached my model for reference (with the errors) but here is a sample:

rawPlant1 = 
  rawAllocationPlant1 == 
   rawAllocation[[1, 1]] + rawAllocation[[1, 2]] + 
    rawAllocation[[1, 3]];

Error message: Part::partd: Part specification rawAllocation[[1,1]] is longer than depth of object. Part::partd: Part specification rawAllocation[[1,2]] is longer than depth of object. Part::partd: Part specification rawAllocation[[1,3]] is longer than depth of object.

Also, apologies in advance for the extra variables (region1plant1 = r1p1, etc) but I could not figure out how to introduce the variables any other way (can you just insert them into an assignment without having used them before?).

Thanks again...

Attachments:
POSTED BY: Scott T

Scott,

It is strange, I got your posting as an email but it is not here on the site.

Your problem is solved as follows:

CostofPart1 = 1;
CostofPart2 = 2;
NumberofPart1 = x;
NumberofPart2 = y;
ExCosts = 
  ExampleCosts == ((CostofPart1*NumberofPart1) + (CostofPart2*
       NumberofPart2));
ExampleRevenue = ExampleRev;
prof = ExampleRevenue - ExampleCosts;

Now construct the constraints -- they must be one expression separated by && -- (Eqn1 AND Eqn2 AND ...)

constraintsA = 
  ExampleCosts >= 100 && ExampleRev <= 1000 && 
   20 <= NumberofPart1 <= 80 && 20 <= NumberofPart2 <= 80;

Solve the problem with:

Maximize[{prof, constraintsA && ExCosts}, {ExampleCosts, ExampleRev, 
  NumberofPart1, NumberofPart2}]

to get:

{900, {ExampleCosts -> 100, ExampleRev -> 1000, x -> 20, y -> 40}}

Note that I used ";" to end lines to suppress printing. You are mixing up equations and variables and assignments. you solve for variables -- they do not have to be x and y but they must be consistently used. Also, you really should not have expressions like ExampleRevenue = ExampleRev Adding extra variables only confuses things. Just use the minimal number -- I left some in your example but I would avoid the confusion.

The answer of 900 is correct -- the profit is ExampleRev - ExampleCosts = (1000 - 100) = 900. The cost of 100 comes from the 20 units of x at 1 and 40 units of y at 2 (80 +20 = 100)

anything else would not maximize profit and meet the constraints.

Lastly it is bad form to start variables with Capital letters -- Mathematica internal symbols start with Cap letters -- yours should not.

I hope this helps

POSTED BY: Neil Singer

Scott,

I am not sure I understand your question. I assume you want to maximize profit subject to constraints?

POSTED BY: Neil Singer
Posted 9 years ago

Use a proper optimization function for a profit model?

POSTED BY: Scott T

Scott,

You want to start here in the documentation: Constrained Optimization. Your problem is a linear programming problem (use the LinearProgramming function in Mathematica.

Some general comments:

  1. While you can use x =Plus[a,b,c]. Its easier to do x = a+b+c
  2. Summing up a matrix row can be done by Total[m[[2]]] where 2 is the row number.
  3. Summing up a matrix column can be done by either Total[m[[;; , 2]]] or Total[m[[All, 2]]] (All rows, second column) (although you may prefer to itemize each element for clarity.
  4. you need to read about the difference between the assignment = and the == (Equal) operator. In constructing constraint equations for optimization you need to define equations like

    equation1 = totalcost == numberOfParts * costOfPart
    

If you put some variables in for some of your numbers and create equations and constraints (with == or >= or < , etc.) you can optimize your problem.

I hope this helps...

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard