// traverse the input network and make a list of the nodes in // the network. We want only one copy of a node that appears // in the network. This list is used to build a new network with // pointers. *operation* Node_List* all_nodes() *init* (@ new Node_List() @) *traverse* *from* InputNetwork *to-stop* InputAdjacency *wrapper* InputAdjacency (@ InputNode* in_node = get_source(); if (!(return_val->id_member(in_node))) { Node* node = new Node(in_node->get_id(), new VNode_ParList()); return_val->append(node); } @) // find the position of a node with the same id as "node" in the // list of nodes. If there is no such node, the function returns 0. *operation* int id_member(InputNode* node) *init* (@ 0 @) *traverse* *from* Node_List *to-stop* Node *carry* *inout* int count = (@ 0 @) *along* *from* Node_List *to-stop* Node *wrapper* Node (@ count++; if (this->get_id()->g_equal(node->get_id())) return_val = count; @) // use the list of nodes "nodelist" to build a new network where // there is only one copy of each node. *operation* Network* rebuild_network(Node_List*& nodelist) *wrapper* InputNetwork (@ nodelist = this->all_nodes(); Network* new_net = new Network(new Adjacency_ParList()); this->traverse_net(nodelist, new_net); return_val = new_net; @) // this is the function that actually does the work for the network // rebuilt. *operation* void traverse_net(Node_List* nodelist, Network* net) *traverse* *from* InputNetwork *to-stop* InputAdjacency *wrapper* InputAdjacency (@ int pos = nodelist->id_member(get_source()); if (pos == 0) { cout << "***Error!\n"; exit(1); } Node* node = nodelist->n_th(pos); Neighbor_ParList* neighbors = new Neighbor_ParList(); Adjacency* new_adj = new Adjacency(node, neighbors, new DemNumber(0)); this->update_neighbors(nodelist, new_adj); net->get_adjacencies()->append(new_adj); @) // add neighbors to the adjacency "adj", using the list of nodes *operation* void update_neighbors(Node_List* nodelist, Adjacency* adj) *traverse* *from* InputAdjacency *through* -> *, neighbors, * *to-stop* InputNeighbor *wrapper* InputNeighbor (@ int pos = nodelist->id_member(get_node()); Node* node = nodelist->n_th(pos); Neighbor* new_neighbor = new Neighbor(node, get_capacity()); adj->get_neighbors()->append(new_neighbor); @)