Guest User

Untitled

a guest
Jan 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import pandas as pd
  2. from pyomo.environ import *
  3. import numpy as np
  4.  
  5.  
  6. rawfile = "C:/Users/User/Downloads/chickenwings2.csv"
  7.  
  8. df_raw = pd.read_csv(rawfile, index_col='Name')
  9. print (df_raw)
  10.  
  11. Set = df_raw.index.tolist()
  12. count = dict(zip(df_raw.index,df_raw['count']))
  13. price = dict(zip(df_raw.index,df_raw['price']))
  14.  
  15. #print (count,price)
  16.  
  17. model = ConcreteModel()
  18. model.x = Var(Set, within=NonNegativeIntegers)
  19.  
  20. model.obj = Objective(expr= sum(price[i]*model.x[i] for i in Set), sense=minimize)
  21.  
  22. model.count_con = Constraint(expr=sum(count[i]*model.x[i] for i in Set) == 200)
  23.  
  24. opt = SolverFactory("glpk")
  25. opt_success = opt.solve(model)
  26.  
  27. total_count = sum(count[i]*value(model.x[i]) for i in Set)
  28. print('Total Count:', total_count)
  29. print('Total Price:', value(model.obj))
  30.  
  31. print('%5s %5s %12s' % ('Set','Count', 'Order Count'))
  32. print('=========================')
  33.  
  34. for i in Set:
  35. if value(model.x[i]>0):
  36. print ('%5s %5s %5s' % (i,count[i], value(model.x[i])))
  37.  
  38. print('=========================')
  39.  
  40. opt = SolverFactory("gurobi", solver_io="python")
  41.  
  42. opt = SolverFactory("gurobi")
  43.  
  44. Traceback (most recent call last):
  45. File "D:/Python learning/ProjektX/chicken wings.py", line 26, in <module>
  46. opt_success = opt.solve(model)
  47. File "D:EngineeringSoftwareAnacondalibsite-packagespyomosolverspluginssolversdirect_solver.py", line 68, in solve
  48. self.available(exception_flag=True)
  49. File "D:EngineeringSoftwareAnacondalibsite-packagespyomosolverspluginssolversdirect_or_persistent_solver.py", line 301, in available
  50. "plugin").format(type(self)))
  51. pyutilib.common._exceptions.ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin
  52.  
  53. WARNING: Could not locate the 'gurobi' executable, which is required for
  54. solver gurobi
  55.  
  56. conda config --add channels http://conda.anaconda.org/gurobi
  57. conda install gurobi
Add Comment
Please, Sign In to add comment