Percentage constraint for Integer programming model

589 Views Asked by At

Th question is as follows:

There are 10 items that need to assigned to 2 categories, A and B. Each item has a weight and 30 % of the weight is allocated to A and the remaining 70% to B.The objective is t minimize the difference between the items assigned to A and B. I am not sure how to write the percentage constraint in Xpress-Ive (Mosel lang)

What i've tried:

Manually calculated the percentages and stated them. Then, calculated the sum of items in each category and set it equal to the percentage. A and B are set to be binary. This is my code for the constraint:

Item = 1..10
W_a=43.8 !0.3 of sum of Weight
W_b=102.2 !0.7 of sum of Weight
Weight: array(Item) OF REAL
A,B: array(Item) OF MPVAR 
END-DECLARATIONS
Weight :: [12,7,16,10,11,23,21,13,19,14]
SUM(i in Item)Weight(i)*A(i) = W_a
SUM(i in Item)Weight(i)*B(i) = W_b

This gives me zero as the solution with none of the items assigned to A or B. Could i get a hint on what i've done wrong?