I have done a program which works fine when using "glpk" solver and I am able to get the expected results, hence I am confident that the program works. Following is the code.
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('=========================')
However, when I tried using gurobi solver by altering the code as shown below, I am not able to get any results.
opt = SolverFactory("gurobi", solver_io="python")
or
opt = SolverFactory("gurobi")
The error:
Traceback (most recent call last):
File "D:/Python learning/ProjektX/chicken wings.py", line 26, in <module>
opt_success = opt.solve(model)
File "D:\EngineeringSoftware\Anaconda\lib\site-packages\pyomo\solvers\plugins\solvers\direct_solver.py", line 68, in solve
self.available(exception_flag=True)
File "D:\EngineeringSoftware\Anaconda\lib\site-packages\pyomo\solvers\plugins\solvers\direct_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
or
WARNING: Could not locate the 'gurobi' executable, which is required for
solver gurobi
For Installation of gurobi, I have followed the gurobi installation procedure using anaconda
conda config --add channels http://conda.anaconda.org/gurobi
conda install gurobi
I have created a environment variable under the name GRB_LICENSE_FILE and directed the variable value to the location of the .lic file.
I have exhausted all option that I can find from the internet, hence I am requesting help from the pyomo community here to enlighten me on this issue.
Regarding that you try to use the Python interface for Gurobi with this line:
opt = SolverFactory("gurobi", solver_io="python")
You might get the
Traceback (most recent call last): File "D:/Python learning/ProjektX/chicken wings.py", line 26, in <module> opt_success = opt.solve(model) File "D:\EngineeringSoftware\Anaconda\lib\site-packages\pyomo\solvers\plugins\solvers\direct_solver.py", line 68, in solve self.available(exception_flag=True) File "D:\EngineeringSoftware\Anaconda\lib\site-packages\pyomo\solvers\plugins\solvers\direct_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
error. One reason that can lead to this kind of error is that your Gurobi's Python binding has to be installed. This binding comes with your Gurobi installation, but is not installed by default. Provided that you already have a valide Gurobi license, I suggest you to visit
http://www.gurobi.com/documentation/8.1/quickstart_mac/the_gurobi_python_interfac.html
To summarize the support page,
python setup.py install
to run the installation of the Python binding. You can check if it is installed by entering the line import gurobipy
in your Python console.