1
$\begingroup$

I am trying to build an optimization model using PYOMO for the daily production of a product demand, minimizing the production cost.

I have demand, production capacity (by machine by day), production cost (by machine by day) and delivery cost to produce the products. Some machines have different costs and production capacities to produce the same product.

My problem is that I am getting very low production numbers (like 3.981296e-08 ) and I'm not be able to know where this numbers are getting from.

I suppose they are about OF, but I can't see a way to implement them differently. Below the code - Any suggestions are welcome.

### SOURCES:
import pandas as pd
from pyomo.environ import *

capacidade = {
    'MC05': {'PRODUCT_A': 371, 'PRODUCT_B': 371, 'PRODUCT_C': 427},
    'MC06': {'PRODUCT_A': 396, 'PRODUCT_B': 396, 'PRODUCT_C': 435},
    'MC07': {'PRODUCT_A': 547, 'PRODUCT_B': 571, 'PRODUCT_C': 1},
    'MC08': {'PRODUCT_A': 476, 'PRODUCT_B': 497, 'PRODUCT_C': 1},
    'MC09': {'PRODUCT_A': 657, 'PRODUCT_B': 692, 'PRODUCT_C': 790}
    }
df_capacidade = pd.DataFrame(capacidade)

custo = {
     'MC05': {'PRODUCT_A': 1368, 'PRODUCT_B': 1368, 'PRODUCT_C': 1368},
     'MC06': {'PRODUCT_A': 1435, 'PRODUCT_B': 1435, 'PRODUCT_C': 1427},
     'MC07': {'PRODUCT_A': 1189, 'PRODUCT_B': 1207, 'PRODUCT_C': 100000},
     'MC08': {'PRODUCT_A': 1221, 'PRODUCT_B': 1209, 'PRODUCT_C': 100000},
     'MC09': {'PRODUCT_A': 1905, 'PRODUCT_B': 1907, 'PRODUCT_C': 1965}
     } 
df_custo = pd.DataFrame(custo)
dmd =  {
 'Argentina'        : {'PRODUCT_A':       899.58 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Paraguay'         : {'PRODUCT_A':      253.067 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Uruguay'          : {'PRODUCT_A':       94.472 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':   1.123 },
 'Peru'             : {'PRODUCT_A':      1370.06 ,   'PRODUCT_B':   614.97 ,     'PRODUCT_C':       0 },
 'Caribe'           : {'PRODUCT_A':        50.64 ,   'PRODUCT_B':   73.078 ,     'PRODUCT_C':       0 },
 'AmericaCentral'   : {'PRODUCT_A':     1936.941 ,   'PRODUCT_B':  108.893 ,     'PRODUCT_C':       0 },
 'Colombia'         : {'PRODUCT_A':       72.814 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Chile'            : {'PRODUCT_A':     3013.913 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Bolivia'          : {'PRODUCT_A':        1.266 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Equador'          : {'PRODUCT_A':        471.6 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Mexico-Intc'      : {'PRODUCT_A':      394.758 ,   'PRODUCT_B':        0 ,     'PRODUCT_C':       0 },
 'Europa'           : {'PRODUCT_A':     2774.484 ,   'PRODUCT_B': 1843.355 ,     'PRODUCT_C':       0 },
 'Brasil'           : {'PRODUCT_A':    14868.788 ,   'PRODUCT_B':        0 ,     'PRODUCT_C': 118.354 },
 'Mea'              : {'PRODUCT_A':     1020.808 ,   'PRODUCT_B':  1989.25 ,     'PRODUCT_C':       0 },
 'Others'           : {'PRODUCT_A':           0  ,   'PRODUCT_B':   21.457 ,     'PRODUCT_C':       0 },
                                                       
}
df_demanda = pd.DataFrame(dmd)

frete =  {
 'Argentina' : {'MC05': 12214.3739456068, 'MC06': 12214.3739456068, 'MC07': 12987.9489324915, 'MC08': 12987.9489324915, 'MC09': 14063.2725317568},
 'Paraguay' : {'MC05': 8415.8538992,  'MC06': 8415.8538992,  'MC07': 8750.83648755556, 'MC08': 8750.83648755556, 'MC09': 9465.15779},
 'Uruguay'  : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Peru'     : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Caribe'    : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'AmericaCentral'   : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Colombia' : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Chile'    : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Bolivia'  : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Equador' : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Mexico-Intc' : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Europa' : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Brasil' : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Mea'  : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025},
 'Others' : {'MC05': 2851.8259,    'MC06': 2851.8259,  'MC07': 4067.61025,  'MC08': 4067.61025,  'MC09': 7449.23025}
    
}
df_frete = pd.DataFrame(frete)


model = ConcreteModel()
model.i = df_custo.keys()    ## i=Machines
model.j = df_demanda.index   ## j=Products
model.h = df_demanda.keys()  ## h=Customers

container = 25


model.x = Var(model.i, model.j,model.h, within=NonNegativeReals)                  ### Quantity 
model.y = Var(model.i, model.j,model.h, bounds=(1,31), within=NonNegativeReals)   ### Days

model.OF = Var(within=Reals)                  ### Total production Cost
model.P = Var(model.i,within=Reals)           ### Production by Machine

def rule_C1(model, i):
    return sum(model.x[i,j,h] for j in model.j for h in model.h) == model.P[i]
model.C1 = Constraint(model.i, rule=rule_C1)


model.cons = ConstraintList()
for j in model.j:
    for h in model.h:
        model.cons.add(sum(model.x[i,j,h] for i in model.i) == (df_demanda.loc[j,h] ) )

model.cons2 = ConstraintList()
for i in model.i:
    for j in model.j:
        for h in model.h:
            model.cons2.add( model.x[i,j,h] <= capacidade[i][j] * model.y[i,j,h])

def rule_OF(model): ##>>>>>       #Cost by Unit                 #Production        #Days                 #delivery by container 
    return model.OF == sum( ( custo[i][j]/capacidade[i][j] ) * (model.x[i,j,h]  * model.y[i,j,h])  + (model.x[i,j,h] / container) * df_frete.loc[i,h]  for i in model.i for j in model.j for h in model.h) 
model.C3 = Constraint(rule=rule_OF)
model.obj1 = Objective(expr=model.OF, sense=minimize)


solver = SolverFactory('ipopt')
results = solver.solve(model, tee=True)

results.solver.termination_condition

print("OF= ", value(model.OF))


df = pd.DataFrame(columns=('Machines','Products', 'Clients', 'Production', 'Days',"MachineCost", "MachineCapacity") )
for i in model.i:
  for j in model.j:
    for h in model.h:
      v1 = value(model.x[i,j,h])
      v2 = value(model.y[i,j,h])
      v3 = custo[i][j]
      v4 = capacidade[i][j]
      #print (i, j, h, v1, v2, v3,v4)
      df = df.append(pd.DataFrame({"Machines":[i], "Products":[j], "Clients":[h], "Production":[v1], "Days":[v2], "MachineCost": v3, "MachineCapacity": v4})) 

df
$\endgroup$
3
  • 2
    $\begingroup$ Welcome to OR.SE. I cannot see where you have stacked. Can you edit your question and add some details? Your model currently is an "Infeasible or unbounded model". $\endgroup$ – Oguz Toragay Feb 24 at 8:13
  • 1
    $\begingroup$ @PAULO CRISTIANO KLEIN, It would be helpful if, you could share the mathematical model. $\endgroup$ – A.Omidi Feb 24 at 13:27
  • $\begingroup$ I found a partial solution. I update the question with the new code. $\endgroup$ – PAULO CRISTIANO KLEIN Feb 26 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.