result not correct
Answeredhello when I change my database a,l,S1 and S2 get it from excel some thing happen
my excel database a and l are like this table
and S1 , S2 are like this table
import gurobipy as gp
import pandas as pd
import numpy as np
from gurobipy import GRB
#Read Purchase Order from Excel
df=pd.read_excel("purchase order.xlsx")
products=df.Article.values.tolist()
print(products)
m=df.drop(columns='Article',axis=1)
#print(m)
a=m.values.tolist()
print (a)
#a=[[0,0,10,0,0],[0,20,0,0,0],]
#Read Consommation from Excel
df=pd.read_excel("Consommation.xlsx")
b=df.drop(columns='Article',axis=1)
l=b.values.tolist()
print(l)
#l=[[0,2,3,1,2],[0,9,5,1,2],]
#Read initial Local stock from Excel
df=pd.read_excel("initial stock.xlsx")
b=df.drop(columns='Article',axis=1)
S1=b.values.tolist()
print(S1)
#S1[1,0].lb=1
#S1[1,0].ub=1
#S1[2,0].lb=2
#S1[2,0].ub=2
#Read initial Logis stock from Excel
df=pd.read_excel("S2.xlsx")
b=df.drop(columns='Article',axis=1)
S2=b.values.tolist()
print(S2)
#S2[1,0].lb=3
#S2[1,0].ub=3
#S2[2,0].lb=4
#S2[2,0].ub=4
m=gp.Model("Log")
weeks = [0,1,2,3,4]
#products=[1,2]
L=10
k=2
S=m.addVars(products,weeks,name='S')
S1=m.addVars(products,weeks,name='S1')
S2=m.addVars(products,weeks,obj=k,name='S2')
l1=m.addVars(products,weeks,name='l1')
l2=m.addVars(products,weeks,obj=k,name='l2')
l3=m.addVars(products,weeks,obj=k,name='l3')
a1=m.addVars(products,weeks,name='a1')
a2=m.addVars(products,weeks,obj=k,name='a2')
m.addConstrs(S[p,t-1]+a[p-1][t] == l[p-1][t]+S[p,t] for p in products for t in weeks if t>0)
m.addConstrs(S1[p,t-1]+a1[p,t] == l1[p,t]+S1[p,t]-l3[p,t] for p in products for t in weeks if t>0)
m.addConstrs(S2[p,t-1]+a2[p,t] == l2[p,t]+S2[p,t]+l3[p,t] for p in products for t in weeks if t>0)
m.addConstrs((S[p,t] == S1[p,t]+S2[p,t] for p in products for t in weeks ))
m.addConstrs((a[p-1][t] == a1[p,t]+a2[p,t] for p in products for t in weeks ))
m.addConstrs((l[p-1][t] == l1[p,t]+l2[p,t] for p in products for t in weeks ))
m.addConstrs(gp.quicksum(S1[p,t] for p in products) <= L for t in weeks)
m.addConstrs(gp.quicksum(S[p,t] for p in products) <= L + gp.quicksum(S2[p,t] for p in products) for t in weeks)
m.optimize()
m.write("myLP.lp")
print(m)
print(S)
0
-
Dear Ghada,
what kind of "thing" are you experiencing? Are the results not what you expected them to be?
It would be helpful to also describe what kind of model you are solving and what is the desired behaviour of your code.
Looking from afar, there is at least one issue I found with your code:
You first store some weekly values in your dict C1:
S1=b.values.tolist()
but then you overwrite it with a tupledict containing variables:
S1=m.addVars(products,weeks,name='S1')
The same holds for S2. Is that the intended behaviour?
Best regards
Jonasz0 -
This is a duplicate of result not correct.
0
Please sign in to leave a comment.
Comments
2 comments