Skip to content
Snippets Groups Projects
Commit 6b69daba authored by Montaña Melgarejo,J.A. (Juliana)'s avatar Montaña Melgarejo,J.A. (Juliana)
Browse files

deleted datacollectors and added two types of humans

parent 8f102b9c
No related branches found
No related tags found
2 merge requests!2Env factors,!1Env factors
<repast.simphony.visualization.engine.CartesianDisplayDescriptor simphonyVersion="2.6.0">
<name>parkingGrid</name>
<type>2D</type>
<styles>
<entry>
<string>loadPoles.Human</string>
<string>repast.simphony.visualization.editedStyle.EditedStyle2D</string>
</entry>
</styles>
<editedStyles>
<entry>
<string>loadPoles.Human</string>
<string>loadPoles.Human.style_3.xml</string>
</entry>
</editedStyles>
<netStyles/>
<editedNetStyles/>
<frequency>ON_MOVE</frequency>
<schedParams>
<start>1.0</start>
<interval>1.0</interval>
<priority>-Infinity</priority>
<pType>LAST</pType>
<duration>-1.0</duration>
<frequency>REPEAT</frequency>
<hashCode>340843923</hashCode>
</schedParams>
<layoutClassName>foo.bar.baz</layoutClassName>
<layoutProjection>parkingspacesGrid</layoutProjection>
<layoutInterval>0</layoutInterval>
<layerOrder>
<entry>
<string>loadPoles.Human</string>
<int>0</int>
</entry>
</layerOrder>
<projections>
<repast.simphony.scenario.data.ProjectionData>
<id>parkingspacesGrid</id>
<attributes/>
<type>grid</type>
</repast.simphony.scenario.data.ProjectionData>
</projections>
<visualizationProperties class="repast.simphony.visualization.UnitSizeLayoutProperties">
<unitSize>15.0</unitSize>
</visualizationProperties>
<projectionDescriptors>
<entry>
<string>parkingspacesGrid</string>
<repast.simphony.visualization.grid.GridProjectionDescriptor>
<proj reference="../../../../projections/repast.simphony.scenario.data.ProjectionData"/>
<props>
<entry>
<string>repast.simphony.visualization.grid.GridDecorator</string>
<map>
<entry>
<string>COLOR</string>
<int>-16777216</int>
</entry>
<entry>
<string>UNIT_SIZE</string>
<float>15.0</float>
</entry>
<entry>
<string>SHOW</string>
<boolean>true</boolean>
</entry>
</map>
</entry>
</props>
</repast.simphony.visualization.grid.GridProjectionDescriptor>
</entry>
</projectionDescriptors>
<props/>
<backgroundColor>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</backgroundColor>
<valueLayers/>
</repast.simphony.visualization.engine.CartesianDisplayDescriptor>
\ No newline at end of file
<repast.simphony.chart2.engine.TimeSeriesChartDescriptor simphonyVersion="2.6.0">
<name>customB</name>
<dataSet>CustomHappinessB</dataSet>
<xAxisLabel>Tick Count</xAxisLabel>
<yAxisLabel>happy</yAxisLabel>
<chartTitle>customb</chartTitle>
<type>TIME_SERIES</type>
<background>
<red>192</red>
<green>192</green>
<blue>192</blue>
<alpha>255</alpha>
</background>
<gridLineColor>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</gridLineColor>
<showGrid>true</showGrid>
<showLegend>true</showLegend>
<seriesIds>
<entry>
<string>Happiness per Type (B)</string>
<SeriesData>
<label>Happiness per Type (B)</label>
<color>
<red>51</red>
<green>204</green>
<blue>0</blue>
<alpha>255</alpha>
</color>
</SeriesData>
</entry>
</seriesIds>
<dataValueIds/>
<plotRangeLength>-1</plotRangeLength>
</repast.simphony.chart2.engine.TimeSeriesChartDescriptor>
\ No newline at end of file
package loadPoles;
import java.util.List;
import repast.simphony.context.Context;
import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.query.space.grid.GridCell;
import repast.simphony.query.space.grid.GridCellNgh;
import repast.simphony.random.RandomHelper;
import repast.simphony.space.graph.Network;
import repast.simphony.space.grid.Grid;
import repast.simphony.space.grid.GridPoint;
import repast.simphony.util.SimUtilities;
public class Asshole extends Human {
boolean needsCharging;
public Asshole(Context<Object> context) {
super(context);
this.carType = "a";
// TODO Auto-generated constructor stub
}
@ScheduledMethod(start = 1, interval = 1, priority = 2, shuffle = true)
public void parkCar() {
//do we even use a car?
if (!carUser)
return;
System.out.println("Parkingname: " + this.name);
//Find best empty spot
//Get location of home
Grid<Object> grid = (Grid<Object>) context.getProjection("dwellingsGrid");
Network<Object> livingin = (Network<Object>) context.getProjection("livingin");
Iterable<Object> home = livingin.getAdjacent(this);
GridPoint homeLocation = grid.getLocation(home.iterator().next());
//Now look for parking spots
Grid<Object> parkingSpots = (Grid<Object>) context.getProjection("parkingspacesGrid");
//get all cells around the home location
GridCellNgh<ParkingSpace> nghCreator = new GridCellNgh<ParkingSpace>(parkingSpots, homeLocation, ParkingSpace.class, 2, 2);
List<GridCell<ParkingSpace>> gridCells = nghCreator.getNeighborhood(true);
SimUtilities.shuffle(gridCells, RandomHelper.getUniform());
//Check the neighbourhood for the closest empty spot
// The spot has either no agent in it or an agent that isn't parked
double minDistance = Double.MAX_VALUE, parkDistance = 0;
GridCell<ParkingSpace> closestCell = null;
ParkingSpace closestSpot = null;
for (GridCell<ParkingSpace> cell : gridCells) {
//Iterable<Object> spotUsers = parkingSpots.getObjectsAt(cell.getPoint().getX(),cell.getPoint().getY());
//System.out.println("spotUsers: " + spotUsers + " size: "+ spotUsers.spliterator().estimateSize() + " somone parked: " + isSomeoneParked(parkingSpots, cell));
ParkingSpace spot = (ParkingSpace) parkingSpots.getObjectAt(cell.getPoint().getX(),cell.getPoint().getY());
System.out.println("this carType: " + this.carType + " and spot type: " + spot.getType());
//if( spotUser != null) System.out.println("Spot "+ cell.getPoint().getX() + "," + cell.getPoint().getY() + " is not null but first occupant is parked?: " + spotUser.getHasParked());
//if( spotUser == null || isSomeoneParked(parkingSpots, cell) == false) {
if (!spot.getOccupied() && this.carType == spot.getType()) {
parkDistance = parkingSpots.getDistance(homeLocation, cell.getPoint());
if (parkDistance < minDistance) {
minDistance = parkDistance;
if(parkDistance == 0.0) System.out.println("is someone parked: " + spot.getOccupied());
System.out.println("parkDistance: " + parkDistance);
closestCell = cell;
closestSpot = spot;
}
}
}
//If we have found a parking spot: park!
if(closestCell != null) {
System.out.println("I am moving to: " + closestCell.getPoint().getX() + "," + closestCell.getPoint().getY());
parkingSpots.moveTo(this, closestCell.getPoint().getX(),closestCell.getPoint().getY());
closestSpot.setOccupied(true);
this.hasParked = true;
if(closestSpot.getType() == "a" && this.happiness < 1)
this.happiness = (float) (this.happiness + 0.1 - (parkDistance * parkDistance * 0.01));
} else {
System.out.println("wasnt able to find a spot!!!!!!");
if (this.happiness > 0) this.happiness = (float) (this.happiness - 0.3);
}
}
}
package loadPoles;
import repast.simphony.data2.AggregateDataSource;
public class HappinessAggregateDataSourceA implements AggregateDataSource {
@Override
public String getId() {
return "Happiness per Type (A)";
}
@Override
public Class<?> getDataType() {
return float.class;
}
@Override
public Class<?> getSourceType() {
// TODO Auto-generated method stub
return Human.class;
}
@Override
public Object get(Iterable<?> objs, int size) {
Human human = (Human) objs.iterator().next();
if(human.getType() == "a") {
return human.getHappinessA();
}
return null;
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
}
package loadPoles;
import repast.simphony.data2.AggregateDataSource;
public class HappinessAggregateDataSourceB implements AggregateDataSource {
@Override
public String getId() {
return "Happiness per Type (B)";
}
@Override
public Class<?> getDataType() {
return float.class;
}
@Override
public Class<?> getSourceType() {
// TODO Auto-generated method stub
return Human.class;
}
@Override
public Object get(Iterable<?> objs, int size) {
Human human = (Human) objs.iterator().next();
if(human.getType() == "b") {
return human.getHappinessB();
}
return null;
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
}
package loadPoles;
import java.util.List;
import repast.simphony.context.Context;
import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.query.space.grid.GridCell;
import repast.simphony.query.space.grid.GridCellNgh;
import repast.simphony.random.RandomHelper;
import repast.simphony.space.graph.Network;
import repast.simphony.space.grid.Grid;
import repast.simphony.space.grid.GridPoint;
import repast.simphony.util.SimUtilities;
public class Hippie extends Human {
boolean needsCharging;
public Hippie(Context<Object> context) {
super(context);
this.carType = "b";
// TODO Auto-generated constructor stub
}
@ScheduledMethod(start = 1, interval = 1, priority = 2, shuffle = true)
public void parkCar() {
//do we even use a car?
if (!carUser)
return;
System.out.println("Parkingname: " + this.name);
//Find best empty spot
//Get location of home
Grid<Object> grid = (Grid<Object>) context.getProjection("dwellingsGrid");
Network<Object> livingin = (Network<Object>) context.getProjection("livingin");
Iterable<Object> home = livingin.getAdjacent(this);
GridPoint homeLocation = grid.getLocation(home.iterator().next());
//Now look for parking spots
Grid<Object> parkingSpots = (Grid<Object>) context.getProjection("parkingspacesGrid");
//get all cells around the home location
GridCellNgh<ParkingSpace> nghCreator = new GridCellNgh<ParkingSpace>(parkingSpots, homeLocation, ParkingSpace.class, 2, 2);
List<GridCell<ParkingSpace>> gridCells = nghCreator.getNeighborhood(true);
SimUtilities.shuffle(gridCells, RandomHelper.getUniform());
//Check the neighbourhood for the closest empty spot
// The spot has either no agent in it or an agent that isn't parked
double minDistance = Double.MAX_VALUE, parkDistance = 0;
GridCell<ParkingSpace> closestCell = null;
ParkingSpace closestSpot = null;
for (GridCell<ParkingSpace> cell : gridCells) {
//Iterable<Object> spotUsers = parkingSpots.getObjectsAt(cell.getPoint().getX(),cell.getPoint().getY());
//System.out.println("spotUsers: " + spotUsers + " size: "+ spotUsers.spliterator().estimateSize() + " somone parked: " + isSomeoneParked(parkingSpots, cell));
ParkingSpace spot = (ParkingSpace) parkingSpots.getObjectAt(cell.getPoint().getX(),cell.getPoint().getY());
System.out.println("this carType: " + this.carType + " and spot type: " + spot.getType());
//if( spotUser != null) System.out.println("Spot "+ cell.getPoint().getX() + "," + cell.getPoint().getY() + " is not null but first occupant is parked?: " + spotUser.getHasParked());
//if( spotUser == null || isSomeoneParked(parkingSpots, cell) == false) {
if (!spot.getOccupied() && ( this.carType == spot.getType() ||
(spot.getType() == "a" && !needsCharging))) {
parkDistance = parkingSpots.getDistance(homeLocation, cell.getPoint());
if (parkDistance < minDistance) {
minDistance = parkDistance;
if(parkDistance == 0.0) System.out.println("is someone parked: " + spot.getOccupied());
System.out.println("parkDistance: " + parkDistance);
closestCell = cell;
closestSpot = spot;
}
}
}
//If we have found a parking spot: park!
if(closestCell != null) {
System.out.println("I am moving to: " + closestCell.getPoint().getX() + "," + closestCell.getPoint().getY());
parkingSpots.moveTo(this, closestCell.getPoint().getX(),closestCell.getPoint().getY());
closestSpot.setOccupied(true);
this.hasParked = true;
if(closestSpot.getType() == "b") {
if(this.happiness < 1) {
if(!needsCharging) this.happiness = (float) (this.happiness - 0.1 - (parkDistance * parkDistance * 0.01));
if(needsCharging) this.happiness = (float) (this.happiness + 0.2 - (parkDistance * parkDistance * 0.01));
}
} else {
if(this.happiness < 1) {
if(!needsCharging) this.happiness = (float) (this.happiness + 0.1 - (parkDistance * parkDistance * 0.01));
if(needsCharging) this.happiness = (float) (this.happiness + 0.1 - (parkDistance * parkDistance * 0.5));
}
}
} else {
System.out.println("wasnt able to find a spot!!!!!!");
if (this.happiness > 0) this.happiness = (float) (this.happiness - 0.3);
}
}
}
......@@ -17,7 +17,7 @@ import repast.simphony.util.SimUtilities;
public class Human {
boolean carUser, hasParked;
String carType,name;
String carType, name;
Context<Object> context;
float happiness;
......
......@@ -72,9 +72,16 @@ public class Neighbourhood {
//Add people
for(int i = 0; i < humancount; i++)
{
context.add(new Human(context));
if(RandomHelper.nextDoubleFromTo(0, 1) > 0.5) {
// "Normal" car
context.add(new Asshole(context));
} else {
// Electric car user
context.add(new Hippie(context));
}
}
//make sure they have a home
NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object> ("livingin", context, true);
Network<Object> livingin = netBuilder.buildNetwork();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment