diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ad_hoc.py b/ad_hoc.py new file mode 100644 index 0000000..586c7b2 --- /dev/null +++ b/ad_hoc.py @@ -0,0 +1,97 @@ +""" +An example using the rover domain gym-style interface and the standard, included CCEA learning algorithms. +This is a minimal example, showing the minimal Gym interface. +""" +import numpy as np +import sys +import multiprocessing as mp + + + +from rover_domain_core_gym import RoverDomainGym +import code.ccea_2 as ccea +import code.agent_domain_2 as domain +import mods +from teaming.learner import learner +from sys import argv +import pickle +import tensorflow as tf + + +def make_env(progress): + + nagents=1 + + sim = RoverDomainGym(nagents,100) + #mods.recipePoi(sim) + obs=sim.reset() + #print(len(obs[0])) + #for i in range(sim.data["Recipe Size" ]): + # sim.data["Item Held"][0][i]=progress[i] + + #obs=reduce_state(obs) + + sim.data["Coupling"]=1 + sim.data['Number of Agents']=nagents + return sim + +def test1(trial): + env=make_env([1,1,1,1]) + team=[0,0,1,1,2,2,3,3] + team=[0] + with tf.Session() as sess: + + controller = learner(team,sess) + init=tf.global_variables_initializer() + sess.run(init) + + + for i in range(10001): + r=controller.run(env,i,0)# i%100 == -10) + print(i,max(r)) + if i%1000==0 and 0: + controller.test(env) + if i%1000==0: + controller.save("logs/"+str(trial)+"t.pkl") + #print(r) +''' +test1(0) +for i in range(0): + p=mp.Process(target=test1,args=(i,)) + p.start() + #p.join() +''' +env=make_env(None) + +from time import sleep + +s=env.reset() +s=s[:,4:][0] +for i in range(100): + + idx=1 + loc=env.data["Poi Positions"][idx] + ang=env.data["Agent Orientations"][0] + pos=env.data["Agent Positions"][0] + + heading=[loc[0]-pos[0],loc[1]-pos[1]] + + trn=np.arccos( (heading[0]*ang[0]+heading[1]*ang[1])/( np.sqrt(heading[0]**2+heading[1]**2))* np.sqrt(ang[0]**2+ang[1]**2) ) + trn/=4 + spd=1.0 + + a=[spd,trn] + + s,r,_,_=env.step([a]) + s=s[:,4:][0] + print(i,r,trn,spd) + env.render() + sleep(0.033) + + + + + + + + diff --git a/ad_hoc2.py b/ad_hoc2.py new file mode 100644 index 0000000..aa8b248 --- /dev/null +++ b/ad_hoc2.py @@ -0,0 +1,234 @@ +""" +An example using the rover domain gym-style interface and the standard, included CCEA learning algorithms. +This is a minimal example, showing the minimal Gym interface. +""" +import numpy as np +import sys +import multiprocessing as mp + + + +from rover_domain_core_gym import RoverDomainGym +import code.ccea_2 as ccea +import code.agent_domain_2 as domain +import mods +from teaming.learner3 import learner +from sys import argv +import pickle +import tensorflow as tf + +def rand_loc(n): + x,y=np.random.random(2) + pos=[[x,y]] + while len(pos)<6: + X,Y=np.random.random(2) + for x,y in pos: + dist=((X-x)**2.0+(Y-y)**2.0 )**0.5 + if dist<0.2: + X=None + break + if not X is None: + pos.append([X,Y]) + + return np.array(pos) + + +#print(vals) +def make_env(team): + vals =np.array([0.1, 0.1, 0.5,0.3, 0.0, 0.0]) + + pos=np.array([ + [0.0, 0.0], + [1.0, 1.0], + [0.0, 1.0], + [1.0, 0.5], + [0.0, 0.5], + [1.0, 0.0] + ]) + + #pos=rand_loc(6)#np.random.random((6,2)) + #vals=np.random.random(6)/2.0 + print(vals) + nagents=len(team) + + sim = RoverDomainGym(nagents,100,pos,vals) + #mods.recipePoi(sim) + obs=sim.reset() + #print(len(obs[0])) + #for i in range(sim.data["Recipe Size" ]): + # sim.data["Item Held"][0][i]=progress[i] + + #obs=reduce_state(obs) + + sim.data["Coupling"]=2 + sim.data['Number of Agents']=nagents + return sim + + +import time + +def test1(trial,frq): + frq=1 + #print(np.random.get_state())[1] + np.random.seed(int(time.time()*100000)%100000) + team=[0,0,1,1,2,2,3,3] + team=[0,1,2,2,1] + + #team=[0,1,2,2,1,2,0,0] + #team=team+team + env=make_env(team) + with tf.compat.v1.Session() as sess: + + controller = learner(team,sess,env) + init=tf.compat.v1.global_variables_initializer() + sess.run(init) + + + for i in range(10001): + + if i%int(frq)==0: + controller.randomize() + + r=controller.run(env,i,0)# i%100 == -10) + if i%10==0: + print(i,r[-1],controller.team) + if i%50==0 and 1: + controller.test(env) + + if i%50==0: + #controller.save("tests/q"+str(frq)+"-"+str(trial)+".pkl") + #controller.save("logs/"+str(trial)+"r"+str(16)+".pkl") + #controller.save("tests/jj"+str(121)+"-"+str(trial)+".pkl") + controller.save("tests/evo"+str(121)+"-"+str(trial)+".pkl") + #print(r) + #print(r) + + +def test2(trial,f): + #print(np.random.get_state())[1] + np.random.seed(int(time.time()*100000)%100000) + team=[i for i in range(16)] + #team=[0,1,2,3,4] + env=make_env(team) + with tf.compat.v1Session() as sess: + + controller = learner(team,sess) + init=tf.compat.v1.global_variables_initializer() + sess.run(init) + + + for i in range(10001): + r=controller.run(env,i,0)# i%100 == -10) + if i%10==0: + print(i,r[-1],controller.team) + if i%100==0 and 1: + controller.test(env) + if i%1000==0: + controller.save("logs/"+str(trial)+"v16.pkl") + #print(r) + + +def test3(trial,f): + #print(np.random.get_state())[1] + np.random.seed(int(time.time()*100000)%100000) + team=[0,1,2,0,0,0,0,0] + team=team+team + #team=[0,1,2,0,0] + env=make_env(team) + with tf.compat.v1.Session() as sess: + + controller = learner(team,sess) + init=tf.compat.v1.global_variables_initializer() + sess.run(init) + + controller.randomize() + for i in range(10001): + r=controller.run(env,i,0)# i%100 == -10) + if i%10==0: + print(i,r[-1],controller.team) + if i%100==0 and 1: + controller.test(env) + if i%1000==0: + controller.save("logs/"+str(trial)+"r8.pkl") + #print(r) + +def test4(trial,frq): + #print(np.random.get_state())[1] + np.random.seed(int(time.time()*100000)%100000) + team=[0,0,1,1,2,2,3,3] + team=[0,1,2,2,1,1,0,0] + team=team+team + team=np.array([i%int(frq) for i in range(8)]) + env=make_env(team) + with tf.compat.v1.Session() as sess: + + controller = learner(team,sess) + init=tf.compat.v1.global_variables_initializer() + sess.run(init) + + + for i in range(10001): + + if i%1==0: + controller.randomize() + + r=controller.run(env,i,0)# i%100 == -10) + if i%10==0: + print(i,r[-1],controller.team) + if i%100==0 and 1: + controller.test(env) + if i%1000==0: + controller.save("tests/qq"+str(frq)+"-"+str(trial)+".pkl") + + #print(r) +def test5(trial,frq): + #print(np.random.get_state())[1] + np.random.seed(int(time.time()*100000)%100000) + team=[0,0,1,1,2,2,3,3] + team=[0,1,2,2,1,1,0,0] + #team=team+team + #team=np.array([i%int(frq) for i in range(16)]) + env=make_env(team) + with tf.compat.v1.Session() as sess: + + controller = learner(team,sess) + init=tf.compat.v1.global_variables_initializer() + sess.run(init) + controller.put("poi vals",vals) + + for i in range(10001): + + if i%1==0: + controller.randomize() + + r=controller.run(env,i,0)# i%100 == -10) + if i%10==0: + print(i,r[-1],controller.team) + if i%100==0 and 1: + controller.test(env) + if i%1000==0: + controller.save("tests/c"+str(frq)+"-"+str(trial)+".pkl") + +if 0: + + test1(20) +else: + f=sys.argv[1] + print(f) + f=int(f) + for i in range(4): + p=mp.Process(target=test1,args=(i+(8*f),f)) + p.start() + time.sleep(0.01) + #p.join() + +#env=make_env(None) + + + + + + + + + diff --git a/code/agent_domain_2.html b/code/agent_domain_2.html new file mode 100644 index 0000000..4ef583b --- /dev/null +++ b/code/agent_domain_2.html @@ -0,0 +1,1255 @@ + + + +
+ +Generated by Cython 0.29.21
+
+ Yellow lines hint at Python interaction.
+ Click on a line that starts with a "+" to see the C code that Cython generated for it.
+
Raw output: agent_domain_2.c
+ 001:
++002: import numpy as np
+__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; +/* … */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; +
003: cimport cython
+ 004:
+ 005: cdef extern from "math.h":
+ 006: double sqrt(double m)
+ 007:
+ 008: @cython.boundscheck(False) # Deactivate bounds checking
+ 009: @cython.wraparound(False) # Deactivate negative indexing.
++010: cpdef doAgentSense(data):
+static PyObject *__pyx_pw_4code_14agent_domain_2_1doAgentSense(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
+static PyObject *__pyx_f_4code_14agent_domain_2_doAgentSense(PyObject *__pyx_v_data, CYTHON_UNUSED int __pyx_skip_dispatch) {
+ int __pyx_v_number_agents;
+ int __pyx_v_number_pois;
+ double __pyx_v_minDistanceSqr;
+ __Pyx_memviewslice __pyx_v_agentPositionCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ __Pyx_memviewslice __pyx_v_poiValueCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ __Pyx_memviewslice __pyx_v_poiPositionCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ __Pyx_memviewslice __pyx_v_orientationCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ PyObject *__pyx_v_npObservationCol = NULL;
+ __Pyx_memviewslice __pyx_v_observationCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ int __pyx_v_agentIndex;
+ int __pyx_v_otherAgentIndex;
+ int __pyx_v_poiIndex;
+ double __pyx_v_globalFrameSeparation0;
+ double __pyx_v_globalFrameSeparation1;
+ double __pyx_v_agentFrameSeparation0;
+ double __pyx_v_agentFrameSeparation1;
+ double __pyx_v_distanceSqr;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentSense", 0);
+/* … */
+ /* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_3);
+ __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
+ __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_8);
+ __Pyx_XDECREF(__pyx_t_9);
+ __Pyx_AddTraceback("code.agent_domain_2.doAgentSense", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __PYX_XDEC_MEMVIEW(&__pyx_v_agentPositionCol, 1);
+ __PYX_XDEC_MEMVIEW(&__pyx_v_poiValueCol, 1);
+ __PYX_XDEC_MEMVIEW(&__pyx_v_poiPositionCol, 1);
+ __PYX_XDEC_MEMVIEW(&__pyx_v_orientationCol, 1);
+ __Pyx_XDECREF(__pyx_v_npObservationCol);
+ __PYX_XDEC_MEMVIEW(&__pyx_v_observationCol, 1);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_4code_14agent_domain_2_1doAgentSense(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
+static char __pyx_doc_4code_14agent_domain_2_doAgentSense[] = "\n Sensor model is <aNE, aNW, aSW, aSE, pNE, pNE, pSW, pSE>\n Where a means (other) agent, p means poi, and the rest are the quadrants\n ";
+static PyObject *__pyx_pw_4code_14agent_domain_2_1doAgentSense(PyObject *__pyx_self, PyObject *__pyx_v_data) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentSense (wrapper)", 0);
+ __pyx_r = __pyx_pf_4code_14agent_domain_2_doAgentSense(__pyx_self, ((PyObject *)__pyx_v_data));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_4code_14agent_domain_2_doAgentSense(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentSense", 0);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __pyx_f_4code_14agent_domain_2_doAgentSense(__pyx_v_data, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("code.agent_domain_2.doAgentSense", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+ 011: """
+ 012: Sensor model is <aNE, aNW, aSW, aSE, pNE, pNE, pSW, pSE>
+ 013: Where a means (other) agent, p means poi, and the rest are the quadrants
+ 014: """
++015: cdef int number_agents = data['Number of Agents']
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Number_of_Agents); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_number_agents = __pyx_t_2; +
+016: cdef int number_pois = data['Number of POIs']
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Number_of_POIs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 16, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_number_pois = __pyx_t_2; +
+017: cdef double minDistanceSqr = data["Minimum Distance"] ** 2
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Minimum_Distance); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyNumber_Power(__pyx_t_1, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_4 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_minDistanceSqr = __pyx_t_4; +
+018: cdef double[:, :] agentPositionCol = data["Agent Positions"]
+__pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Positions); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 18, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 18, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_agentPositionCol = __pyx_t_5; + __pyx_t_5.memview = NULL; + __pyx_t_5.data = NULL; +
+019: cdef double[:] poiValueCol = data['Poi Values']
+__pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Poi_Values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_poiValueCol = __pyx_t_6; + __pyx_t_6.memview = NULL; + __pyx_t_6.data = NULL; +
+020: cdef double[:, :] poiPositionCol = data["Poi Positions"]
+__pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Poi_Positions); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 20, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 20, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_poiPositionCol = __pyx_t_5; + __pyx_t_5.memview = NULL; + __pyx_t_5.data = NULL; +
+021: cdef double[:, :] orientationCol = data["Agent Orientations"]
+__pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Orientations); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 21, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 21, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_orientationCol = __pyx_t_5; + __pyx_t_5.memview = NULL; + __pyx_t_5.data = NULL; +
+022: npObservationCol = np.zeros((number_agents, 8), dtype = np.float64)
+__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_number_agents); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_int_8); + __Pyx_GIVEREF(__pyx_int_8); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_8); + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_np); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_9) < 0) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_npObservationCol = __pyx_t_9; + __pyx_t_9 = 0; +
+023: cdef double[:, :] observationCol = npObservationCol
+__pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_npObservationCol, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 23, __pyx_L1_error) + __pyx_v_observationCol = __pyx_t_5; + __pyx_t_5.memview = NULL; + __pyx_t_5.data = NULL; +
024:
+ 025: cdef int agentIndex, otherAgentIndex, poiIndex, obsIndex
+ 026: cdef double globalFrameSeparation0, globalFrameSeparation1
+ 027: cdef double agentFrameSeparation0, agentFrameSeparation1
+ 028:
+ 029: cdef double distanceSqr
+ 030:
+ 031:
++032: for agentIndex in range(number_agents):
+ __pyx_t_2 = __pyx_v_number_agents;
+ __pyx_t_10 = __pyx_t_2;
+ for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
+ __pyx_v_agentIndex = __pyx_t_11;
+ 033:
+ 034: # calculate observation values due to other agents
++035: for otherAgentIndex in range(number_agents):
+ __pyx_t_12 = __pyx_v_number_agents;
+ __pyx_t_13 = __pyx_t_12;
+ for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
+ __pyx_v_otherAgentIndex = __pyx_t_14;
+ 036:
+ 037: # agents do not sense self (ergo skip self comparison)
++038: if agentIndex == otherAgentIndex:
+ __pyx_t_15 = ((__pyx_v_agentIndex == __pyx_v_otherAgentIndex) != 0);
+ if (__pyx_t_15) {
+/* … */
+ }
++039: continue
+goto __pyx_L5_continue; +
040:
+ 041: # Get global separation vector between the two agents
++042: globalFrameSeparation0 = agentPositionCol[otherAgentIndex,0] - agentPositionCol[agentIndex,0]
+__pyx_t_16 = __pyx_v_otherAgentIndex; + __pyx_t_17 = 0; + __pyx_t_18 = __pyx_v_agentIndex; + __pyx_t_19 = 0; + __pyx_v_globalFrameSeparation0 = ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_16 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_17 * __pyx_v_agentPositionCol.strides[1]) ))) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_18 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_19 * __pyx_v_agentPositionCol.strides[1]) )))); +
+043: globalFrameSeparation1 = agentPositionCol[otherAgentIndex,1] - agentPositionCol[agentIndex,1]
+__pyx_t_19 = __pyx_v_otherAgentIndex; + __pyx_t_18 = 1; + __pyx_t_17 = __pyx_v_agentIndex; + __pyx_t_16 = 1; + __pyx_v_globalFrameSeparation1 = ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_19 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_18 * __pyx_v_agentPositionCol.strides[1]) ))) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_17 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_16 * __pyx_v_agentPositionCol.strides[1]) )))); +
044:
+ 045: # Translate separation to agent frame using inverse rotation matrix
++046: agentFrameSeparation0 = orientationCol[agentIndex, 0] * globalFrameSeparation0 + orientationCol[agentIndex, 1] * globalFrameSeparation1
+__pyx_t_16 = __pyx_v_agentIndex; + __pyx_t_17 = 0; + __pyx_t_18 = __pyx_v_agentIndex; + __pyx_t_19 = 1; + __pyx_v_agentFrameSeparation0 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_16 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation0) + ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_18 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_19 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation1)); +
+047: agentFrameSeparation1 = orientationCol[agentIndex, 0] * globalFrameSeparation1 - orientationCol[agentIndex, 1] * globalFrameSeparation0
+__pyx_t_19 = __pyx_v_agentIndex; + __pyx_t_18 = 0; + __pyx_t_17 = __pyx_v_agentIndex; + __pyx_t_16 = 1; + __pyx_v_agentFrameSeparation1 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_19 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_18 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation1) - ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_17 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation0)); +
+048: distanceSqr = agentFrameSeparation0 * agentFrameSeparation0 + agentFrameSeparation1 * agentFrameSeparation1
+__pyx_v_distanceSqr = ((__pyx_v_agentFrameSeparation0 * __pyx_v_agentFrameSeparation0) + (__pyx_v_agentFrameSeparation1 * __pyx_v_agentFrameSeparation1)); +
049:
+ 050: # By bounding distance value we implicitly bound sensor values
++051: if distanceSqr < minDistanceSqr:
+ __pyx_t_15 = ((__pyx_v_distanceSqr < __pyx_v_minDistanceSqr) != 0);
+ if (__pyx_t_15) {
+/* … */
+ }
++052: distanceSqr = minDistanceSqr
+__pyx_v_distanceSqr = __pyx_v_minDistanceSqr; +
053:
+ 054:
+ 055: # other is east of agent
++056: if agentFrameSeparation0 > 0:
+ __pyx_t_15 = ((__pyx_v_agentFrameSeparation0 > 0.0) != 0);
+ if (__pyx_t_15) {
+/* … */
+ goto __pyx_L9;
+ }
+ 057: # other is north-east of agent
++058: if agentFrameSeparation1 > 0:
+ __pyx_t_15 = ((__pyx_v_agentFrameSeparation1 > 0.0) != 0);
+ if (__pyx_t_15) {
+/* … */
+ goto __pyx_L10;
+ }
++059: observationCol[agentIndex,0] += 1.0 / distanceSqr
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 59, __pyx_L1_error)
+ }
+ __pyx_t_16 = __pyx_v_agentIndex;
+ __pyx_t_17 = 0;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_16 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_observationCol.strides[1]) )) += (1.0 / __pyx_v_distanceSqr);
+ 060: else: # other is south-east of agent
++061: observationCol[agentIndex,3] += 1.0 / distanceSqr
+ /*else*/ {
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 61, __pyx_L1_error)
+ }
+ __pyx_t_17 = __pyx_v_agentIndex;
+ __pyx_t_16 = 3;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_17 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_observationCol.strides[1]) )) += (1.0 / __pyx_v_distanceSqr);
+ }
+ __pyx_L10:;
+ 062: else: # other is west of agent
+ 063: # other is north-west of agent
++064: if agentFrameSeparation1 > 0:
+ /*else*/ {
+ __pyx_t_15 = ((__pyx_v_agentFrameSeparation1 > 0.0) != 0);
+ if (__pyx_t_15) {
+/* … */
+ goto __pyx_L11;
+ }
++065: observationCol[agentIndex,1] += 1.0 / distanceSqr
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 65, __pyx_L1_error)
+ }
+ __pyx_t_16 = __pyx_v_agentIndex;
+ __pyx_t_17 = 1;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_16 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_observationCol.strides[1]) )) += (1.0 / __pyx_v_distanceSqr);
+ 066: else: # other is south-west of agent
++067: observationCol[agentIndex,2] += 1.0 / distanceSqr
+ /*else*/ {
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 67, __pyx_L1_error)
+ }
+ __pyx_t_17 = __pyx_v_agentIndex;
+ __pyx_t_16 = 2;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_17 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_observationCol.strides[1]) )) += (1.0 / __pyx_v_distanceSqr);
+ }
+ __pyx_L11:;
+ }
+ __pyx_L9:;
+ __pyx_L5_continue:;
+ }
+ 068:
+ 069:
+ 070:
+ 071: # calculate observation values due to pois
++072: for poiIndex in range(number_pois):
+ __pyx_t_12 = __pyx_v_number_pois;
+ __pyx_t_13 = __pyx_t_12;
+ for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
+ __pyx_v_poiIndex = __pyx_t_14;
+ 073:
+ 074: # Get global separation vector between the two agents
++075: globalFrameSeparation0 = poiPositionCol[poiIndex,0] - agentPositionCol[agentIndex,0]
+__pyx_t_16 = __pyx_v_poiIndex; + __pyx_t_17 = 0; + __pyx_t_18 = __pyx_v_agentIndex; + __pyx_t_19 = 0; + __pyx_v_globalFrameSeparation0 = ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_poiPositionCol.data + __pyx_t_16 * __pyx_v_poiPositionCol.strides[0]) ) + __pyx_t_17 * __pyx_v_poiPositionCol.strides[1]) ))) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_18 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_19 * __pyx_v_agentPositionCol.strides[1]) )))); +
+076: globalFrameSeparation1 = poiPositionCol[poiIndex,1] - agentPositionCol[agentIndex,1]
+__pyx_t_19 = __pyx_v_poiIndex; + __pyx_t_18 = 1; + __pyx_t_17 = __pyx_v_agentIndex; + __pyx_t_16 = 1; + __pyx_v_globalFrameSeparation1 = ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_poiPositionCol.data + __pyx_t_19 * __pyx_v_poiPositionCol.strides[0]) ) + __pyx_t_18 * __pyx_v_poiPositionCol.strides[1]) ))) - (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_17 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_16 * __pyx_v_agentPositionCol.strides[1]) )))); +
077:
+ 078: # Translate separation to agent frame unp.sing inverse rotation matrix
++079: agentFrameSeparation0 = orientationCol[agentIndex, 0] * globalFrameSeparation0 + orientationCol[agentIndex, 1] * globalFrameSeparation1
+__pyx_t_16 = __pyx_v_agentIndex; + __pyx_t_17 = 0; + __pyx_t_18 = __pyx_v_agentIndex; + __pyx_t_19 = 1; + __pyx_v_agentFrameSeparation0 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_16 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation0) + ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_18 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_19 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation1)); +
+080: agentFrameSeparation1 = orientationCol[agentIndex, 0] * globalFrameSeparation1 - orientationCol[agentIndex, 1] * globalFrameSeparation0
+__pyx_t_19 = __pyx_v_agentIndex; + __pyx_t_18 = 0; + __pyx_t_17 = __pyx_v_agentIndex; + __pyx_t_16 = 1; + __pyx_v_agentFrameSeparation1 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_19 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_18 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation1) - ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_17 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_orientationCol.strides[1]) ))) * __pyx_v_globalFrameSeparation0)); +
+081: distanceSqr = agentFrameSeparation0 * agentFrameSeparation0 + agentFrameSeparation1 * agentFrameSeparation1
+__pyx_v_distanceSqr = ((__pyx_v_agentFrameSeparation0 * __pyx_v_agentFrameSeparation0) + (__pyx_v_agentFrameSeparation1 * __pyx_v_agentFrameSeparation1)); +
082:
+ 083: # By bounding distance value we implicitly bound sensor values
++084: if distanceSqr < minDistanceSqr:
+ __pyx_t_15 = ((__pyx_v_distanceSqr < __pyx_v_minDistanceSqr) != 0);
+ if (__pyx_t_15) {
+/* … */
+ }
++085: distanceSqr = minDistanceSqr
+__pyx_v_distanceSqr = __pyx_v_minDistanceSqr; +
086:
+ 087: # poi is east of agent
++088: if agentFrameSeparation0> 0:
+ __pyx_t_15 = ((__pyx_v_agentFrameSeparation0 > 0.0) != 0);
+ if (__pyx_t_15) {
+/* … */
+ goto __pyx_L15;
+ }
+ 089: # poi is north-east of agent
++090: if agentFrameSeparation1 > 0:
+ __pyx_t_15 = ((__pyx_v_agentFrameSeparation1 > 0.0) != 0);
+ if (__pyx_t_15) {
+/* … */
+ goto __pyx_L16;
+ }
++091: observationCol[agentIndex,4] += poiValueCol[poiIndex] / distanceSqr
+ __pyx_t_16 = __pyx_v_poiIndex;
+ __pyx_t_4 = (*((double *) ( /* dim=0 */ (__pyx_v_poiValueCol.data + __pyx_t_16 * __pyx_v_poiValueCol.strides[0]) )));
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 91, __pyx_L1_error)
+ }
+ __pyx_t_16 = __pyx_v_agentIndex;
+ __pyx_t_17 = 4;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_16 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_observationCol.strides[1]) )) += (__pyx_t_4 / __pyx_v_distanceSqr);
+ 092: else: # poi is south-east of agent
++093: observationCol[agentIndex,7] += poiValueCol[poiIndex] / distanceSqr
+ /*else*/ {
+ __pyx_t_17 = __pyx_v_poiIndex;
+ __pyx_t_4 = (*((double *) ( /* dim=0 */ (__pyx_v_poiValueCol.data + __pyx_t_17 * __pyx_v_poiValueCol.strides[0]) )));
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 93, __pyx_L1_error)
+ }
+ __pyx_t_17 = __pyx_v_agentIndex;
+ __pyx_t_16 = 7;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_17 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_observationCol.strides[1]) )) += (__pyx_t_4 / __pyx_v_distanceSqr);
+ }
+ __pyx_L16:;
+ 094: else: # poi is west of agent
+ 095: # poi is north-west of agent
++096: if agentFrameSeparation1 > 0:
+ /*else*/ {
+ __pyx_t_15 = ((__pyx_v_agentFrameSeparation1 > 0.0) != 0);
+ if (__pyx_t_15) {
+/* … */
+ goto __pyx_L17;
+ }
++097: observationCol[agentIndex,5] += poiValueCol[poiIndex] / distanceSqr
+ __pyx_t_16 = __pyx_v_poiIndex;
+ __pyx_t_4 = (*((double *) ( /* dim=0 */ (__pyx_v_poiValueCol.data + __pyx_t_16 * __pyx_v_poiValueCol.strides[0]) )));
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 97, __pyx_L1_error)
+ }
+ __pyx_t_16 = __pyx_v_agentIndex;
+ __pyx_t_17 = 5;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_16 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_observationCol.strides[1]) )) += (__pyx_t_4 / __pyx_v_distanceSqr);
+ 098: else: # poi is south-west of agent
++099: observationCol[agentIndex,6] += poiValueCol[poiIndex] / distanceSqr
+ /*else*/ {
+ __pyx_t_17 = __pyx_v_poiIndex;
+ __pyx_t_4 = (*((double *) ( /* dim=0 */ (__pyx_v_poiValueCol.data + __pyx_t_17 * __pyx_v_poiValueCol.strides[0]) )));
+ if (unlikely(__pyx_v_distanceSqr == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 99, __pyx_L1_error)
+ }
+ __pyx_t_17 = __pyx_v_agentIndex;
+ __pyx_t_16 = 6;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_observationCol.data + __pyx_t_17 * __pyx_v_observationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_observationCol.strides[1]) )) += (__pyx_t_4 / __pyx_v_distanceSqr);
+ }
+ __pyx_L17:;
+ }
+ __pyx_L15:;
+ }
+ }
+ 100:
++101: data["Agent Observations"] = npObservationCol
+if (unlikely(PyObject_SetItem(__pyx_v_data, __pyx_kp_s_Agent_Observations, __pyx_v_npObservationCol) < 0)) __PYX_ERR(0, 101, __pyx_L1_error) +
102:
+ 103: @cython.boundscheck(False) # Deactivate bounds checking
+ 104: @cython.wraparound(False) # Deactivate negative indexing.
++105: cpdef doAgentProcess(data):
+static PyObject *__pyx_pw_4code_14agent_domain_2_3doAgentProcess(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
+static PyObject *__pyx_f_4code_14agent_domain_2_doAgentProcess(PyObject *__pyx_v_data, CYTHON_UNUSED int __pyx_skip_dispatch) {
+ int __pyx_v_number_agents;
+ PyObject *__pyx_v_actionCol = NULL;
+ PyObject *__pyx_v_policyCol = NULL;
+ PyObject *__pyx_v_observationCol = NULL;
+ int __pyx_v_agentIndex;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentProcess", 0);
+/* … */
+ /* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_AddTraceback("code.agent_domain_2.doAgentProcess", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_actionCol);
+ __Pyx_XDECREF(__pyx_v_policyCol);
+ __Pyx_XDECREF(__pyx_v_observationCol);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_4code_14agent_domain_2_3doAgentProcess(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
+static PyObject *__pyx_pw_4code_14agent_domain_2_3doAgentProcess(PyObject *__pyx_self, PyObject *__pyx_v_data) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentProcess (wrapper)", 0);
+ __pyx_r = __pyx_pf_4code_14agent_domain_2_2doAgentProcess(__pyx_self, ((PyObject *)__pyx_v_data));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_4code_14agent_domain_2_2doAgentProcess(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentProcess", 0);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __pyx_f_4code_14agent_domain_2_doAgentProcess(__pyx_v_data, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("code.agent_domain_2.doAgentProcess", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
++106: cdef int number_agents = data['Number of Agents']
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Number_of_Agents); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 106, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_number_agents = __pyx_t_2; +
+107: actionCol = np.zeros((number_agents, 2), dtype = np.float_)
+__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_number_agents); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_INCREF(__pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_2); + __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_actionCol = __pyx_t_6; + __pyx_t_6 = 0; +
+108: policyCol = data["Agent Policies"]
+__pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Policies); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_policyCol = __pyx_t_6; + __pyx_t_6 = 0; +
+109: observationCol = data["Agent Observations"]
+__pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Observations); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 109, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_observationCol = __pyx_t_6; + __pyx_t_6 = 0; +
110: cdef int agentIndex
++111: for agentIndex in range(number_agents):
+ __pyx_t_2 = __pyx_v_number_agents;
+ __pyx_t_7 = __pyx_t_2;
+ for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
+ __pyx_v_agentIndex = __pyx_t_8;
++112: actionCol[agentIndex] = policyCol[agentIndex].get_action(observationCol[agentIndex])
+__pyx_t_4 = __Pyx_GetItemInt(__pyx_v_policyCol, __pyx_v_agentIndex, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get_action); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_observationCol, __pyx_v_agentIndex, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_6 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(__Pyx_SetItemInt(__pyx_v_actionCol, __pyx_v_agentIndex, __pyx_t_6, int, 1, __Pyx_PyInt_From_int, 0, 0, 0) < 0)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } +
+113: data["Agent Actions"] = actionCol
+if (unlikely(PyObject_SetItem(__pyx_v_data, __pyx_kp_s_Agent_Actions, __pyx_v_actionCol) < 0)) __PYX_ERR(0, 113, __pyx_L1_error) +
114:
+ 115: @cython.boundscheck(False) # Deactivate bounds checking
+ 116: @cython.wraparound(False) # Deactivate negative indexing.
++117: cpdef doAgentMove(data):
+static PyObject *__pyx_pw_4code_14agent_domain_2_5doAgentMove(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
+static PyObject *__pyx_f_4code_14agent_domain_2_doAgentMove(PyObject *__pyx_v_data, CYTHON_UNUSED int __pyx_skip_dispatch) {
+ CYTHON_UNUSED float __pyx_v_worldWidth;
+ CYTHON_UNUSED float __pyx_v_worldLength;
+ int __pyx_v_number_agents;
+ __Pyx_memviewslice __pyx_v_agentPositionCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ __Pyx_memviewslice __pyx_v_orientationCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ PyObject *__pyx_v_npActionCol = NULL;
+ __Pyx_memviewslice __pyx_v_actionCol = { 0, 0, { 0 }, { 0 }, { 0 } };
+ int __pyx_v_agentIndex;
+ double __pyx_v_globalFrameMotion0;
+ double __pyx_v_globalFrameMotion1;
+ double __pyx_v_norm;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentMove", 0);
+/* … */
+ /* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_8);
+ __Pyx_AddTraceback("code.agent_domain_2.doAgentMove", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __PYX_XDEC_MEMVIEW(&__pyx_v_agentPositionCol, 1);
+ __PYX_XDEC_MEMVIEW(&__pyx_v_orientationCol, 1);
+ __Pyx_XDECREF(__pyx_v_npActionCol);
+ __PYX_XDEC_MEMVIEW(&__pyx_v_actionCol, 1);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_4code_14agent_domain_2_5doAgentMove(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
+static PyObject *__pyx_pw_4code_14agent_domain_2_5doAgentMove(PyObject *__pyx_self, PyObject *__pyx_v_data) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentMove (wrapper)", 0);
+ __pyx_r = __pyx_pf_4code_14agent_domain_2_4doAgentMove(__pyx_self, ((PyObject *)__pyx_v_data));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_4code_14agent_domain_2_4doAgentMove(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("doAgentMove", 0);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __pyx_f_4code_14agent_domain_2_doAgentMove(__pyx_v_data, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("code.agent_domain_2.doAgentMove", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
++118: cdef float worldWidth = data["World Width"]
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_World_Width); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 118, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_worldWidth = __pyx_t_2; +
+119: cdef float worldLength = data["World Length"]
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_World_Length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_worldLength = __pyx_t_2; +
+120: cdef int number_agents = data['Number of Agents']
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Number_of_Agents); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 120, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_number_agents = __pyx_t_3; +
+121: cdef double[:, :] agentPositionCol = data["Agent Positions"]
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Positions); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 121, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_agentPositionCol = __pyx_t_4; + __pyx_t_4.memview = NULL; + __pyx_t_4.data = NULL; +
+122: cdef double[:, :] orientationCol = data["Agent Orientations"]
+__pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Orientations); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 122, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_orientationCol = __pyx_t_4; + __pyx_t_4.memview = NULL; + __pyx_t_4.data = NULL; +
+123: npActionCol = np.array(data["Agent Actions"]).astype(np.float_)
+__Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_v_data, __pyx_kp_s_Agent_Actions); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_float); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_npActionCol = __pyx_t_1; + __pyx_t_1 = 0; +
+124: npActionCol = np.clip(npActionCol, -1, 1)
+__Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_clip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_3 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_3 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_npActionCol, __pyx_int_neg_1, __pyx_int_1}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_3, 3+__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_npActionCol, __pyx_int_neg_1, __pyx_int_1}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_3, 3+__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(3+__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_npActionCol); + __Pyx_GIVEREF(__pyx_v_npActionCol); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_3, __pyx_v_npActionCol); + __Pyx_INCREF(__pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_3, __pyx_int_neg_1); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_3, __pyx_int_1); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF_SET(__pyx_v_npActionCol, __pyx_t_1); + __pyx_t_1 = 0; +
+125: cdef double[:, :] actionCol = npActionCol
+__pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_npActionCol, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 125, __pyx_L1_error) + __pyx_v_actionCol = __pyx_t_4; + __pyx_t_4.memview = NULL; + __pyx_t_4.data = NULL; +
126:
+ 127: cdef int agentIndex
+ 128:
+ 129: cdef double globalFrameMotion0, globalFrameMotion1, norm
+ 130:
+ 131: # move all agents
++132: for agentIndex in range(number_agents):
+ __pyx_t_3 = __pyx_v_number_agents;
+ __pyx_t_9 = __pyx_t_3;
+ for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
+ __pyx_v_agentIndex = __pyx_t_10;
+ 133:
+ 134: # turn action into global frame motion
++135: globalFrameMotion0 = orientationCol[agentIndex, 0] * actionCol[agentIndex, 0] - orientationCol[agentIndex, 1] * actionCol[agentIndex, 1]
+__pyx_t_11 = __pyx_v_agentIndex; + __pyx_t_12 = 0; + __pyx_t_13 = __pyx_v_agentIndex; + __pyx_t_14 = 0; + __pyx_t_15 = __pyx_v_agentIndex; + __pyx_t_16 = 1; + __pyx_t_17 = __pyx_v_agentIndex; + __pyx_t_18 = 1; + __pyx_v_globalFrameMotion0 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_11 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_12 * __pyx_v_orientationCol.strides[1]) ))) * (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_actionCol.data + __pyx_t_13 * __pyx_v_actionCol.strides[0]) ) + __pyx_t_14 * __pyx_v_actionCol.strides[1]) )))) - ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_15 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_16 * __pyx_v_orientationCol.strides[1]) ))) * (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_actionCol.data + __pyx_t_17 * __pyx_v_actionCol.strides[0]) ) + __pyx_t_18 * __pyx_v_actionCol.strides[1]) ))))); +
+136: globalFrameMotion1 = orientationCol[agentIndex, 0] * actionCol[agentIndex, 1] + orientationCol[agentIndex, 1] * actionCol[agentIndex, 0]
+__pyx_t_18 = __pyx_v_agentIndex; + __pyx_t_17 = 0; + __pyx_t_16 = __pyx_v_agentIndex; + __pyx_t_15 = 1; + __pyx_t_14 = __pyx_v_agentIndex; + __pyx_t_13 = 1; + __pyx_t_12 = __pyx_v_agentIndex; + __pyx_t_11 = 0; + __pyx_v_globalFrameMotion1 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_18 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_17 * __pyx_v_orientationCol.strides[1]) ))) * (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_actionCol.data + __pyx_t_16 * __pyx_v_actionCol.strides[0]) ) + __pyx_t_15 * __pyx_v_actionCol.strides[1]) )))) + ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_14 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_13 * __pyx_v_orientationCol.strides[1]) ))) * (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_actionCol.data + __pyx_t_12 * __pyx_v_actionCol.strides[0]) ) + __pyx_t_11 * __pyx_v_actionCol.strides[1]) ))))); +
137:
+ 138:
+ 139: # globally move and reorient agent
++140: agentPositionCol[agentIndex, 0] += globalFrameMotion0
+__pyx_t_11 = __pyx_v_agentIndex; + __pyx_t_12 = 0; + *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_11 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_12 * __pyx_v_agentPositionCol.strides[1]) )) += __pyx_v_globalFrameMotion0; +
+141: agentPositionCol[agentIndex, 1] += globalFrameMotion1
+__pyx_t_12 = __pyx_v_agentIndex; + __pyx_t_11 = 1; + *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_agentPositionCol.data + __pyx_t_12 * __pyx_v_agentPositionCol.strides[0]) ) + __pyx_t_11 * __pyx_v_agentPositionCol.strides[1]) )) += __pyx_v_globalFrameMotion1; +
142:
++143: if globalFrameMotion0 == 0.0 and globalFrameMotion1 == 0.0:
+ __pyx_t_20 = ((__pyx_v_globalFrameMotion0 == 0.0) != 0);
+ if (__pyx_t_20) {
+ } else {
+ __pyx_t_19 = __pyx_t_20;
+ goto __pyx_L6_bool_binop_done;
+ }
+ __pyx_t_20 = ((__pyx_v_globalFrameMotion1 == 0.0) != 0);
+ __pyx_t_19 = __pyx_t_20;
+ __pyx_L6_bool_binop_done:;
+ if (__pyx_t_19) {
+/* … */
+ goto __pyx_L5;
+ }
++144: orientationCol[agentIndex,0] = 1.0
+__pyx_t_11 = __pyx_v_agentIndex; + __pyx_t_12 = 0; + *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_11 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_12 * __pyx_v_orientationCol.strides[1]) )) = 1.0; +
+145: orientationCol[agentIndex,1] = 0.0
+__pyx_t_12 = __pyx_v_agentIndex; + __pyx_t_11 = 1; + *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_12 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_11 * __pyx_v_orientationCol.strides[1]) )) = 0.0; +
146: else:
++147: norm = sqrt(globalFrameMotion0**2 + globalFrameMotion1 **2)
+ /*else*/ {
+ __pyx_v_norm = sqrt((pow(__pyx_v_globalFrameMotion0, 2.0) + pow(__pyx_v_globalFrameMotion1, 2.0)));
++148: orientationCol[agentIndex,0] = globalFrameMotion0 /norm
+ if (unlikely(__pyx_v_norm == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 148, __pyx_L1_error)
+ }
+ __pyx_t_11 = __pyx_v_agentIndex;
+ __pyx_t_12 = 0;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_11 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_12 * __pyx_v_orientationCol.strides[1]) )) = (__pyx_v_globalFrameMotion0 / __pyx_v_norm);
++149: orientationCol[agentIndex,1] = globalFrameMotion1 /norm
+ if (unlikely(__pyx_v_norm == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "float division");
+ __PYX_ERR(0, 149, __pyx_L1_error)
+ }
+ __pyx_t_12 = __pyx_v_agentIndex;
+ __pyx_t_11 = 1;
+ *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_orientationCol.data + __pyx_t_12 * __pyx_v_orientationCol.strides[0]) ) + __pyx_t_11 * __pyx_v_orientationCol.strides[1]) )) = (__pyx_v_globalFrameMotion1 / __pyx_v_norm);
+ }
+ __pyx_L5:;
+ }
+ 150:
+ 151: # # Check if action moves agent within the world bounds
+ 152: # if agentPositionCol[agentIndex,0] > worldWidth:
+ 153: # agentPositionCol[agentIndex,0] = worldWidth
+ 154: # elif agentPositionCol[agentIndex,0] < 0.0:
+ 155: # agentPositionCol[agentIndex,0] = 0.0
+ 156: #
+ 157: # if agentPositionCol[agentIndex,1] > worldLength:
+ 158: # agentPositionCol[agentIndex,1] = worldLength
+ 159: # elif agentPositionCol[agentIndex,1] < 0.0:
+ 160: # agentPositionCol[agentIndex,1] = 0.0
+ 161:
+ 162:
++163: data["Agent Positions"] = agentPositionCol
+__pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_agentPositionCol, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(PyObject_SetItem(__pyx_v_data, __pyx_kp_s_Agent_Positions, __pyx_t_1) < 0)) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; +
+164: data["Agent Orientations"] = orientationCol
+__pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_orientationCol, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(PyObject_SetItem(__pyx_v_data, __pyx_kp_s_Agent_Orientations, __pyx_t_1) < 0)) __PYX_ERR(0, 164, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; +