Best tutorials or demo models for displaying subcontexts?

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

Best tutorials or demo models for displaying subcontexts?

Willy Ray-2
I have a hospital model with many floors.  Each floor has many rooms.  These are all extending DefaulContext and are added to each other as subcontexts.

These floors and rooms don't have actual spatial relationships... they're only related via their hierarchy.   What I'd like to do is visualize them with a bunch of tiled, nested rectangles... each color coded for different kinds of status.  

So, I'm guessing I'm going to loop through the contexts, adding them to a grid projection?  but I'm still not sure how to set up the visualization.  Is there a suggestion for the best tutorial or demo model that I could look at to get an idea of how to do something like this?

Thanks,

Willy

------------------------------------------------------------------------------
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: Best tutorials or demo models for displaying subcontexts?

srcnick
 There’s no way to visualize the contexts per se — you’d be visualizing the agents within them. You could perhaps have a “display agent” in each one that you style as rectangle in a continous space. You might also be able to create a similar effect using value layers. See:


And see this about 1/2 way down:


Unfortunately, we don’t have any good examples in the demo models for displaying contexts themselves,

Nick



On Jun 14, 2017, at 6:10 PM, Willy Ray <[hidden email]> wrote:

I have a hospital model with many floors.  Each floor has many rooms.  These are all extending DefaulContext and are added to each other as subcontexts.

These floors and rooms don't have actual spatial relationships... they're only related via their hierarchy.   What I'd like to do is visualize them with a bunch of tiled, nested rectangles... each color coded for different kinds of status.  

So, I'm guessing I'm going to loop through the contexts, adding them to a grid projection?  but I'm still not sure how to set up the visualization.  Is there a suggestion for the best tutorial or demo model that I could look at to get an idea of how to do something like this?

Thanks,

Willy
------------------------------------------------------------------------------
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: Best tutorials or demo models for displaying subcontexts?

Willy Ray-2
I'll take a close look at those two links.  I'll need to visualize empty rooms (extending DefaultContext, and added via addSubContext)... no agents inside, just objects with decaying levels of contamination.  I wonder if there's some way to get a canvas and draw programmatically?  

On Thu, Jun 15, 2017 at 1:32 PM, Nick Collier <[hidden email]> wrote:
 There’s no way to visualize the contexts per se — you’d be visualizing the agents within them. You could perhaps have a “display agent” in each one that you style as rectangle in a continous space. You might also be able to create a similar effect using value layers. See:


And see this about 1/2 way down:


Unfortunately, we don’t have any good examples in the demo models for displaying contexts themselves,

Nick



On Jun 14, 2017, at 6:10 PM, Willy Ray <[hidden email]> wrote:

I have a hospital model with many floors.  Each floor has many rooms.  These are all extending DefaulContext and are added to each other as subcontexts.

These floors and rooms don't have actual spatial relationships... they're only related via their hierarchy.   What I'd like to do is visualize them with a bunch of tiled, nested rectangles... each color coded for different kinds of status.  

So, I'm guessing I'm going to loop through the contexts, adding them to a grid projection?  but I'm still not sure how to set up the visualization.  Is there a suggestion for the best tutorial or demo model that I could look at to get an idea of how to do something like this?

Thanks,

Willy
------------------------------------------------------------------------------
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: Best tutorials or demo models for displaying subcontexts?

Tatara, Eric R.

The two options I would suggest are 1) use separate surrogate non-context objects for display only that reflect your room properties or 2) don’t use sub-contexts for this type of model.  Most of what you need in regards to collecting agents in contexts could be achieved using standard Java collections like lists or maps and you would avoid this issues of displaying nested contexts.   I created a simple model below that shows how to display nested sub-contexts.  The only issue with this approach is that the display probe doesn’t work on contexts, but all of the normal styling does work.  This example shows how a 2D display could work.  Two floors are visualized in one 2D display.  You could change this by explicitly defining the Floor contexts in the context.xml and then create a separate display for each floor.  You could also use a 3D display and build a full 3D volume representation of the floors and rooms but I suspect that would look too crowded.

 

<context id="Subcontexts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://repast.org/scenario/context">

     

      <context id="Hospital">

            <projection type="grid" id="grid"/>

      </context>

</context>

 

package subcontexts;

 

import repast.simphony.context.Context;

import repast.simphony.context.space.grid.GridFactory;

