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)
    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?

  • 3
    $\begingroup$ It looks pretty nice to me. Can you clarify what the problem is? $\endgroup$ Jan 25, 2020 at 17:52
  • $\begingroup$ I was just wondering if this is clear enough to a reader. If so then there isn't a problem. $\endgroup$
    – teshim
    Jan 26, 2020 at 9:31

1 Answer 1


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.

  • $\begingroup$ Thanks, looks more clear to me. $\endgroup$
    – teshim
    Jan 26, 2020 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.