-1

I would like to ask you regarding on the Linear program for optimization.

I have an objective function, and constraint functions as below,

Variables (x1, x2, x3, x4, x5, and x6) are quantities of the products, and the quantities of products have to be fixed numbers now. The goal of this problem is the optimizing the quantities of products.

  1. Objective Function (c.T * [x1, x2, x3, x4, x5, x6])

    [[c11, c12, c13, c14, c15 c16],
    [c21, c22, c23, c24, c25, c26],
                                          X     [x1, x2, x3, x4, x5, x6]
    [c31, c32, c33, c34, c35, c36],
    [c41, c42, c43, c44, c45, c45]]
    

    The result that I would like to optimize is going to be as below:

    c11*x1 + c12*x2 + c13*x3 + c14*x4 + c15*x5 + c16*x6 +
    c21*x1 + c22*x2 + c23*x3 + c24*x4 + c25*x5 + c26*x6 +
    c31*x1 + c32*x2 + c33*x3 + c34*x4 + c35*x5 + c36*x6 +
    c41*x1 + c42*x2 + c43*x3 + c44*x4 + c45*x5 + c46*x6 = optimized value
    
  2. Constraint Function

    • constraint_1

      5500000*x1+2500000*x2+825000*x3+5500000*x4+5500000*x5+5500000*x6 <= 800000000
      
    • constraint_2

      x1 <= 10
      x2 <= 10
      x3 <= 10
      x4 <= 10
      x5 <= 10
      x6 <= 10
      

The problem that I am suffering from is the in the "Objective Function of Cs(c1,1 ~ c4,5)".

If the object function is like 3 * x1 + 2 * x2 + 3 * x3 + 4 * x4 + 5 * x5 + 6 * x6, then it will be easier and solved with below code:

c = np.array([3, 2, 3, 4, 5, 6])
A = np.array([[5500000, 2500000, 825000, 5500000, 5500000, 5500000], [1,0,0,0,0,0], [0,1,0,0,0,0], [0,0,1,0,0,0], [0,0,0,1,0,0], [0,0,0,0,1,0], [0,0,0,0,0,1]])
b = np.array([800000000, 10, 10, 10, 10, 10, 10])
c = matrix(c, tc='d')
G = matrix(A, tc='d')
h = matrix(b, tc='d')
status, x = glpk.ilp(c, g, h, I=set([0,1,2,3,4,5]))

Please kindly help to solve the Linear programming problem.

martineau
  • 119,623
  • 25
  • 170
  • 301
Jay Kim
  • 7
  • 1

1 Answers1

0

The below will only work if you install pulp. It's a LP solving library that I use frequently. If you do NOT define c11 through c45 as integers or floats, the below likely will not work. You would need to initialize the c values as LP variables, too.

from pulp import *

# Let's program know that you want to maximize subject to constraints
prob = LpProblem("LP problem", LpMaximize)

# initialize variables
x1=LpVariable("x1",lowBound=0)
x2=LpVariable("x2",lowBound=0)
x3=LpVariable("x3",lowBound=0)
x4=LpVariable("x4",lowBound=0)
x5=LpVariable("x5",lowBound=0)
x6=LpVariable("x6",lowBound=0)

# objective function must be "added" to prob BEFORE constraints.
prob += c11*x1 + c12*x2 + c13*x3 + c14*x4 + c15*x5 + c16*x6 + c21*x1 + c22*x2 + 
c23*x3 + c24*x4 + c25*x5 + c26*x6 + c31*x1 + c32*x2 + c33*x3 + c34*x4 + c35*x5+ 
c36*x6 + c41*x1 + c42*x2 + c43*x3 + c44*x4 + c45*x5 + c46*x6

# constraints
prob += 5500000*x1+2500000*x2+825000*x3+5500000*x4+5500000*x5+5500000*x6 <= 
800000000
prob += x1 <= 10
prob += x2 <= 10
prob += x3 <= 10
prob += x4 <= 10
prob += x5 <= 10
prob += x6 <= 10

Now run the below:

status = prob.solve()
LpStatus[status]

Lastly run the following:

value(x1), value(x2), value(x3), value(x4), value(x5), value(x6) 
value(prob.objective)

Let me know if you run into any issues, with a comment.