0

Am just getting started with Minizinc and would appreciate if I get some ideas in building a model for my problem.

I have three items. On purchase of each item I get certain cashback bonus and there is a limit in number of times an item can be purchased. Also I have a capacity in my cart.

Example :

items = [ 'i1', 'i2', 'i3' ]
cart_capacity = 7

cashback = [30,10,20] 
(meaning, with purchase of item1 I get back $30)

Frequency_of_purchase = [ 2 , 1 , 5]
(meaning, item 3 can be purchased 5 times)

I need an output saying how many times each item can be purchased so that I get maximum cashback

Desired result = { i1 : 2, i2: 0, i3 : 5}

1 Answer 1

3

Generally we would say the string input mainly as the labels of the different items.

In MiniZinc the best approach is to use an enumerated type. An enumerated type can be used both as the index for an array or as the possible values of an variable.

Your model could be expressed as:

/* --- Problem Parameters --- */
enum ITEMS;
int: cart_capacity;
array[ITEMS] of int: cash_back;
array[ITEMS] of int: item_capacity;

/* --- Decision Variables --- */
array[ITEMS] of var 0..ub_array(item_capacity): purchases;

/* --- Constraints --- */
constraint forall(it in ITEMS) (purchases[it] < item_capacity[it]);
constraint sum(it in ITEMS) (purchases[it]) < cart_capacity;

/* --- Solving Goal --- */
solve maximize sum(it in ITEMS) (purchases[it]*cash_back[it]);

output ["{"] ++ [show(it) ++ ": " ++ show(purchases[it]) ++ if it == max(ITEMS) then "" else ", " endif | it in ITEMS] ++ ["}"];

The input in your question has to be slightly adjusted to:

ITEMS = { 'i1', 'i2', 'i3' };
cart_capacity = 7;
cashback = [30, 10, 20];
item_capacity = [2 , 1 , 5];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.