# Homework Problem – Help Formulating Constraints [closed]

I am working on the following assignment problem:

You may produce seven products by consuming three materials. The unit sales price and material consumption of each product are listed in Table 1. For each day, the supply of these three materials are limited. The supply limits are listed in Table 2. For each day, you need to determine the production quantity for each product. Formulate a linear integer program that generates a feasible production plan to maximize the total profit (which is also the total revenue, as there is no cost in this problem).

How I formulated the problem using Mathematica:

(The first line is the objective function, the following lines are the constraints, and the last line specifies the decision variables... Sorry if this is explanatory to the point of condescending... Just want to clarify if anyone's not familiar with Mathematica's syntax.)

I am getting the following error message:

I am guessing I am making a very elementary mistake in how I am formulating my constraints.

• Welcome to OR.SE. I have closed this question as it seems to be about the syntax of Mathematica. To answer your question, Mathematica needs all variables in the constraints on one side of the equality. So Maximize[{100x1+120x2+135x3+90x4+125x5+110x6+105x7,3m2+10m3-x1==0&&5m1+10m2+10m3-x2==0&&5m1+3m2+9m3-x3==0&&4m1+6m2+3m3-x4==0&&8m1+2m2+8m3-x5==0&&5m1+2m2+10m3-x6==0&&3m1+2m2+7m3-x7==0&&0<=m1<=100&&0<=m2<=150&&0<=m3<=200&&x1>=0&&x2>=0&&x3>=0},{x1,x2,x3,x4,x5,x6,x7,m1,m2,m3}] works and gives {2122750,{x1->2450,x2->4000,x3->2750,x4->1900,x5->2700,x6->2800,x7->2000,m1->100,m2->150,m3->200}}. Commented Dec 14, 2022 at 22:17
• @TheSimpliFire The constraints are not correct. See issue #7 in my answer. The correct optimal objective value turns out to be 3365. Commented Dec 14, 2022 at 22:33
• @RobPratt Agreed, thanks. I was trying to resolve the software error instead of trying to correct the formulation. Commented Dec 14, 2022 at 22:38

Seven issues:

1. Product 3, material 2 coefficient should be 3 instead of 10.

2. Lower bound of m3 should be $$0 \le$$ instead of $$0<$$.

3. Use double equals == for equality constraints.

4. Use && instead of commas to delimit constraints:

Maximize[{f, con1 && con2 && ...}, {x1, x2, ...}]

5. List all variables (both x and m) in the second argument.

6. You have not specified that the variables must take integer values.

7. Your constraints should instead be of the form $$m_i = \sum_j a_{i,j} x_j$$. If you prefer, omit the $$m_i$$ variables and just impose $$\sum_j a_{i,j} x_j \le b_i$$.

• Hello Rob, thanks for answer, however, I'm still getting the following error message: "Maximize: 3 m2+10 m3 is not a valid variable." Just like the one shown above. I have tripled checked it and I made all changes as you suggested.
– SDH
Commented Dec 14, 2022 at 19:14
• Picture of code can be found here: imgur.com/a/4gWwNtS
– SDH
Commented Dec 14, 2022 at 19:22
• I don't know mathematica, but maybe it needs an * between the coefficient and the variables?
– Sune
Commented Dec 14, 2022 at 19:22
• I added one more issue to my answer. Commented Dec 14, 2022 at 19:33
• Hey Rob, added the &&'s. Still got the error message. Mathematica syntax aside, does my constraint formulation look correct mathematically?
– SDH
Commented Dec 14, 2022 at 20:15