import repast.simphony.context.space.grid.GridFactoryFinder;

import repast.simphony.dataLoader.ContextBuilder;

import repast.simphony.space.grid.Grid;

import repast.simphony.space.grid.GridBuilderParameters;

import repast.simphony.space.grid.SimpleGridAdder;

import repast.simphony.space.grid.WrapAroundBorders;

 

public class ConBuilder implements ContextBuilder<Object> {

 

      @Override

      public Context build(Context<Object> context) {

 

            Hospital hospital = new Hospital("Hospital");

            context.addSubContext(hospital);

            context.add(hospital);

           

            GridFactory gridFactory = GridFactoryFinder.createGridFactory(null);

            Grid<Object> grid = gridFactory.createGrid("grid", hospital,

                        new GridBuilderParameters<Object>(new WrapAroundBorders(),

                                    new SimpleGridAdder<Object>(), true, 50, 50));

           

            Floor floor1 = new Floor("Floor 1");

            Floor floor2 = new Floor("Floor 2");

           

            hospital.addSubContext(floor1);

            hospital.addSubContext(floor2);

            hospital.add(floor1);

            hospital.add(floor2);

           

            grid.moveTo(floor1, 10, 25);

            grid.moveTo(floor2, 30, 25);

           

            Room room1 = new Room("Room 1");

            Room room2 = new Room("Room 2");

            Room room3 = new Room("Room 3");

            Room room4 = new Room("Room 4");

            Room room5 = new Room("Room 5");

           

            floor1.addSubContext(room1);

            floor1.addSubContext(room2);

            floor1.addSubContext(room3);

           

            hospital.add(room1);

            hospital.add(room2);

            hospital.add(room3);

            grid.moveTo(room1, 10, 25);

            grid.moveTo(room2, 15, 25);

            grid.moveTo(room3, 20, 30);

           

            floor2.addSubContext(room4);

            floor2.addSubContext(room5);

            floor2.add(room4);

            floor2.add(room5);

           

            return context;

      }

     

}

 

package subcontexts;

 

import repast.simphony.context.DefaultContext;

 

public class Hospital extends DefaultContext {

 

      public Hospital(String name){

            super(name,name);

      }

}

 

 

 

package subcontexts;

 

import repast.simphony.context.DefaultContext;

 

public class Floor extends DefaultContext {

 

      public Floor (String name){

            super(name,name);

      }

     

}

 

package subcontexts;

 

import repast.simphony.context.DefaultContext;

import repast.simphony.engine.schedule.ScheduledMethod;

import repast.simphony.random.RandomHelper;

 

public class Room extends DefaultContext {

 

                private double contamination = 100 * RandomHelper.nextDouble();

               

                public Room(String name){

                                super(name,"Room");

                }

               

                @ScheduledMethod(start=1, interval=1)

                public void step(){

                               

                                if (contamination > 0){

                                                contamination -= 1;

                                }

                               

                                if (contamination < 0){

                                                contamination = 0;

                                }

                }

 

                public double getContamination() {

                                return contamination;

                }

 

                public void setContamination(double contamination) {

                                this.contamination = contamination;

                }

               

               

}

 

package subcontexts;

 

import java.awt.Color;

import java.awt.Font;

 

import repast.simphony.visualizationOGL2D.StyleOGL2D;

import saf.v3d.ShapeFactory2D;

import saf.v3d.scene.Position;

import saf.v3d.scene.VSpatial;

 

public class FloorStyle implements StyleOGL2D<Floor> {

 

      protected ShapeFactory2D shapeFactory;

 

      public void init(ShapeFactory2D factory) {

            this.shapeFactory = factory;

      }

 

 

      public VSpatial getVSpatial(Floor agent, VSpatial spatial) {

            if (spatial == null) {

                  spatial = shapeFactory.createRectangle(250, 250);

            }

            return spatial;

      }

 

      public Color getColor(Floor agent) {

            return Color.lightGray;

      }

 

      public float getRotation(Floor agent) {

            return 0f;

      }

 

 

      public Color getBorderColor(Floor object) {

            return Color.BLACK;

      }

 

 

      public int getBorderSize(Floor object) {

            return 0;

      }

 

 

      public float getScale(Floor object) {

            return 1f;

      }

 

      public String getLabel(Floor object) {

            return null;

      }

 

