Quantcast

Custom edge types for NetworkBuilder

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Custom edge types for NetworkBuilder

Van Parunak
I'm trying to use repast.simphony.context.space.graph.NetworkBuilder
with custom edge types, following the examples Nick gives in
https://sourceforge.net/p/repast/mailman/message/23914897/, but I'm
apparently missing something.

I've got two classes, at this point just shells. One defines the new
edge type:

> package assist;
>
> import repast.simphony.space.graph.*;
>
>
> public class AssistEdge extends RepastEdge<Object> {
>     /*
>      * RepastEdge provides getSource, getTarget, getWeight methods
>      */
>
>     public AssistEdge(Object source, Object target, boolean isDirected) {
>         super(source, target, isDirected);
>     }
>
>     public AssistEdge(Object source, Object target, boolean
> isDirected, double weight) {
>         super(source, target, isDirected, weight);
>     }
> }
and the other defines the edge creator:

> package assist;
>
> import repast.simphony.space.graph.EdgeCreator;
> import repast.simphony.space.graph.RepastEdge;
>
>
> public class AssistEdgeCreator implements
> EdgeCreator<RepastEdge<Object>, Object>{
>     /*
>      * RepastEdge provides getSource, getTarget, getWeight methods
>      */
>
>     @Override
>     public AssistEdge createEdge(Object source, Object target, boolean
> isDirected, double weight) {
>         System.out.println("Making new edge between " +
> source.toString() + " and " + target.toString() );
>         return new AssistEdge(source, target, isDirected, 0);
>     }
>
>     @Override
>     public Class getEdgeType() {
>         return AssistEdge.class;
>     }
>
> }
I try to use this in the build() method of my context builder like this:

> NetworkBuilder<Object> targetBuilder = new
> NetworkBuilder<Object>("target", targetContext, false);
> targetBuilder.setEdgeCreator(xxx);
But I can't find an argument for setEdgeCreator that makes it happy.

* targetBuilder.setEdgeCreator(AssistEdgeCreator.createEdge()) complains
"The method createEdge(Object, Object, boolean, double) in the type
AssistEdgeCreator is not applicable for the arguments ()"

* targetBuilder.setEdgeCreator(AssistEdgeCreator) complains
"AssistEdgeCreator cannot be resolved to a variable."

* targetBuilder.setEdgeCreator(AssistEdgeCreator.class) complains "The
method setEdgeCreator(EdgeCreator) in the type NetworkBuilder<Object> is
not applicable for the arguments (Class<AssistEdgeCreator>)."

What am I doing wrong? What's the right way to tell my NetworkBuilder to
invoke my EdgeCreator?

Thanks!



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom edge types for NetworkBuilder

srcnick
I think this should work:

AssistEdgeCreator creator = new AssistEdgeEdgeCreator();
targetBuilder.setEdgeCreator(creator);

Nick

> On Apr 12, 2017, at 5:46 PM, Van Parunak <[hidden email]> wrote:
>
> I'm trying to use repast.simphony.context.space.graph.NetworkBuilder
> with custom edge types, following the examples Nick gives in
> https://sourceforge.net/p/repast/mailman/message/23914897/, but I'm
> apparently missing something.
>
> I've got two classes, at this point just shells. One defines the new
> edge type:
>
>> package assist;
>>
>> import repast.simphony.space.graph.*;
>>
>>
>> public class AssistEdge extends RepastEdge<Object> {
>>    /*
>>     * RepastEdge provides getSource, getTarget, getWeight methods
>>     */
>>
>>    public AssistEdge(Object source, Object target, boolean isDirected) {
>>        super(source, target, isDirected);
>>    }
>>
>>    public AssistEdge(Object source, Object target, boolean
>> isDirected, double weight) {
>>        super(source, target, isDirected, weight);
>>    }
>> }
> and the other defines the edge creator:
>
>> package assist;
>>
>> import repast.simphony.space.graph.EdgeCreator;
>> import repast.simphony.space.graph.RepastEdge;
>>
>>
>> public class AssistEdgeCreator implements
>> EdgeCreator<RepastEdge<Object>, Object>{
>>    /*
>>     * RepastEdge provides getSource, getTarget, getWeight methods
>>     */
>>
>>    @Override
>>    public AssistEdge createEdge(Object source, Object target, boolean
>> isDirected, double weight) {
>>        System.out.println("Making new edge between " +
>> source.toString() + " and " + target.toString() );
>>        return new AssistEdge(source, target, isDirected, 0);
>>    }
>>
>>    @Override
>>    public Class getEdgeType() {
>>        return AssistEdge.class;
>>    }
>>
>> }
> I try to use this in the build() method of my context builder like this:
>
>> NetworkBuilder<Object> targetBuilder = new
>> NetworkBuilder<Object>("target", targetContext, false);
>> targetBuilder.setEdgeCreator(xxx);
> But I can't find an argument for setEdgeCreator that makes it happy.
>
> * targetBuilder.setEdgeCreator(AssistEdgeCreator.createEdge()) complains
> "The method createEdge(Object, Object, boolean, double) in the type
> AssistEdgeCreator is not applicable for the arguments ()"
>
> * targetBuilder.setEdgeCreator(AssistEdgeCreator) complains
> "AssistEdgeCreator cannot be resolved to a variable."
>
> * targetBuilder.setEdgeCreator(AssistEdgeCreator.class) complains "The
> method setEdgeCreator(EdgeCreator) in the type NetworkBuilder<Object> is
> not applicable for the arguments (Class<AssistEdgeCreator>)."
>
> What am I doing wrong? What's the right way to tell my NetworkBuilder to
> invoke my EdgeCreator?
>
> Thanks!
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Repast-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom edge types for NetworkBuilder

Van Parunak
That does it--thanks, Nick.


On 4/13/17 10:50, Nick Collier wrote:
> AssistEdgeCreator creator = new AssistEdgeEdgeCreator();
> targetBuilder.setEdgeCreator(creator);


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...