Re: [AMPL 24332] Sum based on the value of index

14 views
Skip to first unread message

AMPL Google Group

unread,
Nov 19, 2022, 2:44:56 PM11/19/22
to AMPL Modeling Language
You should write Product[i] rather than Product[SKU]:

set SKU;
param Product {SKU} symbolic;
var y {SKU} binary;

s.t. mid: sum {i in SKU: Product[i]= "A"} y[i] = 1;

With the data that you gave, this constraint comes out as intended:

ampl: expand mid:
subject to mid:
	y[1] + y[3] + y[6] = 1;


--
Robert Fourer
am...@googlegroups.com
{#HS:2072494010-112875#}
On Fri, Nov 18, 2022 at 11:24 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello,
I have a data set like given below

Screenshot 2022-11-18 180756.png

I need to write constraints based on the products. For e.g., only one of the product A is selected. I have a binary variable which is 1 if the product i is selected and zero otherwise. I have the following so far.

reset;
load amplxl.dll;
model EP.mod;
table Data IN "amplxl" "DataEdited.xlsx":
SKU <- [SKU], Product, Price;
read table Data;

I tried this and got syntax error.

set SKU;
s.t. mid: sum{ i in SKU : Product[SKU]= "A"} y[i] = 1;

I am trying to write the constraint y_1+y_3+y_6 = 1.

Any help is really appreciated. Thanks

Reply all
Reply to author
Forward
0 new messages