      public Font getLabelFont(Floor object) {

            return null;

      }

 

 

      public Position getLabelPosition(Floor object) {

            return Position.NORTH;

      }

 

 

      public float getLabelXOffset(Floor object) {

            return 0;

      }

 

 

      public float getLabelYOffset(Floor object) {

            return 0;

      }

 

      public Color getLabelColor(Floor object) {

            return Color.BLACK;

      }

}

 

package subcontexts;

 

import java.awt.Color;

import java.awt.Font;

 

import repast.simphony.visualizationOGL2D.StyleOGL2D;

import saf.v3d.ShapeFactory2D;

import saf.v3d.scene.Position;

import saf.v3d.scene.VSpatial;

 

public class RoomStyle implements StyleOGL2D<Room> {

 

                protected ShapeFactory2D shapeFactory;

 

                public void init(ShapeFactory2D factory) {

                                this.shapeFactory = factory;

                }

 

 

                public VSpatial getVSpatial(Room agent, VSpatial spatial) {

                                if (spatial == null) {

                                                spatial = shapeFactory.createRectangle(50, 50);

                                }

                                return spatial;

                }

 

                public Color getColor(Room agent) {

                               

                                float c = (float)agent.getContamination() / 100.0f;

                               

                                return new Color(c, 0.5f, 0.5f);

                }

 

                public float getRotation(Room agent) {

                                return 0f;

                }

 

 

                public Color getBorderColor(Room object) {

                                return Color.BLACK;

                }

 

 

                public int getBorderSize(Room object) {

                                return 0;

                }

 

 

                public float getScale(Room object) {

                                return 1f;

                }

 

                public String getLabel(Room object) {

                                return null;

                }

 

                public Font getLabelFont(Room object) {

                                return null;

                }

 

 

                public Position getLabelPosition(Room object) {

                                return Position.NORTH;

                }

 

 

                public float getLabelXOffset(Room object) {

                                return 0;

                }

 

 

                public float getLabelYOffset(Room object) {

                                return 0;

                }

 

                public Color getLabelColor(Room object) {

                                return Color.BLACK;

                }

}

 

 

 

From: Willy Ray [mailto:[hidden email]]
Sent: Thursday, June 15, 2017 7:59 PM
To: Nick Collier <[hidden email]>
Cc: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Best tutorials or demo models for displaying subcontexts?

 

I'll take a close look at those two links.  I'll need to visualize empty rooms (extending DefaultContext, and added via addSubContext)... no agents inside, just objects with decaying levels of contamination.  I wonder if there's some way to get a canvas and draw programmatically?  

 

On Thu, Jun 15, 2017 at 1:32 PM, Nick Collier <[hidden email]> wrote:

 There’s no way to visualize the contexts per se — you’d be visualizing the agents within them. You could perhaps have a “display agent” in each one that you style as rectangle in a continous space. You might also be able to create a similar effect using value layers. See:

 

 

And see this about 1/2 way down:

 

 

Unfortunately, we don’t have any good examples in the demo models for displaying contexts themselves,

 

Nick

 




On Jun 14, 2017, at 6:10 PM, Willy Ray <[hidden email]> wrote:

I have a hospital model with many floors.  Each floor has many rooms.  These are all extending DefaulContext and are added to each other as subcontexts.

These floors and rooms don't have actual spatial relationships... they're only related via their hierarchy.   What I'd like to do is visualize them with a bunch of tiled, nested rectangles... each color coded for different kinds of status.  

So, I'm guessing I'm going to loop through the contexts, adding them to a grid projection?  but I'm still not sure how to set up the visualization.  Is there a suggestion for the best tutorial or demo model that I could look at to get an idea of how to do something like this?

Thanks,

Willy

------------------------------------------------------------------------------
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: Best tutorials or demo models for displaying subcontexts?

Willy Ray-2
Thanks Eric, I'll take some time and see if I can comprehend this.

On Fri, Jun 16, 2017 at 9:18 AM, Tatara, Eric R. <[hidden email]> wrote:

