Group Abstract Group Abstract

Message Boards Message Boards

0
|
6K 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

Hello,

First time user of Mathematica and I'm really enjoying it! I've created a profit maximization model for a manufacturing firm with many different variables. I want to figure out a way to tell my model to maximize profit subject to a few constraints by changing only a select subset of variables. What would be the best function for doing that?

I've tried searching online for an answer but it's not immediately clear what function would allow me to specify constraints as well as the specific variables I want the optimizer to change in order to optimize. I've attached my model just in case - apologies in advance for the way it's constructed....it's my first one! ha

Thanks, Scott

Attachments:
POSTED BY: Scott T
6 Replies
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