How to model relationships between variables in a set?

Problems with modeling
Post Reply
Posts: 1
Joined: 2 months ago

How to model relationships between variables in a set?

Post by deliora » 2 months ago

beginner here. I'm working on a model and i'm stuck on this part.
I have a set of items that are connected to each other. Each item either enhances the other items in the set or detracts from them.
So i created a table and gave a value to the interaction between the items and it looks something like this:

item1 item2 item3 item4
item1 1 3 2 -2
item2 3 1 -1 1
item3 2 -1 1 2
item4 -2 1 2 1

the model will choose a selection of the items based on some other constraints. What i would like to do is get the sum of the all the interactions of the items the model will choose and also get the number of items that were chosen. For example the model chose item1 item3 and item 4, the sum based on the table above would be ((3)+(-2))+((2)+(2))+((-2)+(2)) without choosing the interaction of the item with itself. And then the model would assign a value of 3 for the item number chosen because 3 items with chosen based on the other constraints (item1. item3, and item4)

if anyone would be kind enough to help i would greatly appreciate it.

Posts: 190
Joined: 10 months ago

Re: How to model relationships between variables in a set?

Post by abhosekar » 2 months ago

It is not clear to me whether you want to do it after solve or as a part of your constraint.

After solve, this is very easy. I assume you have a binary variable representing the selections.

let's say you have the following

Code: Select all

set items /item1*item4/;
alias(items, it);
table weights(items, items);

binary variable y(items);

... (solve statements and constraints etc.)

parameter p;

p = sum((items, it) $(y.l(items) and ord(items) ne ord(it) and y.l(it)), weights(items, it));

display p;
Hope this helps.

- Atharv

Post Reply