The two options I would suggest are 1) use separate surrogate non-context objects for display only that reflect your room properties or 2) don’t use sub-contexts for this type of model.  Most of what you need in regards to collecting agents in contexts could be achieved using standard Java collections like lists or maps and you would avoid this issues of displaying nested contexts.   I created a simple model below that shows how to display nested sub-contexts.  The only issue with this approach is that the display probe doesn’t work on contexts, but all of the normal styling does work.  This example shows how a 2D display could work.  Two floors are visualized in one 2D display.  You could change this by explicitly defining the Floor contexts in the context.xml and then create a separate display for each floor.  You could also use a 3D display and build a full 3D volume representation of the floors and rooms but I suspect that would look too crowded.

 

<context id="Subcontexts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://repast.org/scenario/context">

     

      <context id="Hospital">

            <projection type="grid" id="grid"/>

      </context>

</context>

 

package subcontexts;

 

import repast.simphony.context.Context;

import repast.simphony.context.space.grid.GridFactory;

import repast.simphony.context.space.grid.GridFactoryFinder;

import repast.simphony.dataLoader.ContextBuilder;

import repast.simphony.space.grid.Grid;

import repast.simphony.space.grid.GridBuilderParameters;

import repast.simphony.space.grid.SimpleGridAdder;

import repast.simphony.space.grid.WrapAroundBorders;

 

public class ConBuilder implements ContextBuilder<Object> {

 

      @Override

      public Context build(Context<Object> context) {

 

            Hospital hospital = new Hospital("Hospital");

            context.addSubContext(hospital);

            context.add(hospital);

           

            GridFactory gridFactory = GridFactoryFinder.createGridFactory(null);

            Grid<Object> grid = gridFactory.createGrid("grid", hospital,

                        new GridBuilderParameters<Object>(new WrapAroundBorders(),

                                    new SimpleGridAdder<Object>(), true, 50, 50));

           

            Floor floor1 = new Floor("Floor 1");

            Floor floor2 = new Floor("Floor 2");

           

            hospital.addSubContext(floor1);

            hospital.addSubContext(floor2);

            hospital.add(floor1);

            hospital.add(floor2);

           

            grid.moveTo(floor1, 10, 25);

            grid.moveTo(floor2, 30, 25);

           

            Room room1 = new Room("Room 1");

            Room room2 = new Room("Room 2");

            Room room3 = new Room("Room 3");

            Room room4 = new Room("Room 4");

            Room room5 = new Room("Room 5");

           

            floor1.addSubContext(room1);

            floor1.addSubContext(room2);

            floor1.addSubContext(room3);

           

            hospital.add(room1);

            hospital.add(room2);

            hospital.add(room3);

            grid.moveTo(room1, 10, 25);

            grid.moveTo(room2, 15, 25);

            grid.moveTo(room3, 20, 30);

           

            floor2.addSubContext(room4);

            floor2.addSubContext(room5);

            floor2.add(room4);

            floor2.add(room5);

           

            return context;

      }

     

}

 

package subcontexts;

 

import repast.simphony.context.DefaultContext;

 

public class Hospital extends DefaultContext {

 

      public Hospital(String name){

            super(name,name);

      }

}

 

 

 

package subcontexts;

 

import repast.simphony.context.DefaultContext;

 

public class Floor extends DefaultContext {

 

      public Floor (String name){

            super(name,name);

      }

     

}

 

package subcontexts;

 

import repast.simphony.context.DefaultContext;

import repast.simphony.engine.schedule.ScheduledMethod;

import repast.simphony.random.RandomHelper;

 

public class Room extends DefaultContext {

 

                private double contamination = 100 * RandomHelper.nextDouble();

               

                public Room(String name){

                                super(name,"Room");

                }

               

                @ScheduledMethod(start=1, interval=1)

                public void step(){

                               

                                if (contamination > 0){

                                                contamination -= 1;

                                }

                               

                                if (contamination < 0){

                                                contamination = 0;

                                }

                }

 

                public double getContamination() {

                                return contamination;

                }

 

                public void setContamination(double contamination) {

                                this.contamination = contamination;

                }

               

               

}

 

package subcontexts;

 

import java.awt.Color;

import java.awt.Font;

 

import repast.simphony.visualizationOGL2D.StyleOGL2D;

import saf.v3d.ShapeFactory2D;

import saf.v3d.scene.Position;

import saf.v3d.scene.VSpatial;

 

public class FloorStyle implements StyleOGL2D<Floor> {

 

      protected ShapeFactory2D shapeFactory;

 

      public void init(ShapeFactory2D factory) {

            this.shapeFactory = factory;

      }

 

 

