# How to write a constraint for a directed graph?

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:


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?

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

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.