2

The original solution for creating only one custom edge is here: Repast Java: Creating a custom edge agent to schedule specific actions

1). Now I have a demand for creating more than one type of custom edge to be acted as unique agents (e.g. in my model I have route agent, supply-link agent, relationship-link agent). Do I have to repeat again the above process described in the link? (i.e. add a another dedicated CustomEdgeCreator class and CustomEdge class with a different name), or is there a more efficient method?

2). Given the above example in Zombie model, I noticed that the creation of custom edge through CustomEdgeCreator method does not make the edge agent class visible in the GUI, which is not convenient to track the related properties associated with the edge agent.

enter image description here

It's also not working to perform data collection from edge agent. I have set the weight for each edge as 2 but the sum of them displayed in the chart is 0.

enter image description here

enter image description here

Above problems lead to an important question: How does the edge class differ from the normal agent class?

Jack
  • 1,131
  • 1
  • 8
  • 17

1 Answers1

3

Regarding your first point: Since you're associating each network projection with a specific EdgeCreator instance, you could potentially make the EdgeCreator constructor accept the Link type that you'd like that network projection to create. That would potentially make things a little more streamlined.

Adding requested example here:

package jzombies;

import repast.simphony.space.graph.EdgeCreator;
import repast.simphony.space.graph.RepastEdge;

public class CustomEdgeCreator<E extends RepastEdge<T>, T> implements EdgeCreator<E, T> {

    private Class<E> e;

    public CustomEdgeCreator(Class<E> e) {
        this.e = e;
    }

    @Override
    public Class<E> getEdgeType() {
        return e;
    }

    @Override
    public E createEdge(T source, T target, boolean isDirected, double weight) {
        try {
            return e.getDeclaredConstructor(new Class[]{Object.class, Object.class, boolean.class, double.class}).newInstance(source, target, isDirected, weight);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

Regarding your second point: Unless you add the edge that is created into the context, it won't show up as a true agent. So, upon creating a network link, you could add it to the context and it should show up both in the agent table and for data collection purposes.

J. Ozik
  • 1,041
  • 3
  • 4
  • thanks for your answer. 1). would you please provide the code example of using one EdgeCreator to create different types of edges? (actually I want it as different classes of edges) 2). I tried with the studpid method of repeating the above whole process to create another new EdgeCreator and CustomerEdge with different name. I found that it's not possible to put different Edge classes in one network projection. I have to create a new projection to accommodate the new edge class. any advice? – Jack Oct 22 '19 at 15:15
  • Re: 1. I've added an example snippet to create a CustomEdgeCreator that can take the class of the edge type that you want it to create, but I don't think it's worth the complex code, since you'd still need to create the Edge class itself anyway. Re: 2. Each network projection will be associated with a specific edge type, so you wouldn't be able to mix and max edge types within a single network. – J. Ozik Oct 23 '19 at 17:42