Skip to content

Instantly share code, notes, and snippets.

@tokoro10g
Last active June 17, 2019 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokoro10g/488c5152aa0c6491721d4f3b8f254967 to your computer and use it in GitHub Desktop.
Save tokoro10g/488c5152aa0c6491721d4f3b8f254967 to your computer and use it in GitHub Desktop.
サイゼリヤ1000円以内でカロリー最大化 MATLABバージョン
clear
load saizeriyadb.mat
maxtotalprice = 1000;
selection = optimvar('selection', saizeriyadb.name, 'Type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
problem = optimproblem('ObjectiveSense', 'maximize', 'Objective', dot(selection, saizeriyadb.calorie));
problem.Constraints.constr = dot(selection, saizeriyadb.price) / maxtotalprice <= 1;
tic
[soln, fval, exitflag, output] = solve(problem);
toc
selectedmenu = saizeriyadb(logical(soln.selection), :)
totalprice = sum(selectedmenu.price)
totalcalorie = sum(selectedmenu.calorie)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment