6

I'm working on an optimization problem regarding a directed acyclic graph. The constraint looks in pyomo like this:

model.K = RangeSet(0,n_edges)
model.con_part=ConstraintList()
    for k in model.K:
        model.con_part.add(model.x[edge_list['from_i'][k]] <= model.x[edge_list['to_i'][k]])

x is a binary variable. Mathematically, I would write something like this:

$$x_1\le x_2\quad\forall e_k(x_1,x_2)$$

$e_k$ is an edge which goes form $x_1$ to $x_2$. $k\in K$ which are all the edges of the graph.

Is there a way to express this nicely?

teshim
  • 61
  • 1

1 Answers1

3

Mathematically, you could write the following.

Let $V = \{1,2,\dots,n\}$ be the set of vertices. Each directed arc from $i \in V$ to $j \in V$ is denoted by $(i,j)$. The set $E$ is the set of all arcs.

The constraint can then be stated as $$x_i\le x_j\quad\forall (i,j) \in E.$$

This is more natural, because $x_i$ now always refers to vertex $i$, where the current definition uses $x_1$ and $x_2$ as placeholders.

Kevin Dalmeijer
  • 6,167
  • 1
  • 17
  • 48