Search code examples
pyomo

Use case for "sets of tuple data" in Pyomo


When we specify the data for a set we have the ability to give it tuples of data. For example, we could write in our .dat file the following:

 set A : 1  2  3  :=
     1   +  -  -  
     2   -  -  + 
     3   -  +  +

This would specify that we would have 4 tuples in our set: (1,1), (2,3), (3,2), (3,3)

But I guess that I am struggling to understand exactly why we would want to do this? Furthermore, suppose we instantiated a Set object in our code as:

model.Aset = RangeSet(4, dimen=2)

Would this then specify that our tuples would have the indices 1, 2, 3, and 4?

I am thinking that specifying tuples in our set could potentially be useful when working with some data in which it's important to have a bit of a "spatial" understanding of the problem. But I would be curious to hear from the community what the potential applications of specifying set data this way might be.


Solution

  • The most common place this appears is when you're trying to model edges between nodes in a network. Networks aren't usually completely dense (have edges between every pair of nodes) so it's beneficial to represent just the edges that appear using a sparse set of tuples.