Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (40 sloc) 1.37 KB
import json
import interview_grocery_startup as igs
def get_json_response(cfg, what):
results = igs.main(cfg, what)
solver = results['solver']
if results['result_status'] == solver.OPTIMAL:
response = {'result_status': 'optimal answer'}
variable_list = results['variable_list']
print solver.wall_time()
print solver.Objective().Value()
response['wall_time'] = solver.wall_time()
response['objective_value']= solver.Objective().Value()
response['variables'] = dict()
for variable in variable_list:
response['variables'][]= variable.solution_value()
elif results['result_status'] == solver.INFEASIBLE:
response = {'result_status': 'infeasible'}
elif results['result_status'] == solver.POSSIBLE_OVERFLOW:
response = {'result_status': 'overflow'}
json_response = json.dumps(response, sort_keys=True)
return json_response
def main(cfg, what):
json_response = get_json_response(cfg, what)
return json_response
if __name__ == '__main__':
cfg = {'maxWeight': 10,
'maxCost': 100,
'minCals': 14000,
'minShop': 4/16.0, #16 ounces per pound
'food': [['ham',650, 4],
main(cfg, 'cost')
You can’t perform that action at this time.