Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from pyomo.environ import *
- import numpy as np
- rawfile = "C:/Users/User/Downloads/chickenwings2.csv"
- df_raw = pd.read_csv(rawfile, index_col='Name')
- print (df_raw)
- Set = df_raw.index.tolist()
- count = dict(zip(df_raw.index,df_raw['count']))
- price = dict(zip(df_raw.index,df_raw['price']))
- #print (count,price)
- model = ConcreteModel()
- model.x = Var(Set, within=NonNegativeIntegers)
- model.obj = Objective(expr= sum(price[i]*model.x[i] for i in Set), sense=minimize)
- model.count_con = Constraint(expr=sum(count[i]*model.x[i] for i in Set) == 200)
- opt = SolverFactory("glpk")
- opt_success = opt.solve(model)
- total_count = sum(count[i]*value(model.x[i]) for i in Set)
- print('Total Count:', total_count)
- print('Total Price:', value(model.obj))
- print('%5s %5s %12s' % ('Set','Count', 'Order Count'))
- print('=========================')
- for i in Set:
- if value(model.x[i]>0):
- print ('%5s %5s %5s' % (i,count[i], value(model.x[i])))
- print('=========================')
- opt = SolverFactory("gurobi", solver_io="python")
- opt = SolverFactory("gurobi")
- Traceback (most recent call last):
- File "D:/Python learning/ProjektX/chicken wings.py", line 26, in <module>
- opt_success = opt.solve(model)
- File "D:EngineeringSoftwareAnacondalibsite-packagespyomosolverspluginssolversdirect_solver.py", line 68, in solve
- self.available(exception_flag=True)
- File "D:EngineeringSoftwareAnacondalibsite-packagespyomosolverspluginssolversdirect_or_persistent_solver.py", line 301, in available
- "plugin").format(type(self)))
- pyutilib.common._exceptions.ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin
- WARNING: Could not locate the 'gurobi' executable, which is required for
- solver gurobi
- conda config --add channels http://conda.anaconda.org/gurobi
- conda install gurobi
Add Comment
Please, Sign In to add comment