ScheduledMethod() not called in ContextBuilder

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

ScheduledMethod() not called in ContextBuilder

joshhyatt451
I have created a repast project to model a financial market.

Run.java
Builder.java
Agent.java
Please see the files above.

In the builder class I have created a load of instances at the top, then manipulated them with for loops etc in the context build method. The plan was to then have a scheduled method that would run continually throughout the duration of the project making reference to the assets and manipulating values etc. Although whatever I did I couldn't get the scheduled method go to run as a scheduled method - it wouldn't fire.

The compromise was something I found here - https://sourceforge.net/p/repast/mailman/message/34464726/ 

I created run, extended builder and created a scheduled method, it worked - great. The issue I'm having however is that the go method in Run can't see anything in the build in the builder class, which is fine for most as I can create the instances above it, e.g. assets on lines 27-29, but I need to use a for loop to be able loop through an array to create my agents for the model, which I can't do, and so can't call my step method from my trading agents.
I would bring it all into the constructor of run but then I can't add my agents into the context.

Can someone please advise me on how to get round this problem? Or is there a way I could achieve a scheduled method in my Builder class to avoid this issue,

FYI I have a decent knowledge of Java, limited knowledge of Repast Simphony.

Any help would be greatly appreciated,
Thanks, Josh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ScheduledMethod() not called in ContextBuilder

srcnick
If I understand you correctly, can you put all the fields in Builder into Run. Run doesn’t need to extend Builder anymore. Builder.build(context) then just creates Run and calls Run.build(context) — passing the context from its own build method. Builder would look something like:

public class Builder implements ContextBuilder<Object> {
public Context build(Context<Object> context) {
Run run = new Run();
run.build(context);
context.add(run);
return context;
}
}

Run.build would have almost all of what’s in Builder.build now except for the bit above. 


Better yet, and rather than add Run to the context where its not really an agent, you could also schedule a method on it directly. Using Java 8’s lambdas that looks like:

RunEnvironment.getInstance().getCurrentSchedule().schedule(ScheduleParameters.createRepeating(1, 1), 
        ()-> run.go());

You don’t need to use the @ScheduledMethod on Run.go anymore that way either, or add it to the context. So, Builder is then:

public class Builder implements ContextBuilder<Object> {
public Context build(Context<Object> context) {
Run run = new Run();
run.build(context);
RunEnvironment.getInstance().getCurrentSchedule().schedule(ScheduleParameters.createRepeating(1, 1), 
        ()-> run.go());
return context;
}
}


I hope that makes sense and that I’ve understood you correctly.

Nick

On Apr 17, 2017, at 4:52 PM, joshhyatt451 <[hidden email]> wrote:

I have created a repast project to model a financial market.

Run.java <http://repast.10935.n7.nabble.com/file/n11932/Run.java>  
Builder.java <http://repast.10935.n7.nabble.com/file/n11932/Builder.java>  
Agent.java <http://repast.10935.n7.nabble.com/file/n11932/Agent.java>  
Please see the files above.

In the builder class I have created a load of instances at the top, then
manipulated them with for loops etc in the context build method. The plan
was to then have a scheduled method that would run continually throughout
the duration of the project making reference to the assets and manipulating
values etc. Although whatever I did I couldn't get the scheduled method go
to run as a scheduled method - it wouldn't fire.

The compromise was something I found here -
https://sourceforge.net/p/repast/mailman/message/34464726/  

I created run, extended builder and created a scheduled method, it worked -
great. The issue I'm having however is that the go method in Run can't see
anything in the build in the builder class, which is fine for most as I can
create the instances above it, e.g. assets on lines 27-29, but I need to use
a for loop to be able loop through an array to create my agents for the
model, which I can't do, and so can't call my step method from my trading
agents.
I would bring it all into the constructor of run but then I can't add my
agents into the context.

Can someone please advise me on how to get round this problem? Or is there a
way I could achieve a scheduled method in my Builder class to avoid this
issue,

FYI I have a decent knowledge of Java, limited knowledge of Repast Simphony.

Any help would be greatly appreciated,
Thanks, Josh



--
View this message in context: http://repast.10935.n7.nabble.com/ScheduledMethod-not-called-in-ContextBuilder-tp11932.html
Sent from the repast-interest mailing list archive at Nabble.com.

------------------------------------------------------------------------------
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: ScheduledMethod() not called in ContextBuilder

joshhyatt451
Yes that has worked wonderfully. Thank you so much!
Loading...