Repast Java: Problem of Creating Multiple types of Custom Edge

Viewed 70

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?

1 Answers

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.

Related