Avoiding a nonlinear expression in JuMP

I have formulated a flow conservation constraint in JuMP for a linear model.

  @constraint(SPF_IM, cons5[t in aggList, c in t.VNFChains, n in subGraph.nodes],
              sum((fI[t.ID,c.ID,e.ID] - fO[t.ID,c.ID,e.ID]) for e in n.outEdges)
              - sum((fI[t.ID,c.ID,e.ID] - fO[t.ID,c.ID,e.ID]) for e in n.inEdges)
              == ((z[t.ID] ^ (c.tailID == 1)) * (x[t.ID,c.tailID,n.ID] ^ (c.tailID != 1))
              - x[t.ID,c.headID,n.ID]))

On the RHS, If the tailID = 1, then I want to retain the variable z[t.ID] and if not, the variable x[t.ID,c.tailID,n.ID]. Constraint seems linear to me under these conditions but JuMP throws up an error saying its nonlinear. I understand the reason why its doing so but is there a way to express it without losing the linear property?

you can use: c.tailID == 1 ? z[t.ID] : x[t.ID,c.tailID,n.ID]


It worked like a charm :slight_smile: Thanks Joaquim, you saved my day!