Sink file does not write result!

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Sink file does not write result!

Yared Abayneh
Dear RS team,

I collected a set of non-aggregated data using the 'Data Set Editor' and tried to write them in a file sink. Printing the 'get method' data sources used in the data collection in the console showed correct results. However, the sink file only writes the headers but not the results. What might be the reason for that?
 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education


------------------------------------------------------------------------------
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
|

Sink file does not write result!

Yared Abayneh



Dear RS team,

I collected a set of non-aggregated data using the 'Data Set Editor' and tried to write them in a file sink. Printing the 'get method' data sources used in the data collection in the console showed correct results. However, the sink file only writes the headers but not the results. What might be the reason for that?
 
Cheers,

Yared
-----------------------------------------------------------------

Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education




------------------------------------------------------------------------------
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
|

Sink file does not write non-aggregate data sets, but writes the header!

Yared Abayneh
In reply to this post by Yared Abayneh
Dear all,

I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?

This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!
 
Public class Household {
    private int householdSize;
    private int income;

    public Household (int householdSize, int income) {
        this.householdSize = householdSize;
        this.income = income;
    }
   
    //get and set methods for householdSize and income
}

// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.

Public class MainMethod {
    public static void mainMethod () {
        for each household {
            double random = RandomHelper.nextIntFromTo(1000, 10000);
            household.setIncome(random);
        }
    }
}

Public class CountMethod {
private static int count1;
private static int count2;
    public static void countMethod () {
        count1 = 0;
        count2 = 0;
        for each household {
            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {
                count1++;
            }
            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {
                count2++;
            }
        }
        // printing count1 and count2 on screen
        System.out.println(count1, count2)
    }
    // get and set methods for count1 and count2
    public static in getCount1() {
        return count1;
    }
    public static in getCount2() {
        return count2;
    }
}

In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:
  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type
  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.
In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink
  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education


------------------------------------------------------------------------------
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
|

Re: Sink file does not write non-aggregate data sets, but writes the header!

srcnick
I think the issue is that there are no “CountMethod” objects in the context. The data set looks for data sources in the context and then calls the appriopriate method. That said, I think there’s a better way to do what you want. Conceptually you are creating an aggregate data source in that you are iterating over multiple agents in the model. A non-aggregate would record data for each agent. What you want is to create custom AggregateDataSources. To do that you need to write two classes that implements AggregateDataSource. You’ll have one that counts household.getHouseholdSize() > 3 && household.getIncome() >= 5000)  and one that counts household.getHouseholdSize() = 2 && household.getIncome() >= 7000

You need to implement the methods in DataSource:


and in AggregateDataSource (which extends DataSource).



Hopefully these are self-explanatory with the javadoc, but the important methods are:

  Class<?> getDataType();

This should return an Integer.class (i.e the count of households).

  


Class<?> getSourceType();

The should return Household.class as you are recording data from Households. 


 Object get(Iterable<?> objs, int size);


The data recording mechanism will pass an iterable of Households here. So you can iterate through them in the same way you do in CountMethod.countMethod. 

You can add these two classes in the Custom Data Source panel of the Data Set wizard. Note that there is a way to get away with iterating over the households just once: create two protected static fields in a parent class of your AggregateDataSource implementations  initialized to -1 and if the get method  the value is -1 then do the count of both otherwise return the value. I think the reset method is called after all data sources have returned data so you could reset back to -1 there, but its worth checking if that is actually the case.

Nick


On May 19, 2017, at 6:39 AM, Yared Abayneh Abebe <[hidden email]> wrote:

Dear all,

I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?

This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!
 
Public class Household {
    private int householdSize;
    private int income;

    public Household (int householdSize, int income) {
        this.householdSize = householdSize;
        this.income = income;
    }
   
    //get and set methods for householdSize and income
}

// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.

Public class MainMethod {
    public static void mainMethod () {
        for each household {
            double random = RandomHelper.nextIntFromTo(1000, 10000);
            household.setIncome(random);
        }
    }
}

