Signal8 0.2__tar.gz → 0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of Signal8 might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Signal8
3
- Version: 0.2
3
+ Version: 0.5
4
4
  Summary: A multi-agent environment inspired by the Lewis Signaling Game, featuring eight unique problem configurations with both static and dynamic adversaries.
5
5
  Home-page: https://github.com/ethanmclark1/signal8
6
6
  Author: Ethan Clark
@@ -0,0 +1,153 @@
1
+ import math
2
+ import numpy as np
3
+
4
+ from gymnasium.utils import EzPickle
5
+ from .utils.scenario import BaseScenario
6
+ from .utils.core import Agent, Landmark, World, Action
7
+ from .utils.simple_env import SimpleEnv, make_env
8
+ from .utils.problems import get_problem, get_problem_list
9
+
10
+ class raw_env(SimpleEnv, EzPickle):
11
+ def __init__(
12
+ self,
13
+ agent_radius=0.1,
14
+ goal_radius=0.1,
15
+ adversary_radius=0.1,
16
+ num_adversaries=4,
17
+ has_dynamic_adversaries=False,
18
+ max_cycles=500,
19
+ continuous_actions=False,
20
+ render_mode="human"
21
+ ):
22
+
23
+ scenario = Scenario()
24
+ world = scenario.make_world(
25
+ agent_radius,
26
+ goal_radius,
27
+ num_adversaries,
28
+ adversary_radius,
29
+ has_dynamic_adversaries
30
+ )
31
+
32
+ super().__init__(
33
+ scenario=scenario,
34
+ world=world,
35
+ render_mode=render_mode,
36
+ max_cycles=max_cycles,
37
+ continuous_actions=continuous_actions,
38
+ )
39
+
40
+ self.metadata["agent_radius"] = agent_radius
41
+ self.metadata["goal_radius"] = goal_radius
42
+ self.metadata["num_adversaries"] = num_adversaries
43
+ self.metadata["adversary_radius"] = adversary_radius
44
+
45
+ env = make_env(raw_env)
46
+
47
+ class Scenario(BaseScenario):
48
+ def make_world(self, agent_radius, goal_radius, num_adversaries, adversary_radius, has_dynamic_adversaries):
49
+ world = World(has_dynamic_adversaries)
50
+ world.problem_scenarios = get_problem_list()
51
+
52
+ num_dynamic_adversaries = math.floor(num_adversaries / 2) if has_dynamic_adversaries else 0
53
+ num_agents = num_dynamic_adversaries + 1
54
+
55
+ world.agents = [Agent() for _ in range(num_agents)]
56
+ for i, agent in enumerate(world.agents):
57
+ agent.adversary = True if i > 0 else False
58
+ base_name = "adversary" if agent.adversary else "agent"
59
+ base_index = i - 1 if agent.adversary else 0
60
+ agent.name = f"{base_name}_{base_index}"
61
+ agent.collide = False
62
+ agent.silent = True
63
+ agent.blind = agent.adversary
64
+ agent.size = agent_radius
65
+
66
+ world.landmarks = [Landmark() for _ in range(num_adversaries - num_dynamic_adversaries + 1)]
67
+ world.landmarks[0].name = "goal_0"
68
+ world.landmarks[0].collide = False
69
+ world.landmarks[0].movable = False
70
+ world.landmarks[0].size = goal_radius
71
+
72
+ for i, landmark in enumerate(world.landmarks[1:]):
73
+ landmark.name = f"obstacle_{i}"
74
+ landmark.collide = False
75
+ landmark.size = adversary_radius
76
+
77
+ return world
78
+
79
+ def reset_world(self, world, np_random, problem_name="v_cluster"):
80
+ self.get_problem_scenario(world, problem_name)
81
+ world.problem_name = problem_name
82
+
83
+ # set state and color of both agents and landmarks
84
+ for i, agent in enumerate(world.agents):
85
+ if agent.adversary:
86
+ agent.color = np.array([0.5, 0, 0])
87
+ agent.state.p_vel = np.zeros(world.dim_p)
88
+ agent.state.p_pos = np_random.uniform(*zip(*world.dynamic_adversarial_constr[(i+1) % len(world.dynamic_adversarial_constr)]))
89
+ agent.action_callback = self.get_scripted_action
90
+ else:
91
+ agent.color = np.array([0, 0.8, 0])
92
+ agent.state.p_vel = np.zeros(world.dim_p)
93
+ agent.state.p_pos = np_random.uniform(*zip(*world.start_constr))
94
+ agent.goal = world.landmarks[0]
95
+ agent.goal.color = np.array([0, 0, 0.8])
96
+ agent.goal.state.p_vel = np.zeros(world.dim_p)
97
+ agent.goal.state.p_pos = np_random.uniform(*zip(*world.goal_constr))
98
+
99
+ for landmark in world.landmarks[1:]:
100
+ landmark.color = np.array([0.2, 0.2, 0.2])
101
+ landmark.state.p_vel = np.zeros(world.dim_p)
102
+ landmark.state.p_pos = np_random.uniform(*zip(*world.static_adversarial_constr))
103
+
104
+ # Do not need to implement this function
105
+ def reward(self, agent, world):
106
+ return 0
107
+
108
+ def observation(self, agent, world):
109
+ return np.concatenate((agent.state.p_pos, agent.state.p_vel))
110
+
111
+ # Get constraints on entities given the problem name
112
+ def get_problem_scenario(self, world, problem_name):
113
+ problem = get_problem(problem_name, world.has_dynamic_adversaries)
114
+ world.start_constr = problem['start']
115
+ world.goal_constr = problem['goal']
116
+ world.static_adversarial_constr = problem['static_adversary']
117
+
118
+ if world.has_dynamic_adversaries:
119
+ world.dynamic_adversarial_constr = problem['dynamic_adversary']
120
+
121
+ # Get scripted action for adversarial agents s.t. they move in a straight line along their constraint
122
+ def get_scripted_action(self, agent, world):
123
+ action = Action()
124
+ action.u = np.zeros(world.dim_p)
125
+ action.c = np.zeros(world.dim_c)
126
+
127
+ constr = world.dynamic_adversarial_constr[int(agent.name[-1])]
128
+ constr_size = [(abs(point[0]) + abs(point[1])) for point in constr]
129
+ dimension = 'horizontal' if constr_size[0] > constr_size[1] else 'vertical'
130
+
131
+ # Always start off moving in the positive direction
132
+ if dimension == 'horizontal':
133
+ if (agent.state.p_vel == 0).all():
134
+ action.u[0] = +1.0
135
+ else: # If moving, continue in the direction of velocity
136
+ if agent.state.p_pos[0] <= constr[0][0]: # If at left constraint, move right
137
+ action.u[0] = +1.0
138
+ elif agent.state.p_pos[0] >= constr[1][0]: # If at right constraint, move left
139
+ action.u[0] = -1.0
140
+ else: # Otherwise, follow the direction of velocity
141
+ action.u[0] = np.sign(agent.state.p_vel[0])
142
+ else:
143
+ if (agent.state.p_vel == 0).all():
144
+ action.u[1] = +1.0
145
+ else: # If moving, continue in the direction of velocity
146
+ if agent.state.p_pos[1] <= constr[0][1]: # If at bottom constraint, move up
147
+ action.u[1] = +1.0
148
+ elif agent.state.p_pos[1] >= constr[1][1]: # If at top constraint, move down
149
+ action.u[1] = -1.0
150
+ else: # Otherwise, follow the direction of velocity
151
+ action.u[1] = np.sign(agent.state.p_vel[1])
152
+
153
+ return action
File without changes
@@ -0,0 +1,4 @@
1
+ import Signal8
2
+
3
+ env = Signal8.env(has_dynamic_adversaries=True)
4
+ env.reset(options={"problem_name": "v_cluster"})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Signal8
3
- Version: 0.2
3
+ Version: 0.5
4
4
  Summary: A multi-agent environment inspired by the Lewis Signaling Game, featuring eight unique problem configurations with both static and dynamic adversaries.
5
5
  Home-page: https://github.com/ethanmclark1/signal8
6
6
  Author: Ethan Clark
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ Signal8/Signal8.py
5
+ Signal8/__init__.py
6
+ Signal8/main.py
7
+ Signal8.egg-info/PKG-INFO
8
+ Signal8.egg-info/SOURCES.txt
9
+ Signal8.egg-info/dependency_links.txt
10
+ Signal8.egg-info/top_level.txt
11
+ signal8.egg-info/PKG-INFO
12
+ signal8.egg-info/SOURCES.txt
13
+ signal8.egg-info/dependency_links.txt
14
+ signal8.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ Signal8
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="Signal8",
5
- version="0.2",
5
+ version="0.5",
6
6
  packages=find_packages(),
7
7
  author="Ethan Clark",
8
8
  author_email="eclark715@gmail.com.com",
@@ -1,7 +0,0 @@
1
- LICENSE
2
- README.md
3
- setup.py
4
- Signal8.egg-info/PKG-INFO
5
- Signal8.egg-info/SOURCES.txt
6
- Signal8.egg-info/dependency_links.txt
7
- Signal8.egg-info/top_level.txt
@@ -1 +0,0 @@
1
-
File without changes
File without changes
File without changes