Creating/Using a set dealing about a topological connection

Performing an electrical calculation, there are data dealing about “nodes” and “branches” like

node (id): 1, 2, 3, 4 (four nodes in the network)

branch data (three branches in the network, connecting the four nodes - “from” and “to” side can be switched):

id | from (node) | to (node) | branch-status (binary)
1 1 2 1
2 3 2 1
3 4 3 1

In future, the parameter branch-status shall become a variable, so that the solver can decide about the status.

Is there a possibility to setup a set, dealing with the connected nodes starting at a certain initial node-id (e.g. “1”)?
So, in the example, this set shall contais the data (1,2,3,4) since all nodes are connected among each other.

Setting the 3rd branch-status to 0, the set only have to contain the data (1,2,3) since node 4 isn’t connected any more.

Starting from the original status information and setting the 1st branch-status to 0, the set only have to contain the data (1) - only the initial node remains in the set.

Best regards,
Lothar

If the branch status is a parameter, then you can write a few lines of programming to determine all nodes connected to node 1. It would basically be a loop that starts with node 1 and keeps adding connected nodes until no more can be found. It could use AMPL statements (in an AMPL script) or statements from some general-purpose programming language for which AMPL has an API (for example Python statements if you’re working with amplpy).

AMPL sets are part of the model’s data, however, and their membership needs to be known before solving. Thus if the branch status is a variable, you can’t define an AMPL set whose members are determined by the branch statuses.

Would it work for your model to have another binary variable, indexed over nodes, that is 1 for every node that is connected to node 1, and 0 for every node not connected? Then maybe it is possible to construct constraints that enforce the necessary relationship between these node-connect variables and the branch-status variables. That would be a good question to ask at https://or.stackexchange.com/, where there are many discussions of formulations.