Public class CountMethod {
private static int count1;
private static int count2;
    public static void countMethod () {
        count1 = 0;
        count2 = 0;
        for each household {
            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {
                count1++;
            }
            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {
                count2++;
            }
        }
        // printing count1 and count2 on screen
        System.out.println(count1, count2)
    }
    // get and set methods for count1 and count2
    public static in getCount1() {
        return count1;
    }
    public static in getCount2() {
        return count2;
    }
}

In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:
  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type
  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.
In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink
  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education

------------------------------------------------------------------------------
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
|

Re: Sink file does not write non-aggregate data sets, but writes the header!

Yared Abayneh
Hi Nick,

Thank you for the help. I, now, managed to get the outputs of my model simulations in the file sink as I want. By the way, if anyone is looking for something similar, I just found out that the "Cell" model in the Repast Simphony model examples implements the custom AggregateDataSource interface and can be used as a reference.

On a related topic, one can view a table of all agents in a simulation (per tick) from the runtime environment. Is there a simple way to save the table or the data from the runtime environment? Or do I need to write a code to replicate outputs like what the tables shows?
 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education



On Monday, May 22, 2017 4:20 PM, Nick Collier <[hidden email]> wrote:


I think the issue is that there are no “CountMethod” objects in the context. The data set looks for data sources in the context and then calls the appriopriate method. That said, I think there’s a better way to do what you want. Conceptually you are creating an aggregate data source in that you are iterating over multiple agents in the model. A non-aggregate would record data for each agent. What you want is to create custom AggregateDataSources. To do that you need to write two classes that implements AggregateDataSource. You’ll have one that counts household.getHouseholdSize() > 3 && household.getIncome() >= 5000)  and one that counts household.getHouseholdSize() = 2 && household.getIncome() >= 7000

You need to implement the methods in DataSource:


and in AggregateDataSource (which extends DataSource).



Hopefully these are self-explanatory with the javadoc, but the important methods are:

  Class<?> getDataType();

This should return an Integer.class (i.e the count of households).
  

Class<?> getSourceType();

The should return Household.class as you are recording data from Households. 


 Object get(Iterable<?> objs, int size);


The data recording mechanism will pass an iterable of Households here. So you can iterate through them in the same way you do in CountMethod.countMethod. 

You can add these two classes in the Custom Data Source panel of the Data Set wizard. Note that there is a way to get away with iterating over the households just once: create two protected static fields in a parent class of your AggregateDataSource implementations  initialized to -1 and if the get method  the value is -1 then do the count of both otherwise return the value. I think the reset method is called after all data sources have returned data so you could reset back to -1 there, but its worth checking if that is actually the case.

Nick


On May 19, 2017, at 6:39 AM, Yared Abayneh Abebe <[hidden email]> wrote:

Dear all,

I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?

This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!
 
Public class Household {
    private int householdSize;
    private int income;

    public Household (int householdSize, int income) {
        this.householdSize = householdSize;
        this.income = income;
    }
   
    //get and set methods for householdSize and income
}

// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.

Public class MainMethod {
    public static void mainMethod () {
        for each household {
            double random = RandomHelper.nextIntFromTo(1000, 10000);
            household.setIncome(random);
        }
    }
}

Public class CountMethod {
private static int count1;
private static int count2;
    public static void countMethod () {
        count1 = 0;
        count2 = 0;
        for each household {
            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {
                count1++;
            }
            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {
                count2++;
            }
        }
        // printing count1 and count2 on screen
        System.out.println(count1, count2)
    }
    // get and set methods for count1 and count2
    public static in getCount1() {
        return count1;
    }
    public static in getCount2() {
        return count2;
    }
}

In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:
  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type
  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.
In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink
  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education

------------------------------------------------------------------------------
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
|

Re: Sink file does not write non-aggregate data sets, but writes the header!

Tatara, Eric R.

In the agent table toolbar there is a disk icon that will save the table to an Excel file.  It is also possible to programmatically generate a table and save it to file using the following example code:

 

public void log(){

              double tick = RunEnvironment.getInstance().getCurrentSchedule().getTickCount();

              Context context = RunState.getInstance().getMasterContext();

 

              Map<String,TableModel> models = new HashMap<String,TableModel>();

 

              // Create a tab panel for each agent layer

              for (Object agentType : context.getAgentTypes()){

                     Class agentClass = (Class)agentType;

 

                     JPanel agentPanel = AgentTableFactory.createAgentTablePanel(

                                  context.getAgentLayer(agentClass), agentClass.getSimpleName());

 

                     if (agentPanel instanceof TablePanel){

                           TableModel model = ((TablePanel)agentPanel).getTable().getModel();

                           models.put(agentClass.getSimpleName(), model);

 

                     }

              }

      

              SpreadsheetUtils.saveTablesAsExcel(models, new File("out-"+tick+".xlsx"));

       }

 

Note however this would be extremely inefficient if called frequently so I would not recommend using this to log every tick.

 

eric

 

From: Yared Abayneh Abebe [mailto:[hidden email]]
Sent: Tuesday, May 23, 2017 7:53 AM
To: Nick Collier <[hidden email]>
Cc: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Sink file does not write non-aggregate data sets, but writes the header!

 

Hi Nick,



Thank you for the help. I, now, managed to get the outputs of my model simulations in the file sink as I want. By the way, if anyone is looking for something similar, I just found out that the "Cell" model in the Repast Simphony model examples implements the custom AggregateDataSource interface and can be used as a reference.



On a related topic, one can view a table of all agents in a simulation (per tick) from the runtime environment. Is there a simple way to save the table or the data from the runtime environment? Or do I need to write a code to replicate outputs like what the tables shows?

 

Cheers,

Yared
-----------------------------------------------------------------

Yared Abayneh Abebe, MSc

PhD Research Fellow in Urban Water Systems

Environmental Engineering and Water Technology Department

IHE Delft Institute for Water Education

 

 

On Monday, May 22, 2017 4:20 PM, Nick Collier <[hidden email]> wrote:

 

I think the issue is that there are no “CountMethod” objects in the context. The data set looks for data sources in the context and then calls the appriopriate method. That said, I think there’s a better way to do what you want. Conceptually you are creating an aggregate data source in that you are iterating over multiple agents in the model. A non-aggregate would record data for each agent. What you want is to create custom AggregateDataSources. To do that you need to write two classes that implements AggregateDataSource. You’ll have one that counts household.getHouseholdSize() > 3 && household.getIncome() >= 5000)  and one that counts household.getHouseholdSize() = 2 && household.getIncome() >= 7000

 

You need to implement the methods in DataSource:

 

 

and in AggregateDataSource (which extends DataSource).

 

 

 

Hopefully these are self-explanatory with the javadoc, but the important methods are:

 

  Class<?> getDataType();

 

This should return an Integer.class (i.e the count of households).

  

 

Class<?> getSourceType();

 

The should return Household.class as you are recording data from Households. 

 

 

 Object get(Iterable<?> objs, int size);

 

 

The data recording mechanism will pass an iterable of Households here. So you can iterate through them in the same way you do in CountMethod.countMethod. 

 

You can add these two classes in the Custom Data Source panel of the Data Set wizard. Note that there is a way to get away with iterating over the households just once: create two protected static fields in a parent class of your AggregateDataSource implementations  initialized to -1 and if the get method  the value is -1 then do the count of both otherwise return the value. I think the reset method is called after all data sources have returned data so you could reset back to -1 there, but its worth checking if that is actually the case.

 

Nick

 

 

On May 19, 2017, at 6:39 AM, Yared Abayneh Abebe <[hidden email]> wrote:

 

Dear all,



I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?



This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!

 

Public class Household {

    private int householdSize;

    private int income;



    public Household (int householdSize, int income) {

        this.householdSize = householdSize;

        this.income = income;

    }

   

    //get and set methods for householdSize and income

}



// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.



Public class MainMethod {

    public static void mainMethod () {

        for each household {

            double random = RandomHelper.nextIntFromTo(1000, 10000);

            household.setIncome(random);

        }

    }

}

 

Public class CountMethod {

private static int count1;

private static int count2;

    public static void countMethod () {

        count1 = 0;

        count2 = 0;

        for each household {

            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {

                count1++;

            }

            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {

                count2++;

            }

        }

        // printing count1 and count2 on screen

        System.out.println(count1, count2)

    }

    // get and set methods for count1 and count2

    public static in getCount1() {

        return count1;

    }

    public static in getCount2() {

        return count2;

    }

}



In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:

  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type

  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.

In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink

  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

 

Cheers,


Yared
-----------------------------------------------------------------

Yared Abayneh Abebe, MSc

PhD Research Fellow in Urban Water Systems

Environmental Engineering and Water Technology Department

IHE Delft Institute for Water Education

 

------------------------------------------------------------------------------
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
|

Re: Sink file does not write non-aggregate data sets, but writes the header!

Yared Abayneh
Eric,

Thank you very much. That was exactly what I was looking for. I would like to also confirm that calling the method every tick slows down the simulation.
 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education



On Tuesday, May 23, 2017 8:13 PM, "Tatara, Eric R." <[hidden email]> wrote:


In the agent table toolbar there is a disk icon that will save the table to an Excel file.  It is also possible to programmatically generate a table and save it to file using the following example code:
 
public void log(){
              double tick = RunEnvironment.getInstance().getCurrentSchedule().getTickCount();
              Context context = RunState.getInstance().getMasterContext();
 
              Map<String,TableModel> models = new HashMap<String,TableModel>();
 
              // Create a tab panel for each agent layer
              for (Object agentType : context.getAgentTypes()){
                     Class agentClass = (Class)agentType;
 
                     JPanel agentPanel = AgentTableFactory.createAgentTablePanel(
                                  context.getAgentLayer(agentClass), agentClass.getSimpleName());
 
                     if (agentPanel instanceof TablePanel){
                           TableModel model = ((TablePanel)agentPanel).getTable().getModel();
                           models.put(agentClass.getSimpleName(), model);
 
                     }
              }
      
              SpreadsheetUtils.saveTablesAsExcel(models, new File("out-"+tick+".xlsx"));
       }
 
Note however this would be extremely inefficient if called frequently so I would not recommend using this to log every tick.
 
eric
 
From: Yared Abayneh Abebe [mailto:[hidden email]]
Sent: Tuesday, May 23, 2017 7:53 AM
To: Nick Collier <[hidden email]>
Cc: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Sink file does not write non-aggregate data sets, but writes the header!
 
Hi Nick,


Thank you for the help. I, now, managed to get the outputs of my model simulations in the file sink as I want. By the way, if anyone is looking for something similar, I just found out that the "Cell" model in the Repast Simphony model examples implements the custom AggregateDataSource interface and can be used as a reference.


On a related topic, one can view a table of all agents in a simulation (per tick) from the runtime environment. Is there a simple way to save the table or the data from the runtime environment? Or do I need to write a code to replicate outputs like what the tables shows?
 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education
 
 
On Monday, May 22, 2017 4:20 PM, Nick Collier <[hidden email]> wrote:
 
I think the issue is that there are no “CountMethod” objects in the context. The data set looks for data sources in the context and then calls the appriopriate method. That said, I think there’s a better way to do what you want. Conceptually you are creating an aggregate data source in that you are iterating over multiple agents in the model. A non-aggregate would record data for each agent. What you want is to create custom AggregateDataSources. To do that you need to write two classes that implements AggregateDataSource. You’ll have one that counts household.getHouseholdSize() > 3 && household.getIncome() >= 5000)  and one that counts household.getHouseholdSize() = 2 && household.getIncome() >= 7000
 
You need to implement the methods in DataSource:
 
 
and in AggregateDataSource (which extends DataSource).
 
 
 
Hopefully these are self-explanatory with the javadoc, but the important methods are:
 
  Class<?> getDataType();
 
This should return an Integer.class (i.e the count of households).
  
 
Class<?> getSourceType();
 
The should return Household.class as you are recording data from Households. 
 
 
 Object get(Iterable<?> objs, int size);
 
 
The data recording mechanism will pass an iterable of Households here. So you can iterate through them in the same way you do in CountMethod.countMethod. 
 
You can add these two classes in the Custom Data Source panel of the Data Set wizard. Note that there is a way to get away with iterating over the households just once: create two protected static fields in a parent class of your AggregateDataSource implementations  initialized to -1 and if the get method  the value is -1 then do the count of both otherwise return the value. I think the reset method is called after all data sources have returned data so you could reset back to -1 there, but its worth checking if that is actually the case.
 
Nick
 
 
On May 19, 2017, at 6:39 AM, Yared Abayneh Abebe <[hidden email]> wrote:
 
Dear all,


I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?



This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!

 
Public class Household {
    private int householdSize;
    private int income;



    public Household (int householdSize, int income) {
        this.householdSize = householdSize;
        this.income = income;

    }

   

    //get and set methods for householdSize and income

}



// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.



Public class MainMethod {
    public static void mainMethod () {
        for each household {
            double random = RandomHelper.nextIntFromTo(1000, 10000);
            household.setIncome(random);

        }

    }

}

 
Public class CountMethod {
private static int count1;
private static int count2;
    public static void countMethod () {
        count1 = 0;
        count2 = 0;

        for each household {
            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {

                count1++;
            }

            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {

                count2++;
            }

        }

        // printing count1 and count2 on screen

        System.out.println(count1, count2)

    }
    // get and set methods for count1 and count2

    public static in getCount1() {
        return count1;

    }

    public static in getCount2() {
        return count2;

    }

}


In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:
  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type

  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.

In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink
  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education
 
------------------------------------------------------------------------------
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
|

Re: Sink file does not write non-aggregate data sets, but writes the header!

Yared Abebe
In reply to this post by Tatara, Eric R.
Eric,

I implemented the example code you wrote (with some modifications) and it was working well when I run individual simulations. However, when I run batch simulations, it is failing (error log below). Why the batch execute could not find the AgentTableFactory class? 


BatchSchedule.execute: error when running the schedule
Current tick (0.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
 at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
 at repast.simphony.engine.controller.ScheduledMethodControllerAction$StaticMethodAction.execute(ScheduledMethodControllerAction.java:247)
 at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
 at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
 at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
 at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
 at repast.simphony.batch.BatchScheduleRunner$ScheduleLoopRunnable.run(BatchScheduleRunner.java:37)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
 at mainRun.GlobalVariables$$FastClassByCGLIB$$36621c9d.invoke(<generated>)
 at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
 at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
 ... 7 more
Caused by: java.lang.NoClassDefFoundError: repast/simphony/ui/table/AgentTableFactory
 at mainRun.GlobalVariables.log(GlobalVariables.java:56)
 ... 10 more
Caused by: java.lang.ClassNotFoundException: repast.simphony.ui.table.AgentTableFactory
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 ... 11 more


Cheers,
Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education




In the agent table toolbar there is a disk icon that will save the table to an Excel file.  It is also possible to programmatically generate a table and save it to file using the following example code:
 
public void log(){
              double tick = RunEnvironment.getInstance().getCurrentSchedule().getTickCount();
              Context context = RunState.getInstance().getMasterContext();
 
              Map<String,TableModel> models = new HashMap<String,TableModel>();
 
              // Create a tab panel for each agent layer
              for (Object agentType : context.getAgentTypes()){
                     Class agentClass = (Class)agentType;
 
                     JPanel agentPanel = AgentTableFactory.createAgentTablePanel(
                                  context.getAgentLayer(agentClass), agentClass.getSimpleName());
 
                     if (agentPanel instanceof TablePanel){
                           TableModel model = ((TablePanel)agentPanel).getTable().getModel();
                           models.put(agentClass.getSimpleName(), model);
 
                     }
              }
      
              SpreadsheetUtils.saveTablesAsExcel(models, new File("out-"+tick+".xlsx"));
       }
 
Note however this would be extremely inefficient if called frequently so I would not recommend using this to log every tick.
 
eric
 
From: Yared Abayneh Abebe [[hidden email]]
Sent: Tuesday, May 23, 2017 7:53 AM
To: Nick Collier <[hidden email]>
Cc: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Sink file does not write non-aggregate data sets, but writes the header!
 
Hi Nick,


Thank you for the help. I, now, managed to get the outputs of my model simulations in the file sink as I want. By the way, if anyone is looking for something similar, I just found out that the "Cell" model in the Repast Simphony model examples implements the custom AggregateDataSource interface and can be used as a reference.


On a related topic, one can view a table of all agents in a simulation (per tick) from the runtime environment. Is there a simple way to save the table or the data from the runtime environment? Or do I need to write a code to replicate outputs like what the tables shows?
 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education
 
 
On Monday, May 22, 2017 4:20 PM, Nick Collier <[hidden email]> wrote:
 
I think the issue is that there are no “CountMethod” objects in the context. The data set looks for data sources in the context and then calls the appriopriate method. That said, I think there’s a better way to do what you want. Conceptually you are creating an aggregate data source in that you are iterating over multiple agents in the model. A non-aggregate would record data for each agent. What you want is to create custom AggregateDataSources. To do that you need to write two classes that implements AggregateDataSource. You’ll have one that counts household.getHouseholdSize() > 3 && household.getIncome() >= 5000)  and one that counts household.getHouseholdSize() = 2 && household.getIncome() >= 7000
 
You need to implement the methods in DataSource:
 
 
and in AggregateDataSource (which extends DataSource).
 
 
 
Hopefully these are self-explanatory with the javadoc, but the important methods are:
 
  Class<?> getDataType();
 
This should return an Integer.class (i.e the count of households).
  
 
Class<?> getSourceType();
 
The should return Household.class as you are recording data from Households. 
 
 
 Object get(Iterable<?> objs, int size);
 
 
The data recording mechanism will pass an iterable of Households here. So you can iterate through them in the same way you do in CountMethod.countMethod. 
 
You can add these two classes in the Custom Data Source panel of the Data Set wizard. Note that there is a way to get away with iterating over the households just once: create two protected static fields in a parent class of your AggregateDataSource implementations  initialized to -1 and if the get method  the value is -1 then do the count of both otherwise return the value. I think the reset method is called after all data sources have returned data so you could reset back to -1 there, but its worth checking if that is actually the case.
 
Nick
 
 
On May 19, 2017, at 6:39 AM, Yared Abayneh Abebe <[hidden email]> wrote:
 
Dear all,


I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?



This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!

 
Public class Household {
    private int householdSize;
    private int income;



    public Household (int householdSize, int income) {
        this.householdSize = householdSize;
        this.income = income;

    }

   

    //get and set methods for householdSize and income

}



// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.



Public class MainMethod {
    public static void mainMethod () {
        for each household {
            double random = RandomHelper.nextIntFromTo(1000, 10000);
            household.setIncome(random);

        }

    }

}

 
Public class CountMethod {
private static int count1;
private static int count2;
    public static void countMethod () {
        count1 = 0;
        count2 = 0;

        for each household {
            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {

                count1++;
            }

            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {

                count2++;
            }

        }

        // printing count1 and count2 on screen

        System.out.println(count1, count2)

    }
    // get and set methods for count1 and count2

    public static in getCount1() {
        return count1;

    }

    public static in getCount2() {
        return count2;

    }

}


In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:
  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type

  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.

In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink
  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education
 
------------------------------------------------------------------------------
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
|

Re: Sink file does not write non-aggregate data sets, but writes the header!

srcnick
We don’t include any GUI related libraries when we do headless batch runs and the AgentTable code falls under that category. There can be issues with code that creates Swing components (like a JTable) when running headless, but you can try the following and see if it works.

To include the the GUI classes in the archive jar, you’ll have to edit the build.xml file that we use to create the model archive jar. That build.xml file is in

X/Eclipse/plugins/repast.simphony.distributed.batch_2.4.0/bin/scripts/build.xml

where X is wherever you’ve installed simphony. This assumes version 2.4.0. Add this line around line 56:

<property name="gui" location="${plugins.prefix}/repast.simphony.gui${plugins.suffix}" />

and this around line 144

<jar destfile="${working.lib}/repast.simphony.gui.jar" basedir="${gui}/bin" />

and this around line 155

<fileset dir="${gui}/lib">
<include name="*.jar" />
</fileset>


If you run the batch GUI again to create the archive jar, it should now include the GUI jars. Note that there is another build.xml at:

X/Eclipse/plugins/repast.simphony.distributed.batch_2.4.0/scripts/build.xml

not in bin/scripts. I think the one in bin is the one that is used, but if that doesn’t work try editing that build.xml

Nick

On May 31, 2017, at 12:28 PM, Yared Abebe <[hidden email]> wrote:

Eric,

I implemented the example code you wrote (with some modifications) and it was working well when I run individual simulations. However, when I run batch simulations, it is failing (error log below). Why the batch execute could not find the AgentTableFactory class? 


BatchSchedule.execute: error when running the schedule
Current tick (0.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
 at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
 at repast.simphony.engine.controller.ScheduledMethodControllerAction$StaticMethodAction.execute(ScheduledMethodControllerAction.java:247)
 at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
 at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
 at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
 at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
 at repast.simphony.batch.BatchScheduleRunner$ScheduleLoopRunnable.run(BatchScheduleRunner.java:37)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
 at mainRun.GlobalVariables$$FastClassByCGLIB$$36621c9d.invoke(<generated>)
 at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
 at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
 ... 7 more
Caused by: java.lang.NoClassDefFoundError: repast/simphony/ui/table/AgentTableFactory
 at mainRun.GlobalVariables.log(GlobalVariables.java:56)
 ... 10 more
Caused by: java.lang.ClassNotFoundException: repast.simphony.ui.table.AgentTableFactory
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 ... 11 more


Cheers,
Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education




In the agent table toolbar there is a disk icon that will save the table to an Excel file.  It is also possible to programmatically generate a table and save it to file using the following example code:
 
public void log(){
              double tick = RunEnvironment.getInstance().getCurrentSchedule().getTickCount();
              Context context = RunState.getInstance().getMasterContext();
 
              Map<String,TableModel> models = new HashMap<String,TableModel>();
 
              // Create a tab panel for each agent layer
              for (Object agentType : context.getAgentTypes()){
                     Class agentClass = (Class)agentType;
 
                     JPanel agentPanel = AgentTableFactory.createAgentTablePanel(
                                  context.getAgentLayer(agentClass), agentClass.getSimpleName());
 
                     if (agentPanel instanceof TablePanel){
                           TableModel model = ((TablePanel)agentPanel).getTable().getModel();
                           models.put(agentClass.getSimpleName(), model);
 
                     }
              }
      
              SpreadsheetUtils.saveTablesAsExcel(models, new File("out-"+tick+".xlsx"));
       }
 
Note however this would be extremely inefficient if called frequently so I would not recommend using this to log every tick.
 
eric
 
From: Yared Abayneh Abebe [[hidden email]]
Sent: Tuesday, May 23, 2017 7:53 AM
To: Nick Collier <[hidden email]>
Cc: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Sink file does not write non-aggregate data sets, but writes the header!
 
Hi Nick,


Thank you for the help. I, now, managed to get the outputs of my model simulations in the file sink as I want. By the way, if anyone is looking for something similar, I just found out that the "Cell" model in the Repast Simphony model examples implements the custom AggregateDataSource interface and can be used as a reference.


On a related topic, one can view a table of all agents in a simulation (per tick) from the runtime environment. Is there a simple way to save the table or the data from the runtime environment? Or do I need to write a code to replicate outputs like what the tables shows?
 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education
 
 
On Monday, May 22, 2017 4:20 PM, Nick Collier <[hidden email]> wrote:
 
I think the issue is that there are no “CountMethod” objects in the context. The data set looks for data sources in the context and then calls the appriopriate method. That said, I think there’s a better way to do what you want. Conceptually you are creating an aggregate data source in that you are iterating over multiple agents in the model. A non-aggregate would record data for each agent. What you want is to create custom AggregateDataSources. To do that you need to write two classes that implements AggregateDataSource. You’ll have one that counts household.getHouseholdSize() > 3 && household.getIncome() >= 5000)  and one that counts household.getHouseholdSize() = 2 && household.getIncome() >= 7000
 
You need to implement the methods in DataSource:
 
 
and in AggregateDataSource (which extends DataSource).
 
 
 
Hopefully these are self-explanatory with the javadoc, but the important methods are:
 
  Class<?> getDataType();
 
This should return an Integer.class (i.e the count of households).
  
 
Class<?> getSourceType();
 
The should return Household.class as you are recording data from Households. 
 
 
 Object get(Iterable<?> objs, int size);
 
 
The data recording mechanism will pass an iterable of Households here. So you can iterate through them in the same way you do in CountMethod.countMethod. 
 
You can add these two classes in the Custom Data Source panel of the Data Set wizard. Note that there is a way to get away with iterating over the households just once: create two protected static fields in a parent class of your AggregateDataSource implementations  initialized to -1 and if the get method  the value is -1 then do the count of both otherwise return the value. I think the reset method is called after all data sources have returned data so you could reset back to -1 there, but its worth checking if that is actually the case.
 
Nick
 
 
On May 19, 2017, at 6:39 AM, Yared Abayneh Abebe <[hidden email]> wrote:
 
Dear all,


I collected a set of non-aggregate data using the 'Data Set Editor' and tried to write them in a file sink. But, the sink file does not produce what I wanted! Apparently, writing aggregate data in a file sink in RS is well explained in the "Repast Java getting started.pdf" file and hence, it is straight forward. However, in my case, I need to write non-aggregate data sets since I want to count agents if a combination of two or more attributes satisfy certain evaluation criteria. Therefore, I created a class with multiple static variables to produce the results I need (see an example below. My apologies for over simplified and not reproducible example. The exact code I have is very big with more classes and posting all that is not relevant here. However, the example represent the issue well). I also wrote get-methods for those static variables (count1 and count2 in the example below). Then I added non-aggregate data set in the RS runtime environment and created a file sink for that data set. Now, the issue is that the file sink is created and it writes the headers (tick, count1, count2) but it does not write the values of three items. What would be the problem?



This issue is setting my work back as I'm running supposed-to-be batch simulations one by one by writing the outputs in a file from the class (CountMethod class). Any help is appreciated!

 
Public class Household {
    private int householdSize;
    private int income;



    public Household (int householdSize, int income) {
        this.householdSize = householdSize;
        this.income = income;

    }

   

    //get and set methods for householdSize and income

}



// create 50 households in the ContextBuilder.java class and set their householdSize. Their income is initialized as zero.



Public class MainMethod {
    public static void mainMethod () {
        for each household {
            double random = RandomHelper.nextIntFromTo(1000, 10000);
            household.setIncome(random);

        }

    }

}

 
Public class CountMethod {
private static int count1;
private static int count2;
    public static void countMethod () {
        count1 = 0;
        count2 = 0;

        for each household {
            if (household.getHouseholdSize() > 3 && household.getIncome() >= 5000) {

                count1++;
            }

            if (household.getHouseholdSize() = 2 && household.getIncome() >= 7000) {

                count2++;
            }

        }

        // printing count1 and count2 on screen

        System.out.println(count1, count2)

    }
    // get and set methods for count1 and count2

    public static in getCount1() {
        return count1;

    }

    public static in getCount2() {
        return count2;

    }

}


In the RS runtime environment Scenario Tree -> Data Sets -> Add Data Set:
  • Data Set Editor -> General Settings -> set NonAggregate Data Set as Data Set Id and Non-Aggregate as Data Set Type

  • Data Set Editor -> Select Data Sources -> Method Data Sources tab -> select CountMethod as Source Class -> add two rows with count1 and count2 as Data Source Name and getCount1 and getCount2 as Method respectively. The Standard Sources and Custom Data Sources were set as default.

In the RS runtime environment Scenario Tree -> Text Sinks -> Add File Sink
  • File Sink Editor -> File Data Properties -> set NonAggregate File Sink as Name -> select NonAggregate Data Set as Data Set ID -> select and move tick, count1 and count2 to the second column
  • File Sink Editor -> Configure File Properties -> leave as default

 
Cheers,

Yared
-----------------------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
IHE Delft Institute for Water Education
 
------------------------------------------------------------------------------
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