From 5ae672981c3bf1b76bfbefd7aadaf85eb1c54b25 Mon Sep 17 00:00:00 2001
From: "dereeves@nps.edu" <dereeves@nps.edu>
Date: Tue, 9 Mar 2021 17:15:23 -0800
Subject: [PATCH] * added ability to talk to the borg in libraries

---
 scripts/HTN/Trees/Red/RandomMove.xml |  11 ++++++---
 scripts/HTNBehaviors.py              |  35 +++++++++++++++++++++++++++
 scripts/data/road_edges.srz          | Bin 564136 -> 564136 bytes
 3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/scripts/HTN/Trees/Red/RandomMove.xml b/scripts/HTN/Trees/Red/RandomMove.xml
index 2c36623..8edb793 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 5f0f03a..c7e1aad 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
GIT binary patch
delta 45
zcmZ3nU1`O3r3tAV`nwOaHSCjgZ_I7YWo*r5YRzSC&1GrLWo^x6Yt3cfn#*B58vvr)
B5cvQA

delta 45
zcmZ3nU1`O3r3tAVoU7-*TDvG^Q)6yxE@NvhQ)@1BYc5M`E^BKpTWc=+)?5zj*#OHF
B5=sC7

-- 
GitLab