def __init__(self, xmlFile): Config.__init__(self, xmlFile) self._landCover = 'unknown' self._settlements = 'unknown' self._hydro = 'unknown' self._apdsi = 'unknown' self._harvestVariance = 0.0 self._harvestAdjustment = 0.0 self._mobilityDist = 0 self._initialNumber = 0 self._nutritionNeed = 0 self._minInitialAge = 0 self._maxInitialAge = 0 self._minDeathAge = 0 self._maxDeathAge = 0 self._minFertility = 0.0 self._maxFertility = 0.0 self._minFertilityAge = 0 self._maxFertilityAge = 0 self._minFertilityEndsAge = 0 self._maxFertilityEndsAge = 0 self._maizeToGift = 0 self._minInitialCorn = 0 self._maxInitialCorn = 0 self._locations = []
def __init__(self, xmlFile): Config.__init__(self, xmlFile) self._asabiyaIncrease = 0.0 self._asabiyaDecay = 0.0 self._minAsabiya = 0.0 self._distanceSensibility = 0.0 self._attackThreshold = 0.0
def __init__(self, xmlFile): Config.__init__(self, xmlFile) # farmer config self._initFarmers = 0 self._farmersStrength = 0.0 self._farmersGrowthRate = 0.0 self._farmersImmigrationRate = 0.0 self._initHerders = 0 self._herdersRelativeStrength = 0.0 self._herdersGrowthRate = 0.0 self._herdersImmigrationRate = 0.0
def testSimulationSize(self): myConfig = Config(SizeInt(10, 10), 1) size = SizeInt(9, 10) self.assertNotEqual(myConfig.size, size) size._width = 10 self.assertEqual(myConfig.size, size)
def testGetUnknownRasterThrowsException(self): myConfig = Config(SizeInt(10, 10), 1) myWorld = TestWorld(myConfig, TestWorld.useSpacePartition(1, True)) myWorld.initialize() myWorld.run() try: myWorld.getDynamicRaster('unknown') self.assertEqual(1 != 2) except: dummy = 1 try: myWorld.getStaticRaster('unknown') self.assertEqual(1 != 2) except: dummy = 1 try: myWorld.getStaticRaster(1000) self.assertEqual(1 != 2) except: dummy = 1 try: myWorld.getDynamicRaster(1000) self.assertEqual(1 != 2) except: dummy = 1
def main(): shpFileName = '../../../resources/test.shp' config = Config(SizeInt(64, 64)) shpWorld = ShpWorld(config, ShpWorld.useOpenMPSingleNode(), shpFileName) shpWorld.initialize() shpWorld.run()
def main(): rasterFileName = '../../../resources/rasterWithColor.tiff' rasterWorld = RasterWorld(Config(SizeInt(708, 708), 1), RasterWorld.useOpenMPSingleNode(), rasterFileName) rasterWorld.initialize() rasterWorld.run()
def testExecuteTwoWorlds(self): myConfig = Config(SizeInt(10, 10), 1) myWorld = TestWorld(myConfig, TestWorld.useSpacePartition(1, False)) myWorld.initialize() myWorld.run() myWorld = TestWorld(myConfig, TestWorld.useSpacePartition(1, False)) myWorld.initialize() myWorld.run()
def main(): """ this file provides a template that can be used to create new pyPandora models """ size = SizeInt(10, 10) numSteps = 10 myConfig = Config(size, numSteps) world = HelloWorld(myConfig) world.initialize() world.run()
def main(): print('getting started with pyPandora') numTimeSteps = 10 worldSize = SizeInt(64, 64) myConfig = Config(worldSize, numTimeSteps) myWorld = MyWorld(myConfig) myWorld.initialize() myWorld.run() print('simulation finished')
def testAddAgent(self): myConfig = Config(SizeInt(10, 10), 1) myWorld = TestWorld(myConfig, TestWorld.useSpacePartition(1, False)) myWorld.initialize() myAgent = TestAgent('agent_0') myWorld.addAgent(myAgent) myAgent.setRandomPosition() myWorld.run() self.assertEqual(myAgent.getWorld(), myWorld)
def testAgentRemovedIsNotExecuted(self): myConfig = Config(SizeInt(10, 10), 1) myWorld = TestWorld(myConfig, TestWorld.useSpacePartition(1, False)) myWorld.initialize() myAgent = TestAgent('agent_0') myWorld.addAgent(myAgent) myAgent.setRandomPosition() self.assertEqual(myAgent.exists, True) myAgent.remove() self.assertEqual(myAgent.exists, False) myWorld.run()
def __init__(self, xmlFile): Config.__init__(self, xmlFile) # climate self._climateMean = 0 self._climateSd = 1 # agents self._initialPopulation = 0 self._locationTries = 10 self._requiredNeedsPercentage = 1.0 # animals self._animalsCaKg = 0 self._animalsKg = 0 # crops self._cropsKgHa = 0 self._cropsCaKg = 0 self._cropsVariability = 0.0 self._cropsMinRain = 0.0 self._cropsOptimalRain = 0.0 self._cropsMaxRain = 0.0 self._reserve = 1.0
def testAgentRemovedIsNotInsideNeighbours(self): myConfig = Config(SizeInt(10, 10), 1) myWorld = TestWorld(myConfig, TestWorld.useSpacePartition(1, False)) myWorld.initialize() myWorld.run() myAgent0 = TestAgent('agent_0') myAgent1 = TestAgent('agent_1') myAgent2 = TestAgent('agent_2') myWorld.addAgent(myAgent0) myWorld.addAgent(myAgent1) myWorld.addAgent(myAgent2) myAgent0.setRandomPosition() myAgent1.setRandomPosition() myAgent2.setRandomPosition() agentIds = myWorld.getNeighboursIds(myAgent0, 20, 'agent') self.assertEqual(len(agentIds), 2) myAgent1.remove() myAgent2.remove() agentIds = myWorld.getNeighboursIds(myAgent0, 20, 'agent') self.assertEqual(len(agentIds), 0)
def main(): config = Config(SizeInt(64, 64), 5, "sequential/data.hdf5") customWorld = CustomWorld(config, CustomWorld.useOpenMPSingleNode()) customWorld.initialize() customWorld.run()
def updateState(self): newPosition = Point2DInt(self.position._x + random.randint(-1, 1), self.position._y + random.randint(-1, 1)) if self.getWorld().checkPosition(newPosition): self.position = newPosition def serialize(self): return class MyWorld(World): def __init__(self, config): World.__init__(self, config) def createRasters(self): self.registerDynamicRaster("test", 1) self.getDynamicRaster("test").setInitValues(0, 0, 0) def createAgents(self): for i in range(0, 300): newAgent = MyAgent('id_' + str(i)) self.addAgent(newAgent) newAgent.setRandomPosition() myConfig = Config(SizeInt(32, 32), 300) myWorld = MyWorld(myConfig) myWorld.initialize() myWorld.run()
def main(): rasterFileName = '../../../resources/test.tiff' rasterWorld = RasterWorld(Config(SizeInt(120,120), 1), RasterWorld.useOpenMPSingleNode(), rasterFileName) rasterWorld.initialize() rasterWorld.run()
pandoraPath = os.getenv('PANDORAPATH', '/usr/local/pandora') sys.path.append(pandoraPath+'/bin') sys.path.append(pandoraPath+'/lib') from pyPandora import Point2DInt, Config, World, SizeInt class MyWorld(World): def __init__(self, config): World.__init__( self, config) def createRasters(self): self.registerDynamicRaster("test", 1) self.getDynamicRaster("test").setInitValues(0, 10, 0) def createAgents(self): return def stepEnvironment(self): print('executing step environment') raster = self.getDynamicRaster("test") for i in range(self.getBoundaries().left, self.getBoundaries().right+1): for j in range(self.getBoundaries().top, self.getBoundaries().bottom+1): pos = Point2DInt(i,j) raster.setValue(pos, 1+self.currentStep) myConfig = Config(SizeInt(64,64), 10) myWorld = MyWorld(myConfig) myWorld.initialize() myWorld.run()
def __init__(self, config): World.__init__(self, config) def createRasters(self): self.registerDynamicRaster("test", 1) self.getDynamicRaster("test").setInitValues(0, 10, 0) def createAgents(self): for i in range(0, 10): newAgent = MyAgent('id_' + str(i)) self.addAgent(newAgent) newAgent.setRandomPosition() newAgent._value = random.randint(0, 10) myConfig = Config(SizeInt(32, 32), 10) myWorld = MyWorld(myConfig) myWorld.initialize() myWorld.run() # analysis record = SimulationRecord(1, False) record.loadHDF5('data/results.h5', True, True) agentResults = GlobalAgentStats(';') agentResults.addAnalysis(AgentNum()) agentResults.addAnalysis(AgentMean('x')) agentResults.addAnalysis(AgentMean('y')) agentResults.addAnalysis(AgentMean('value')) agentResults.addAnalysis(AgentSum('value'))