      public VSpatial getVSpatial(Floor agent, VSpatial spatial) {

            if (spatial == null) {

                  spatial = shapeFactory.createRectangle(250, 250);

            }

            return spatial;

      }

 

      public Color getColor(Floor agent) {

            return Color.lightGray;

      }

 

      public float getRotation(Floor agent) {

            return 0f;

      }

 

 

      public Color getBorderColor(Floor object) {

            return Color.BLACK;

      }

 

 

      public int getBorderSize(Floor object) {

            return 0;

      }

 

 

      public float getScale(Floor object) {

            return 1f;

      }

 

      public String getLabel(Floor object) {

            return null;

      }

 

      public Font getLabelFont(Floor object) {

            return null;

      }

 

 

      public Position getLabelPosition(Floor object) {

            return Position.NORTH;

      }

 

 

      public float getLabelXOffset(Floor object) {

            return 0;

      }

 

 

      public float getLabelYOffset(Floor object) {

            return 0;

      }

 

      public Color getLabelColor(Floor object) {

            return Color.BLACK;

      }

}

 

package subcontexts;

 

import java.awt.Color;

import java.awt.Font;

 

import repast.simphony.visualizationOGL2D.StyleOGL2D;

import saf.v3d.ShapeFactory2D;

import saf.v3d.scene.Position;

import saf.v3d.scene.VSpatial;

 

public class RoomStyle implements StyleOGL2D<Room> {

 

                protected ShapeFactory2D shapeFactory;

 

                public void init(ShapeFactory2D factory) {

                                this.shapeFactory = factory;

                }

 

 

                public VSpatial getVSpatial(Room agent, VSpatial spatial) {

                                if (spatial == null) {

                                                spatial = shapeFactory.createRectangle(50, 50);

                                }

                                return spatial;

                }

 

                public Color getColor(Room agent) {

                               

                                float c = (float)agent.getContamination() / 100.0f;

                               

                                return new Color(c, 0.5f, 0.5f);

                }

 

                public float getRotation(Room agent) {

                                return 0f;

                }

 

 

                public Color getBorderColor(Room object) {

                                return Color.BLACK;

                }

 

 

                public int getBorderSize(Room object) {

                                return 0;

                }

 

 

                public float getScale(Room object) {

                                return 1f;

                }

 

                public String getLabel(Room object) {

                                return null;

                }

 

                public Font getLabelFont(Room object) {

                                return null;

                }

 

 

                public Position getLabelPosition(Room object) {

                                return Position.NORTH;

                }

 

 

                public float getLabelXOffset(Room object) {

                                return 0;

                }

 

 

                public float getLabelYOffset(Room object) {

                                return 0;

                }

 

                public Color getLabelColor(Room object) {

                                return Color.BLACK;

                }

}

 

 

 

From: Willy Ray [mailto:[hidden email]]
Sent: Thursday, June 15, 2017 7:59 PM
To: Nick Collier <[hidden email]>
Cc: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Best tutorials or demo models for displaying subcontexts?

 

I'll take a close look at those two links.  I'll need to visualize empty rooms (extending DefaultContext, and added via addSubContext)... no agents inside, just objects with decaying levels of contamination.  I wonder if there's some way to get a canvas and draw programmatically?  

 

On Thu, Jun 15, 2017 at 1:32 PM, Nick Collier <[hidden email]> wrote:

 There’s no way to visualize the contexts per se — you’d be visualizing the agents within them. You could perhaps have a “display agent” in each one that you style as rectangle in a continous space. You might also be able to create a similar effect using value layers. See:

 

 

And see this about 1/2 way down:

 

 

Unfortunately, we don’t have any good examples in the demo models for displaying contexts themselves,

 

Nick

 




On Jun 14, 2017, at 6:10 PM, Willy Ray <[hidden email]> wrote:

I have a hospital model with many floors.  Each floor has many rooms.  These are all extending DefaulContext and are added to each other as subcontexts.

These floors and rooms don't have actual spatial relationships... they're only related via their hierarchy.   What I'd like to do is visualize them with a bunch of tiled, nested rectangles... each color coded for different kinds of status.  

So, I'm guessing I'm going to loop through the contexts, adding them to a grid projection?  but I'm still not sure how to set up the visualization.  Is there a suggestion for the best tutorial or demo model that I could look at to get an idea of how to do something like this?

Thanks,

Willy

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