Skip to content

Instantly share code, notes, and snippets.

@alfateam123 alfateam123/data.dzn
Created Jan 25, 2019

Embed
What would you like to do?
Emptying cashless keys with MiniZinc
START_AMOUNT = 260; % 2.60 euro
BEVERAGES = { coffee, tea, ginseng, chocolate };
COST = [ 25, 40, 35, 30 ];
% the initial amount in our cashless key
int: START_AMOUNT;
% the list of beverages (coffee, tea, chocolate, ...)
enum BEVERAGES;
% how much does a beverage cost?
array[BEVERAGES] of int: COST;
/* how many times do I have to drink a beverage B? */
array[BEVERAGES] of var int: quantity;
/* constraint: cannot drink a negative amount of drinks! */
constraint forall(b in BEVERAGES)(quantity[b] >= 0);
/* constraint: we must spend exactly START_AMOUNT */
var int: spent = sum(b in BEVERAGES)(quantity[b] * COST[b]);
constraint START_AMOUNT - spent = 0;
/* the objective function! */
var int: how_many_drinks;
constraint how_many_drinks = sum(b in BEVERAGES)(quantity[b]);
% use `maximize` to drink as many coffees as possible
% use `minimize` to cut down on coffees and get to zero euro as fast as possible
solve maximize how_many_drinks;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.