Why does this code in repast j for java creates double the amount of "outedge"

110 Views Asked by At

I am modeling a supply chain with an customer, retailer and supplier. They are connected in a node. I have found this code. But I do not understand, why this code creates the double amount of outedges. Perhaps, someone can help?

      while (it.hasNext()) {
                // Find the next agent to link to.
                tempAgent = (supply_chain_agent) it.next();
                System.out.println(tempAgent);


                // Create an edge from the last agent to the temp agent.
                tempEdge = new supply_chain_edge("Orders", 1, this.initialOrderPerTimeStep);

                // Connect the new edge.
                tempAgent.addInEdge(tempEdge);
                System.out.println(tempEdge.getLabel());

                lastAgent.addOutEdge(tempEdge);
                System.out.println(tempEdge.getLabel());

                tempEdge.setTo(tempAgent);
                tempEdge.setFrom(lastAgent);

                // Create an edge from the temp agent to the last agent.
                if (lastAgent.getNodeLabel().startsWith("Customer")) {
                    tempEdge = new supply_chain_edge("Shipments", this.ordering_delay, this.initialOrderPerTimeStep);
                } else {
                    tempEdge = new supply_chain_edge("Shipments", this.delivery_delay, this.initialOrderPerTimeStep);
                }

                // Connect the new edge.
                lastAgent.addInEdge(tempEdge);
                System.out.println(tempEdge.getLabel());

                tempAgent.addOutEdge(tempEdge);
                System.out.println(tempEdge.getLabel());

                tempEdge.setTo(lastAgent);
                tempEdge.setFrom(tempAgent);

                // Move on.
                lastAgent = tempAgent;
                System.out.println(lastAgent);

            }
0

There are 0 best solutions below