Repast System Dynamics issue with code generation? - rate name influences calculation results

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

Repast System Dynamics issue with code generation? - rate name influences calculation results

Michal Kecera
Hi Everyone,

I've built a very simple SD model with two stocks connected by one rate and in parallel another two stocks connected by one rate. Both stock-rate-stock combinations do the exactly the same but the names are different. When I generate code for this (which is included below), it puts calculation of one of those rates above the stock it should influence therefore giving incorrect results. The results for the other stock is correct.

It seems like the calculation is influenced by names of the rates and stocks and produces different results even though the logic is exactly the same. Have you encountered this before or am I missing something? Will be grateful for any advice.

Kind regards,

Michal.

package testX;

// imports

import repast.simphony.systemdynamics.support.SDModelWithPropertiesVDM_Native;
import repast.simphony.engine.schedule.ISchedule;
import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.engine.environment.RunEnvironment;
import repast.simphony.parameter.Parameters;
import repast.simphony.systemdynamics.support.MessageJava;
import repast.simphony.systemdynamics.support.ResultsReporterJava;
import repast.simphony.systemdynamics.support.SDFunctionsWithXLSColt;


public class TestX extends SDModelWithPropertiesVDM_Native {

private MemoryTestX memory;
public TestX(String name) {
this(name, null);
}

public TestX(String name, String[] args) {
super(name,true, args);

sdFunctions = new SDFunctionsWithXLSColt(this);
message = new MessageJava();
results = new ResultsReporterJava();
memory = new MemoryTestX();


timeSeriesData.setNativeDataTypes(true);
oneTime();
}

public MemoryTestX getMemory() {
return memory;
}

@Override
public double getINITIALTIME() {
return memory.getINITIALTIME();
}
@Override
public double getFINALTIME() {
return memory.getFINALTIME();
}
@Override
public double getTIMESTEP() {
return memory.getTIMESTEP();
}
protected void oneTime0() {

double time = 0.0;
double timeStep = getTIMESTEP();
Parameters params = RunEnvironment.getInstance().getParameters();
/*
Equation: FINAL TIME = 12.0

Units:null

Comment: None Provided

*/
{
    memory.FINAL_TIME = (Double) params.getValue("FINAL_TIME"); // 2;
logit("memory.FINAL_TIME", getINITIALTIME(), (Double) params.getValue("FINAL_TIME"),memory.get_SAVEPER());
}
/*
Equation: NAREPLACEMENT = 0.0000001

Units:any

Comment: This is autogenerated

*/
{
    memory.NAREPLACEMENT = 0.0000001;
logit("memory.NAREPLACEMENT", getINITIALTIME(), 0.0000001,memory.get_SAVEPER());
}
/*
Equation: INITIAL TIME = 0.0

Units:null

Comment: None Provided

*/
{
    memory.INITIAL_TIME = (Double) params.getValue("INITIAL_TIME"); // 2;
logit("memory.INITIAL_TIME", getINITIALTIME(), (Double) params.getValue("INITIAL_TIME"),memory.get_SAVEPER());
}
/*
Equation: Time=0.0

Units:null

Comment: This is autogenerated

*/
{
    memory.Time = 0.0;
logit("memory.Time", getINITIALTIME(), 0.0,memory.get_SAVEPER());
}
/*
Equation: SAVEPER = 1.0

Units:null

Comment: None Provided

*/
{
    memory.SAVEPER = (Double) params.getValue("SAVEPER"); // 2;
logit("memory.SAVEPER", getINITIALTIME(), (Double) params.getValue("SAVEPER"),memory.get_SAVEPER());
}
/*
Equation: TIME STEP = 1.0

Units:null

Comment: None Provided

*/
{
    memory.TIME_STEP = (Double) params.getValue("TIME_STEP"); // 2;
logit("memory.TIME_STEP", getINITIALTIME(), (Double) params.getValue("TIME_STEP"),memory.get_SAVEPER());
}
{
/*
Equation: StockPotentialCBDe= INTEG(-RataAcquiringMOPr,1000)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("StockPotentialCBDe",memory.StockPotentialCBDe,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.RataAcquiringMOPr)) ),(1000));
memory.StockPotentialCBDe = _t0;
/* log6 */logit("memory.StockPotentialCBDe",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: Stock1= INTEG(-Rate12,1000)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("Stock1",memory.Stock1,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.Rate12)) ),(1000));
memory.Stock1 = _t0;
/* log6 */logit("memory.Stock1",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: Stock2= INTEG(Rate12,0)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("Stock2",memory.Stock2,time,timeStep,(time == 0.0 ? 0.0 : (memory.Rate12) ),(0));
memory.Stock2 = _t0;
/* log6 */logit("memory.Stock2",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: StockNewCBDe= INTEG(RataAcquiringMOPr,0)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("StockNewCBDe",memory.StockNewCBDe,time,timeStep,(time == 0.0 ? 0.0 : (memory.RataAcquiringMOPr) ),(0));
memory.StockNewCBDe = _t0;
/* log6 */logit("memory.StockNewCBDe",time,_t0,memory.get_SAVEPER());
}
}

protected void oneTime() {

   oneTime0();
}

@ScheduledMethod(start = 1,interval = 1,shuffle = true)
public void step() {
ISchedule schedule = repast.simphony.engine.environment.RunEnvironment
.getInstance().getCurrentSchedule();
double timeStep = memory.getTIMESTEP();
double time = memory.getINITIALTIME() + (schedule.getTickCount() - 1.0);
double nextTime = time + 1.0;
while (time < nextTime) {
memory.Time = time;
currentTime = time;
repeated(time, timeStep);
time += timeStep;
}
}

protected void repeated0(double time, double timeStep) {

{
/*
Equation: StockPotentialCBDe= INTEG(-RataAcquiringMOPr,1000)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("StockPotentialCBDe",memory.StockPotentialCBDe,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.RataAcquiringMOPr)) ),(1000));
memory.StockPotentialCBDe = _t0;
/* log6 */logit("memory.StockPotentialCBDe",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: RataAcquiringMOPR=StockPotentialCBDe*0.1

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = (memory.StockPotentialCBDe) * (0.1);
memory.RataAcquiringMOPR = _t0;
/* log6 */logit("memory.RataAcquiringMOPR",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: Stock1= INTEG(-Rate12,1000)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("Stock1",memory.Stock1,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.Rate12)) ),(1000));
memory.Stock1 = _t0;
/* log6 */logit("memory.Stock1",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: Stock2= INTEG(Rate12,0)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("Stock2",memory.Stock2,time,timeStep,(time == 0.0 ? 0.0 : (memory.Rate12) ),(0));
memory.Stock2 = _t0;
/* log6 */logit("memory.Stock2",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: StockNewCBDe= INTEG(RataAcquiringMOPr,0)

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = sdFunctions.INTEG("StockNewCBDe",memory.StockNewCBDe,time,timeStep,(time == 0.0 ? 0.0 : (memory.RataAcquiringMOPr) ),(0));
memory.StockNewCBDe = _t0;
/* log6 */logit("memory.StockNewCBDe",time,_t0,memory.get_SAVEPER());
}
{
/*
Equation: Rate12=Stock1*0.1

Units:people

Comment: None Provided

*/
double _t0 = 0.0;
_t0 = (memory.Stock1) * (0.1);
memory.Rate12 = _t0;
/* log6 */logit("memory.Rate12",time,_t0,memory.get_SAVEPER());
}
}

protected void repeated(double time, double timeStep) {

  data.setCurrentTime(time);
  setValue("Time", time);
  timeSeriesData.advanceTime(data, time);
  updateTimeSeriesReferences(time);
   repeated0(time, timeStep);
}

public double getFINAL_TIME() {return memory.FINAL_TIME;}
public void   setFINAL_TIME(double value) {memory.FINAL_TIME = value;}
public double getINITIAL_TIME() {return memory.INITIAL_TIME;}
public void   setINITIAL_TIME(double value) {memory.INITIAL_TIME = value;}
public double getNAREPLACEMENT() {return memory.NAREPLACEMENT;}
public void   setNAREPLACEMENT(double value) {memory.NAREPLACEMENT = value;}
public double getRataAcquiringMOPR() {return memory.RataAcquiringMOPR;}
public void   setRataAcquiringMOPR(double value) {memory.RataAcquiringMOPR = value;}
public double getRataAcquiringMOPr() {return memory.RataAcquiringMOPr;}
public void   setRataAcquiringMOPr(double value) {memory.RataAcquiringMOPr = value;}
public double getRate12() {return memory.Rate12;}
public void   setRate12(double value) {memory.Rate12 = value;}
public double getSAVEPER() {return memory.SAVEPER;}
public void   setSAVEPER(double value) {memory.SAVEPER = value;}
public double getStock1() {return memory.Stock1;}
public void   setStock1(double value) {memory.Stock1 = value;}
public double getStock2() {return memory.Stock2;}
public void   setStock2(double value) {memory.Stock2 = value;}
public double getStockNewCBDe() {return memory.StockNewCBDe;}
public void   setStockNewCBDe(double value) {memory.StockNewCBDe = value;}
public double getStockPotentialCBDe() {return memory.StockPotentialCBDe;}
public void   setStockPotentialCBDe(double value) {memory.StockPotentialCBDe = value;}
public double getTIME_STEP() {return memory.TIME_STEP;}
public void   setTIME_STEP(double value) {memory.TIME_STEP = value;}
public double getTime() {return memory.Time;}
public void   setTime(double value) {memory.Time = value;}
protected void updateTimeSeriesReferences(double time) {

}

}




------------------------------------------------------------------------------
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: Repast System Dynamics issue with code generation? - rate name influences calculation results

srcnick
Michal,

Thanks for letting us know about this. We are looking into it.

Nick

> On Jan 26, 2017, at 3:47 AM, Michal Kecera <[hidden email]> wrote:
>
> Hi Everyone,
>
> I've built a very simple SD model with two stocks connected by one rate and in parallel another two stocks connected by one rate. Both stock-rate-stock combinations do the exactly the same but the names are different. When I generate code for this (which is included below), it puts calculation of one of those rates above the stock it should influence therefore giving incorrect results. The results for the other stock is correct.
>
> It seems like the calculation is influenced by names of the rates and stocks and produces different results even though the logic is exactly the same. Have you encountered this before or am I missing something? Will be grateful for any advice.
>
> Kind regards,
>
> Michal.
>
> package testX;
>
> // imports
>
> import repast.simphony.systemdynamics.support.SDModelWithPropertiesVDM_Native;
> import repast.simphony.engine.schedule.ISchedule;
> import repast.simphony.engine.schedule.ScheduledMethod;
> import repast.simphony.engine.environment.RunEnvironment;
> import repast.simphony.parameter.Parameters;
> import repast.simphony.systemdynamics.support.MessageJava;
> import repast.simphony.systemdynamics.support.ResultsReporterJava;
> import repast.simphony.systemdynamics.support.SDFunctionsWithXLSColt;
>
>
> public class TestX extends SDModelWithPropertiesVDM_Native {
>
> private MemoryTestX memory;
> public TestX(String name) {
> this(name, null);
> }
>
> public TestX(String name, String[] args) {
> super(name,true, args);
>
> sdFunctions = new SDFunctionsWithXLSColt(this);
> message = new MessageJava();
> results = new ResultsReporterJava();
> memory = new MemoryTestX();
>
>
> timeSeriesData.setNativeDataTypes(true);
> oneTime();
> }
>
> public MemoryTestX getMemory() {
> return memory;
> }
>
> @Override
> public double getINITIALTIME() {
> return memory.getINITIALTIME();
> }
> @Override
> public double getFINALTIME() {
> return memory.getFINALTIME();
> }
> @Override
> public double getTIMESTEP() {
> return memory.getTIMESTEP();
> }
> protected void oneTime0() {
>
> double time = 0.0;
> double timeStep = getTIMESTEP();
> Parameters params = RunEnvironment.getInstance().getParameters();
> /*
> Equation: FINAL TIME = 12.0
>
> Units:null
>
> Comment: None Provided
>
> */
> {
>     memory.FINAL_TIME = (Double) params.getValue("FINAL_TIME"); // 2;
> logit("memory.FINAL_TIME", getINITIALTIME(), (Double) params.getValue("FINAL_TIME"),memory.get_SAVEPER());
> }
> /*
> Equation: NAREPLACEMENT = 0.0000001
>
> Units:any
>
> Comment: This is autogenerated
>
> */
> {
>     memory.NAREPLACEMENT = 0.0000001;
> logit("memory.NAREPLACEMENT", getINITIALTIME(), 0.0000001,memory.get_SAVEPER());
> }
> /*
> Equation: INITIAL TIME = 0.0
>
> Units:null
>
> Comment: None Provided
>
> */
> {
>     memory.INITIAL_TIME = (Double) params.getValue("INITIAL_TIME"); // 2;
> logit("memory.INITIAL_TIME", getINITIALTIME(), (Double) params.getValue("INITIAL_TIME"),memory.get_SAVEPER());
> }
> /*
> Equation: Time=0.0
>
> Units:null
>
> Comment: This is autogenerated
>
> */
> {
>     memory.Time = 0.0;
> logit("memory.Time", getINITIALTIME(), 0.0,memory.get_SAVEPER());
> }
> /*
> Equation: SAVEPER = 1.0
>
> Units:null
>
> Comment: None Provided
>
> */
> {
>     memory.SAVEPER = (Double) params.getValue("SAVEPER"); // 2;
> logit("memory.SAVEPER", getINITIALTIME(), (Double) params.getValue("SAVEPER"),memory.get_SAVEPER());
> }
> /*
> Equation: TIME STEP = 1.0
>
> Units:null
>
> Comment: None Provided
>
> */
> {
>     memory.TIME_STEP = (Double) params.getValue("TIME_STEP"); // 2;
> logit("memory.TIME_STEP", getINITIALTIME(), (Double) params.getValue("TIME_STEP"),memory.get_SAVEPER());
> }
> {
> /*
> Equation: StockPotentialCBDe= INTEG(-RataAcquiringMOPr,1000)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("StockPotentialCBDe",memory.StockPotentialCBDe,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.RataAcquiringMOPr)) ),(1000));
> memory.StockPotentialCBDe = _t0;
> /* log6 */logit("memory.StockPotentialCBDe",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: Stock1= INTEG(-Rate12,1000)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("Stock1",memory.Stock1,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.Rate12)) ),(1000));
> memory.Stock1 = _t0;
> /* log6 */logit("memory.Stock1",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: Stock2= INTEG(Rate12,0)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("Stock2",memory.Stock2,time,timeStep,(time == 0.0 ? 0.0 : (memory.Rate12) ),(0));
> memory.Stock2 = _t0;
> /* log6 */logit("memory.Stock2",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: StockNewCBDe= INTEG(RataAcquiringMOPr,0)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("StockNewCBDe",memory.StockNewCBDe,time,timeStep,(time == 0.0 ? 0.0 : (memory.RataAcquiringMOPr) ),(0));
> memory.StockNewCBDe = _t0;
> /* log6 */logit("memory.StockNewCBDe",time,_t0,memory.get_SAVEPER());
> }
> }
>
> protected void oneTime() {
>
>    oneTime0();
> }
>
> @ScheduledMethod(start = 1,interval = 1,shuffle = true)
> public void step() {
> ISchedule schedule = repast.simphony.engine.environment.RunEnvironment
> .getInstance().getCurrentSchedule();
> double timeStep = memory.getTIMESTEP();
> double time = memory.getINITIALTIME() + (schedule.getTickCount() - 1.0);
> double nextTime = time + 1.0;
> while (time < nextTime) {
> memory.Time = time;
> currentTime = time;
> repeated(time, timeStep);
> time += timeStep;
> }
> }
>
> protected void repeated0(double time, double timeStep) {
>
> {
> /*
> Equation: StockPotentialCBDe= INTEG(-RataAcquiringMOPr,1000)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("StockPotentialCBDe",memory.StockPotentialCBDe,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.RataAcquiringMOPr)) ),(1000));
> memory.StockPotentialCBDe = _t0;
> /* log6 */logit("memory.StockPotentialCBDe",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: RataAcquiringMOPR=StockPotentialCBDe*0.1
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = (memory.StockPotentialCBDe) * (0.1);
> memory.RataAcquiringMOPR = _t0;
> /* log6 */logit("memory.RataAcquiringMOPR",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: Stock1= INTEG(-Rate12,1000)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("Stock1",memory.Stock1,time,timeStep,(time == 0.0 ? 0.0 : (- (memory.Rate12)) ),(1000));
> memory.Stock1 = _t0;
> /* log6 */logit("memory.Stock1",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: Stock2= INTEG(Rate12,0)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("Stock2",memory.Stock2,time,timeStep,(time == 0.0 ? 0.0 : (memory.Rate12) ),(0));
> memory.Stock2 = _t0;
> /* log6 */logit("memory.Stock2",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: StockNewCBDe= INTEG(RataAcquiringMOPr,0)
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = sdFunctions.INTEG("StockNewCBDe",memory.StockNewCBDe,time,timeStep,(time == 0.0 ? 0.0 : (memory.RataAcquiringMOPr) ),(0));
> memory.StockNewCBDe = _t0;
> /* log6 */logit("memory.StockNewCBDe",time,_t0,memory.get_SAVEPER());
> }
> {
> /*
> Equation: Rate12=Stock1*0.1
>
> Units:people
>
> Comment: None Provided
>
> */
> double _t0 = 0.0;
> _t0 = (memory.Stock1) * (0.1);
> memory.Rate12 = _t0;
> /* log6 */logit("memory.Rate12",time,_t0,memory.get_SAVEPER());
> }
> }
>
> protected void repeated(double time, double timeStep) {
>
>   data.setCurrentTime(time);
>   setValue("Time", time);
>   timeSeriesData.advanceTime(data, time);
>   updateTimeSeriesReferences(time);
>    repeated0(time, timeStep);
> }
>
> public double getFINAL_TIME() {return memory.FINAL_TIME;}
> public void   setFINAL_TIME(double value) {memory.FINAL_TIME = value;}
> public double getINITIAL_TIME() {return memory.INITIAL_TIME;}
> public void   setINITIAL_TIME(double value) {memory.INITIAL_TIME = value;}
> public double getNAREPLACEMENT() {return memory.NAREPLACEMENT;}
> public void   setNAREPLACEMENT(double value) {memory.NAREPLACEMENT = value;}
> public double getRataAcquiringMOPR() {return memory.RataAcquiringMOPR;}
> public void   setRataAcquiringMOPR(double value) {memory.RataAcquiringMOPR = value;}
> public double getRataAcquiringMOPr() {return memory.RataAcquiringMOPr;}
> public void   setRataAcquiringMOPr(double value) {memory.RataAcquiringMOPr = value;}
> public double getRate12() {return memory.Rate12;}
> public void   setRate12(double value) {memory.Rate12 = value;}
> public double getSAVEPER() {return memory.SAVEPER;}
> public void   setSAVEPER(double value) {memory.SAVEPER = value;}
> public double getStock1() {return memory.Stock1;}
> public void   setStock1(double value) {memory.Stock1 = value;}
> public double getStock2() {return memory.Stock2;}
> public void   setStock2(double value) {memory.Stock2 = value;}
> public double getStockNewCBDe() {return memory.StockNewCBDe;}
> public void   setStockNewCBDe(double value) {memory.StockNewCBDe = value;}
> public double getStockPotentialCBDe() {return memory.StockPotentialCBDe;}
> public void   setStockPotentialCBDe(double value) {memory.StockPotentialCBDe = value;}
> public double getTIME_STEP() {return memory.TIME_STEP;}
> public void   setTIME_STEP(double value) {memory.TIME_STEP = value;}
> public double getTime() {return memory.Time;}
> public void   setTime(double value) {memory.Time = value;}
> protected void updateTimeSeriesReferences(double time) {
>
> }
>
> }
>
>
>
> ------------------------------------------------------------------------------
> 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
Loading...