'Minizinc piecewise linear function

I have a cost minimization problem.In the problem we have 3 suppliers. They are S1,S2 & S3, where cost is calculated as price x Qty purchased.

Price value for 3 suppliers as follows.

price=[10,15,20]

If I have a decision variable as array[1..3] of var int:purchase where I am going to get the answers from optimization problem from which supplier how many units I need to purchase.

Sample code as follows.

enum suppliers={s1,s2,s3};
int: len_sup=length(suppliers);
set of int:range_sup=1..len_sup;

array[range_sup] of int:price=[10,15,20];
int:demand=40;

array[range_sup] of int:moq=[5,0,5];
array[range_sup] of int:maxoq=[8,20,30];

array[range_sup] of var 0..100:purchase;

constraint sum(i in range_sup)(
purchase[i])=demand
;

constraint forall(i in range_sup)(
purchase[i]>=moq[i] \/ purchase[i]=0
);

constraint forall(i in range_sup)(
purchase[i] <= maxoq[i]
);

var int:cost;

constraint sum(i in range_sup)(
purchase[i]*price[i])=cost;

solve minimize cost;

Now I have a new requirement to embed price discounts for this.This price discount will definitely vary from the qty we purchase.

for this example imagine it is known that from any supplier if we purchase Qty of 1 to 5 then we would get 5% discount (price would decrease from 5%) on the price. If we purchase 6 to 10 we get 10% price discount. If we purchase more than 11 we get 15% price discount.

How do you incorporate this thing to model.Is this using by piecewise linear functions (because it seems like problem becoming non linear)? Can someone show how could this using piecewise linear function?



Solution 1:[1]

assuming you have a model that contains the 'email', 'user_master', 'id', then beneath the model (but within its tab) you can try something like the following (the @property decorator enables one to use the function as though its a part of the model)

@property
def myEmailerId(self):
    queryset = self.email.all().values_list('user_master__id', flat=True)
    return queryset

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JVDB