diff --git a/scripts/HTN/Trees/Red/RandomMove.xml b/scripts/HTN/Trees/Red/RandomMove.xml index 2c366235b052f0f73f5503f3ccd7d03d54705ca4..8edb793e69ba08b16580b2fc6a689b4ee76b6574 100644 --- a/scripts/HTN/Trees/Red/RandomMove.xml +++ b/scripts/HTN/Trees/Red/RandomMove.xml @@ -13,15 +13,18 @@ <HTNNode AllowMsg="true" Name="moveToData" Type="DEFAULT"> <Parent>initInfo</Parent> <Code IsFile="false">from HTNBehaviors import SendEntityEventDelay +from HTNBehaviors import GetRandomPoint import cxxi.model.behavior.PythonUtilities as PythonUtilities import math -int_num = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0]) -int_num *= borg.allWPs.size() -int_num = int(round(int_num)) +#int_num = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0]) +#int_num *= borg.allWPs.size() +#int_num = int(round(int_num)) #destName = "INTERSECTION" + str(int_num) -destName = borg.allWPs.get(int_num).getName() +#destName = borg.allWPs.get(int_num).getName() + +destName = GetRandomPoint() SendEntityEventDelay(info.getMyAssignedName(), "GoalTracker_MoveToDestination", ["RANDOM", destName], 5.0) borg.delay=1.0 diff --git a/scripts/HTNBehaviors.py b/scripts/HTNBehaviors.py index 5f0f03a46cab3a2ddc47088febce84b13a92a53d..c7e1aadf54eb0506433103745410ba6397cd3bbe 100644 --- a/scripts/HTNBehaviors.py +++ b/scripts/HTNBehaviors.py @@ -3,10 +3,45 @@ from java.util import ArrayList import cxxi.model.objects.holders.CMHolder as CMHolder import cxxi.model.behavior.OrderUtilities as OrderUtilities +import mtry.cxxi.model.HierarchicalTaskNetwork.GoalContainer as GoalContainer +import cxxi.model.behavior.PythonUtilities as PythonUtilities + +#from UtilityFuncsExp import HTNBorg as borg + __HTN_PATH__ = "HTN/Trees/" __BASIC_MOVE_PATH__ = "HTN/Trees/BasicMove.xml" __NETWORK_MOVE_PATH__ = "HTN/Trees/NetworkMove.xml" +borg = None + +# Reads from a list of allWPs +def GetRandomPoint(): + _InitBorgInternal() + + int_num = PythonUtilities._py_getRandomNumber("UNIFORM", [0.0, 1.0]) + int_num *= borg.allWPs.size() + int_num = int(round(int_num)) + + destName = borg.allWPs.get(int_num).getName() + + return destName + +def _InitBorgInternal(): + global borg + + if borg == None: + borgName = GoalContainer.getBorgName() + impStr = "from "+borgName+" import HTNBorg" + exec(impStr) + borg = HTNBorg() + print "Borg created" + else: + print "Borg already created" + +def TestBorg(): + _InitBorgInternal() + print "Test borg=",borg.allWPs.size() + def ConvertToJavaList(l): al = ArrayList() for o in l: diff --git a/scripts/data/road_edges.srz b/scripts/data/road_edges.srz index 02e3dc721779a41d962e639a2dd8cdada8b0bd3c..81aa1bb6c916ab81494c4e66767ff651191f0f73 100644 Binary files a/scripts/data/road_edges.srz and b/scripts/data/road_edges.srz differ