"""
The Simplified Whiskas Model Python Formulation for the PuLP Modeller

Authors: Antony Phillips, Dr Stuart Mitchell  2007

Adapted to show features of the MOSEK interface.
"""

# Import PuLP modeler functions
from pulp import *
import mosek

# Create the 'prob' variable to contain the problem data
prob = LpProblem("TheWhiskasProblem",LpMinimize)

# The 2 variables Beef and Chicken are created with a lower limit of zero
x1=LpVariable("ChickenPercent",0,None,LpInteger)
x2=LpVariable("BeefPercent",0)

# The objective function is added to 'prob' first
prob += 0.013*x1 + 0.008*x2, "Total Cost of Ingredients per can"

# The five constraints are entered
prob += x1 + x2 == 100, "PercentagesSum"
prob += 0.100*x1 + 0.200*x2 >= 8.0, "ProteinRequirement"
prob += 0.080*x1 + 0.100*x2 >= 6.0, "FatRequirement"
prob += 0.001*x1 + 0.005*x2 <= 2.0, "FibreRequirement"
prob += 0.002*x1 + 0.005*x2 <= 0.4, "SaltRequirement"

# Solve the lp using MOSEK and write an opf task file.
# msg - activate MOSEK log output (optional)
# options - a dictionary with MOSEK parameters (optional)
# task_file_name - name of the file where to save the data (optional)
prob.solve(solver=MOSEK(mip = False,
                        msg = True,
                        options = {mosek.dparam.optimizer_max_time:  100.0, 
                                   mosek.iparam.optimizer:           mosek.optimizertype.dual_simplex},
                        task_file_name = 'dump.task.gz'))

# The status of the solution is printed to the screen
print("Status:", LpStatus[prob.status])

# Each of the variables is printed with it's resolved optimum value
for v in prob.variables():
    print(v.name, "=", v.varValue)
    
# The optimised objective function value is printed to the screen
print("Total Cost of Ingredients per can = ", value(prob.objective))
