pycityagent 2.0.0a65__cp39-cp39-macosx_11_0_arm64.whl → 2.0.0a67__cp39-cp39-macosx_11_0_arm64.whl
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.
- pycityagent/agent/agent.py +157 -57
- pycityagent/agent/agent_base.py +316 -43
- pycityagent/cityagent/bankagent.py +49 -9
- pycityagent/cityagent/blocks/__init__.py +1 -2
- pycityagent/cityagent/blocks/cognition_block.py +54 -31
- pycityagent/cityagent/blocks/dispatcher.py +22 -17
- pycityagent/cityagent/blocks/economy_block.py +46 -32
- pycityagent/cityagent/blocks/mobility_block.py +209 -105
- pycityagent/cityagent/blocks/needs_block.py +101 -54
- pycityagent/cityagent/blocks/other_block.py +42 -33
- pycityagent/cityagent/blocks/plan_block.py +59 -42
- pycityagent/cityagent/blocks/social_block.py +167 -126
- pycityagent/cityagent/blocks/utils.py +13 -6
- pycityagent/cityagent/firmagent.py +17 -35
- pycityagent/cityagent/governmentagent.py +3 -3
- pycityagent/cityagent/initial.py +79 -49
- pycityagent/cityagent/memory_config.py +123 -94
- pycityagent/cityagent/message_intercept.py +0 -4
- pycityagent/cityagent/metrics.py +41 -0
- pycityagent/cityagent/nbsagent.py +24 -36
- pycityagent/cityagent/societyagent.py +9 -4
- pycityagent/cli/wrapper.py +2 -2
- pycityagent/economy/econ_client.py +407 -81
- pycityagent/environment/__init__.py +0 -3
- pycityagent/environment/sim/__init__.py +0 -3
- pycityagent/environment/sim/aoi_service.py +2 -2
- pycityagent/environment/sim/client.py +3 -31
- pycityagent/environment/sim/clock_service.py +2 -2
- pycityagent/environment/sim/lane_service.py +8 -8
- pycityagent/environment/sim/light_service.py +8 -8
- pycityagent/environment/sim/pause_service.py +9 -10
- pycityagent/environment/sim/person_service.py +20 -20
- pycityagent/environment/sim/road_service.py +2 -2
- pycityagent/environment/sim/sim_env.py +21 -5
- pycityagent/environment/sim/social_service.py +4 -4
- pycityagent/environment/simulator.py +249 -27
- pycityagent/environment/utils/__init__.py +2 -2
- pycityagent/environment/utils/geojson.py +2 -2
- pycityagent/environment/utils/grpc.py +4 -4
- pycityagent/environment/utils/map_utils.py +2 -2
- pycityagent/llm/embeddings.py +147 -28
- pycityagent/llm/llm.py +178 -111
- pycityagent/llm/llmconfig.py +5 -0
- pycityagent/llm/utils.py +4 -0
- pycityagent/memory/__init__.py +0 -4
- pycityagent/memory/const.py +2 -2
- pycityagent/memory/faiss_query.py +140 -61
- pycityagent/memory/memory.py +394 -91
- pycityagent/memory/memory_base.py +140 -34
- pycityagent/memory/profile.py +13 -13
- pycityagent/memory/self_define.py +13 -13
- pycityagent/memory/state.py +14 -14
- pycityagent/message/message_interceptor.py +253 -3
- pycityagent/message/messager.py +133 -6
- pycityagent/metrics/mlflow_client.py +47 -4
- pycityagent/pycityagent-sim +0 -0
- pycityagent/pycityagent-ui +0 -0
- pycityagent/simulation/__init__.py +3 -2
- pycityagent/simulation/agentgroup.py +150 -54
- pycityagent/simulation/simulation.py +276 -66
- pycityagent/survey/manager.py +45 -3
- pycityagent/survey/models.py +42 -2
- pycityagent/tools/__init__.py +1 -2
- pycityagent/tools/tool.py +93 -69
- pycityagent/utils/avro_schema.py +2 -2
- pycityagent/utils/parsers/code_block_parser.py +1 -1
- pycityagent/utils/parsers/json_parser.py +2 -2
- pycityagent/utils/parsers/parser_base.py +2 -2
- pycityagent/workflow/block.py +64 -13
- pycityagent/workflow/prompt.py +31 -23
- pycityagent/workflow/trigger.py +91 -24
- {pycityagent-2.0.0a65.dist-info → pycityagent-2.0.0a67.dist-info}/METADATA +2 -2
- pycityagent-2.0.0a67.dist-info/RECORD +97 -0
- pycityagent/environment/interact/__init__.py +0 -0
- pycityagent/environment/interact/interact.py +0 -198
- pycityagent/environment/message/__init__.py +0 -0
- pycityagent/environment/sence/__init__.py +0 -0
- pycityagent/environment/sence/static.py +0 -416
- pycityagent/environment/sidecar/__init__.py +0 -8
- pycityagent/environment/sidecar/sidecarv2.py +0 -109
- pycityagent/environment/sim/economy_services.py +0 -192
- pycityagent/metrics/utils/const.py +0 -0
- pycityagent-2.0.0a65.dist-info/RECORD +0 -105
- {pycityagent-2.0.0a65.dist-info → pycityagent-2.0.0a67.dist-info}/LICENSE +0 -0
- {pycityagent-2.0.0a65.dist-info → pycityagent-2.0.0a67.dist-info}/WHEEL +0 -0
- {pycityagent-2.0.0a65.dist-info → pycityagent-2.0.0a67.dist-info}/entry_points.txt +0 -0
- {pycityagent-2.0.0a65.dist-info → pycityagent-2.0.0a67.dist-info}/top_level.txt +0 -0
@@ -1,13 +1,10 @@
|
|
1
1
|
"""Environment"""
|
2
2
|
|
3
|
-
from .sence.static import LEVEL_ONE_PRE, POI_TYPE_DICT
|
4
3
|
from .sim import AoiService, PersonService
|
5
4
|
from .simulator import Simulator
|
6
5
|
|
7
6
|
__all__ = [
|
8
7
|
"Simulator",
|
9
|
-
"POI_TYPE_DICT",
|
10
|
-
"LEVEL_ONE_PRE",
|
11
8
|
"PersonService",
|
12
9
|
"AoiService",
|
13
10
|
]
|
@@ -7,7 +7,6 @@ from .person_service import PersonService
|
|
7
7
|
from .aoi_service import AoiService
|
8
8
|
from .client import CityClient
|
9
9
|
from .clock_service import ClockService
|
10
|
-
from .economy_services import EconomyOrgService, EconomyPersonService
|
11
10
|
from .lane_service import LaneService
|
12
11
|
from .road_service import RoadService
|
13
12
|
from .social_service import SocialService
|
@@ -22,8 +21,6 @@ __all__ = [
|
|
22
21
|
"LaneService",
|
23
22
|
"RoadService",
|
24
23
|
"SocialService",
|
25
|
-
"EconomyPersonService",
|
26
|
-
"EconomyOrgService",
|
27
24
|
"LightService",
|
28
25
|
"ControlSimEnv",
|
29
26
|
]
|
@@ -27,10 +27,10 @@ class AoiService:
|
|
27
27
|
获取AOI信息
|
28
28
|
get AOI information
|
29
29
|
|
30
|
-
Args
|
30
|
+
- **Args**:
|
31
31
|
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetAoiRequest
|
32
32
|
|
33
|
-
Returns
|
33
|
+
- **Returns**:
|
34
34
|
- https://cityproto.sim.fiblab.net/#city.map.v2.GetAoiResponse
|
35
35
|
"""
|
36
36
|
if type(req) != aoi_service.GetAoiRequest:
|
@@ -1,14 +1,12 @@
|
|
1
1
|
import warnings
|
2
2
|
import grpc
|
3
3
|
|
4
|
-
from ..sidecar import OnlyClientSidecar
|
5
4
|
from .clock_service import ClockService
|
6
5
|
from .person_service import PersonService
|
7
6
|
from .aoi_service import AoiService
|
8
7
|
from .lane_service import LaneService
|
9
8
|
from .road_service import RoadService
|
10
9
|
from .social_service import SocialService
|
11
|
-
from .economy_services import EconomyPersonService, EconomyOrgService
|
12
10
|
from .light_service import LightService
|
13
11
|
from .pause_service import PauseService
|
14
12
|
from ..utils.grpc import create_aio_channel
|
@@ -30,9 +28,9 @@ class CityClient:
|
|
30
28
|
secure: bool = False,
|
31
29
|
):
|
32
30
|
"""
|
33
|
-
Args
|
34
|
-
|
35
|
-
|
31
|
+
- **Args**:
|
32
|
+
- `url` (`str`): 模拟器server的地址。The address of the emulator server.
|
33
|
+
- `secure` (`bool`, `optional`): 是否使用安全连接. Defaults to False. Whether to use a secure connection. Defaults to False.
|
36
34
|
"""
|
37
35
|
aio_channel = create_aio_channel(url, secure)
|
38
36
|
self._clock_service = ClockService(aio_channel)
|
@@ -41,19 +39,9 @@ class CityClient:
|
|
41
39
|
self._aoi_service = AoiService(aio_channel)
|
42
40
|
self._road_service = RoadService(aio_channel)
|
43
41
|
self._social_service = SocialService(aio_channel)
|
44
|
-
self._economy_person_service = EconomyPersonService(aio_channel)
|
45
|
-
self._economy_org_service = EconomyOrgService(aio_channel)
|
46
42
|
self._light_service = LightService(aio_channel)
|
47
43
|
self._pause_service = PauseService(aio_channel)
|
48
44
|
|
49
|
-
@staticmethod
|
50
|
-
def from_sidecar(sidecar: OnlyClientSidecar, name: str = NAME):
|
51
|
-
"""
|
52
|
-
从sidecar中创建CityClient
|
53
|
-
Create CityClient from sidecar
|
54
|
-
"""
|
55
|
-
return CityClient(sidecar.wait_url(name))
|
56
|
-
|
57
45
|
@property
|
58
46
|
def clock_service(self):
|
59
47
|
"""
|
@@ -110,22 +98,6 @@ class CityClient:
|
|
110
98
|
"""
|
111
99
|
return self._social_service
|
112
100
|
|
113
|
-
@property
|
114
|
-
def economy_person_service(self):
|
115
|
-
"""
|
116
|
-
模拟器经济服务(个人)子模块
|
117
|
-
Simulator economic service (personal) submodule
|
118
|
-
"""
|
119
|
-
return self._economy_person_service
|
120
|
-
|
121
|
-
@property
|
122
|
-
def economy_org_service(self):
|
123
|
-
"""
|
124
|
-
模拟器经济服务(组织)子模块
|
125
|
-
Simulator economic service (organizational) submodule
|
126
|
-
"""
|
127
|
-
return self._economy_org_service
|
128
|
-
|
129
101
|
@property
|
130
102
|
def light_service(self):
|
131
103
|
"""
|
@@ -29,10 +29,10 @@ class ClockService:
|
|
29
29
|
获取当前的模拟时间请求
|
30
30
|
Getting current simulation clock
|
31
31
|
|
32
|
-
Args
|
32
|
+
- **Args**:
|
33
33
|
- req (dict): https://cityproto.readthedocs.io/en/latest/docs.html#nowrequest
|
34
34
|
|
35
|
-
Returns
|
35
|
+
- **Returns**:
|
36
36
|
- https://cityproto.readthedocs.io/en/latest/docs.html#nowresponse
|
37
37
|
"""
|
38
38
|
if type(req) != clock_service.NowRequest:
|
@@ -27,10 +27,10 @@ class LaneService:
|
|
27
27
|
获取Lane的信息
|
28
28
|
Get Lane's information
|
29
29
|
|
30
|
-
Args
|
30
|
+
- **Args**:
|
31
31
|
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneRequest
|
32
32
|
|
33
|
-
Returns
|
33
|
+
- **Returns**:
|
34
34
|
- https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneResponse
|
35
35
|
"""
|
36
36
|
if type(req) != lane_service.GetLaneRequest:
|
@@ -47,10 +47,10 @@ class LaneService:
|
|
47
47
|
设置Lane的最大速度(限速)
|
48
48
|
Set the maximum speed of Lane (speed limit)
|
49
49
|
|
50
|
-
Args
|
50
|
+
- **Args**:
|
51
51
|
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneMaxVRequest
|
52
52
|
|
53
|
-
Returns
|
53
|
+
- **Returns**:
|
54
54
|
- https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneMaxVResponse
|
55
55
|
"""
|
56
56
|
if type(req) != lane_service.SetLaneMaxVRequest:
|
@@ -71,10 +71,10 @@ class LaneService:
|
|
71
71
|
设置Lane的限制
|
72
72
|
Set the restriction of Lane
|
73
73
|
|
74
|
-
Args
|
74
|
+
- **Args**:
|
75
75
|
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneRestrictionRequest
|
76
76
|
|
77
|
-
Returns
|
77
|
+
- **Returns**:
|
78
78
|
- https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneRestrictionResponse
|
79
79
|
"""
|
80
80
|
if type(req) != lane_service.SetLaneRestrictionRequest:
|
@@ -96,10 +96,10 @@ class LaneService:
|
|
96
96
|
获取特定区域内的Lane的信息
|
97
97
|
Get lane information in a specific region
|
98
98
|
|
99
|
-
Args
|
99
|
+
- **Args**:
|
100
100
|
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneByLongLatBBoxRequest
|
101
101
|
|
102
|
-
Returns
|
102
|
+
- **Returns**:
|
103
103
|
- https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneByLongLatBBoxResponse
|
104
104
|
"""
|
105
105
|
if type(req) != lane_service.GetLaneByLongLatBBoxRequest:
|
@@ -32,10 +32,10 @@ class LightService:
|
|
32
32
|
获取路口的红绿灯信息
|
33
33
|
Get traffic light information
|
34
34
|
|
35
|
-
Args
|
35
|
+
- **Args**:
|
36
36
|
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.GetTrafficLightRequest
|
37
37
|
|
38
|
-
Returns
|
38
|
+
- **Returns**:
|
39
39
|
- https://cityproto.sim.fiblab.net/#city.traffic.v1.GetTrafficLightResponse
|
40
40
|
"""
|
41
41
|
if type(req) != light_service.GetTrafficLightRequest:
|
@@ -57,10 +57,10 @@ class LightService:
|
|
57
57
|
设置路口的红绿灯信息
|
58
58
|
Set traffic light information
|
59
59
|
|
60
|
-
Args
|
60
|
+
- **Args**:
|
61
61
|
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightRequest
|
62
62
|
|
63
|
-
Returns
|
63
|
+
- **Returns**:
|
64
64
|
- https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightResponse
|
65
65
|
"""
|
66
66
|
if type(req) != light_service.SetTrafficLightRequest:
|
@@ -82,10 +82,10 @@ class LightService:
|
|
82
82
|
设置路口的红绿灯相位
|
83
83
|
Set traffic light phase
|
84
84
|
|
85
|
-
Args
|
85
|
+
- **Args**:
|
86
86
|
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightPhaseRequest
|
87
87
|
|
88
|
-
Returns
|
88
|
+
- **Returns**:
|
89
89
|
- https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightPhaseResponse
|
90
90
|
"""
|
91
91
|
if type(req) != light_service.SetTrafficLightPhaseRequest:
|
@@ -107,10 +107,10 @@ class LightService:
|
|
107
107
|
设置路口的红绿灯状态
|
108
108
|
Set traffic light status
|
109
109
|
|
110
|
-
Args
|
110
|
+
- **Args**:
|
111
111
|
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightStatusRequest
|
112
112
|
|
113
|
-
Returns
|
113
|
+
- **Returns**:
|
114
114
|
- https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightStatusResponse
|
115
115
|
"""
|
116
116
|
if type(req) != light_service.SetTrafficLightStatusRequest:
|
@@ -1,8 +1,7 @@
|
|
1
1
|
from collections.abc import Awaitable, Coroutine
|
2
|
-
from typing import Any,
|
2
|
+
from typing import Any, Union, cast
|
3
3
|
|
4
4
|
import grpc
|
5
|
-
from google.protobuf.json_format import ParseDict
|
6
5
|
from pycityproto.city.pause.v1 import pause_service_pb2 as pause_service
|
7
6
|
from pycityproto.city.pause.v1 import pause_service_pb2_grpc as pause_grpc
|
8
7
|
|
@@ -22,15 +21,15 @@ class PauseService:
|
|
22
21
|
|
23
22
|
async def pause(
|
24
23
|
self,
|
25
|
-
) ->
|
24
|
+
) -> Awaitable[Union[dict[str, Any], pause_service.PauseResponse]]:
|
26
25
|
"""
|
27
26
|
暂停模拟
|
28
27
|
Pause the simulation
|
29
28
|
|
30
|
-
Args
|
29
|
+
- **Args**:
|
31
30
|
- req (dict): https://cityproto.readthedocs.io/en/latest/docs.html#pauserequest
|
32
31
|
|
33
|
-
Returns
|
32
|
+
- **Returns**:
|
34
33
|
- https://cityproto.readthedocs.io/en/latest/docs.html#pauseresponse
|
35
34
|
"""
|
36
35
|
req = pause_service.PauseRequest()
|
@@ -38,19 +37,19 @@ class PauseService:
|
|
38
37
|
Awaitable[pause_service.PauseResponse],
|
39
38
|
self._aio_stub.Pause(req),
|
40
39
|
)
|
41
|
-
return
|
40
|
+
return res
|
42
41
|
|
43
42
|
async def resume(
|
44
43
|
self,
|
45
|
-
) ->
|
44
|
+
) -> Awaitable[Union[dict[str, Any], pause_service.ResumeResponse]]:
|
46
45
|
"""
|
47
46
|
恢复模拟
|
48
47
|
Resume the simulation
|
49
48
|
|
50
|
-
Args
|
49
|
+
- **Args**:
|
51
50
|
- req (dict): https://cityproto.readthedocs.io/en/latest/docs.html#resumerequest
|
52
51
|
|
53
|
-
Returns
|
52
|
+
- **Returns**:
|
54
53
|
- https://cityproto.readthedocs.io/en/latest/docs.html#resumeresponse
|
55
54
|
"""
|
56
55
|
req = pause_service.ResumeRequest()
|
@@ -58,4 +57,4 @@ class PauseService:
|
|
58
57
|
Awaitable[pause_service.ResumeResponse],
|
59
58
|
self._aio_stub.Resume(req),
|
60
59
|
)
|
61
|
-
return
|
60
|
+
return res
|
@@ -57,10 +57,10 @@ class PersonService:
|
|
57
57
|
获取person信息
|
58
58
|
Get person information
|
59
59
|
|
60
|
-
Args
|
60
|
+
- **Args**:
|
61
61
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.GetPersonRequest
|
62
62
|
|
63
|
-
Returns
|
63
|
+
- **Returns**:
|
64
64
|
- https://cityproto.sim.fiblab.net/#city.person.v2.GetPersonResponse
|
65
65
|
"""
|
66
66
|
if type(req) != person_service.GetPersonRequest:
|
@@ -79,10 +79,10 @@ class PersonService:
|
|
79
79
|
新增person
|
80
80
|
Add a new person
|
81
81
|
|
82
|
-
Args
|
82
|
+
- **Args**:
|
83
83
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.AddPersonRequest
|
84
84
|
|
85
|
-
Returns
|
85
|
+
- **Returns**:
|
86
86
|
- https://cityproto.sim.fiblab.net/#city.person.v2.AddPersonResponse
|
87
87
|
"""
|
88
88
|
if type(req) != person_service.AddPersonRequest:
|
@@ -101,10 +101,10 @@ class PersonService:
|
|
101
101
|
修改person的schedule
|
102
102
|
set person's schedule
|
103
103
|
|
104
|
-
Args
|
104
|
+
- **Args**:
|
105
105
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.SetScheduleRequest
|
106
106
|
|
107
|
-
Returns
|
107
|
+
- **Returns**:
|
108
108
|
- https://cityproto.sim.fiblab.net/#city.person.v2.SetScheduleResponse
|
109
109
|
"""
|
110
110
|
if type(req) != person_service.SetScheduleRequest:
|
@@ -124,10 +124,10 @@ class PersonService:
|
|
124
124
|
获取多个person信息
|
125
125
|
Get information of multiple persons
|
126
126
|
|
127
|
-
Args
|
127
|
+
- **Args**:
|
128
128
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.GetPersonsRequest
|
129
129
|
|
130
|
-
Returns
|
130
|
+
- **Returns**:
|
131
131
|
- https://cityproto.sim.fiblab.net/#city.person.v2.GetPersonsResponse
|
132
132
|
"""
|
133
133
|
if type(req) != person_service.GetPersonsRequest:
|
@@ -149,10 +149,10 @@ class PersonService:
|
|
149
149
|
获取特定区域内的person
|
150
150
|
Get persons in a specific region
|
151
151
|
|
152
|
-
Args
|
152
|
+
- **Args**:
|
153
153
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.GetPersonByLongLatBBoxRequest
|
154
154
|
|
155
|
-
Returns
|
155
|
+
- **Returns**:
|
156
156
|
- https://cityproto.sim.fiblab.net/#city.person.v2.GetPersonByLongLatBBoxResponse
|
157
157
|
"""
|
158
158
|
if type(req) != person_service.GetPersonByLongLatBBoxRequest:
|
@@ -174,10 +174,10 @@ class PersonService:
|
|
174
174
|
获取所有车辆
|
175
175
|
Get all vehicles
|
176
176
|
|
177
|
-
Args
|
177
|
+
- **Args**:
|
178
178
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.GetAllVehiclesRequest
|
179
179
|
|
180
|
-
Returns
|
180
|
+
- **Returns**:
|
181
181
|
- https://cityproto.sim.fiblab.net/#city.person.v2.GetAllVehiclesResponse
|
182
182
|
"""
|
183
183
|
if type(req) != person_service.GetAllVehiclesRequest:
|
@@ -199,10 +199,10 @@ class PersonService:
|
|
199
199
|
重置人的位置(将停止当前正在进行的出行,转为sleep状态)
|
200
200
|
Reset person's position (stop the current trip and switch to sleep status)
|
201
201
|
|
202
|
-
Args
|
202
|
+
- **Args**:
|
203
203
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.ResetPersonPositionRequest
|
204
204
|
|
205
|
-
Returns
|
205
|
+
- **Returns**:
|
206
206
|
- https://cityproto.sim.fiblab.net/#city.person.v2.ResetPersonPositionResponse
|
207
207
|
"""
|
208
208
|
if type(req) != person_service.ResetPersonPositionRequest:
|
@@ -226,10 +226,10 @@ class PersonService:
|
|
226
226
|
设置由外部控制行为的vehicle
|
227
227
|
Set controlled vehicle ID
|
228
228
|
|
229
|
-
Args
|
229
|
+
- **Args**:
|
230
230
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.SetControlledVehicleIDsRequest
|
231
231
|
|
232
|
-
Returns
|
232
|
+
- **Returns**:
|
233
233
|
- https://cityproto.sim.fiblab.net/#city.person.v2.SetControlledVehicleIDsResponse
|
234
234
|
"""
|
235
235
|
if type(req) != person_service.SetControlledVehicleIDsRequest:
|
@@ -253,10 +253,10 @@ class PersonService:
|
|
253
253
|
获取由外部控制行为的vehicle的环境信息
|
254
254
|
Fetch controlled vehicle environment information
|
255
255
|
|
256
|
-
Args
|
256
|
+
- **Args**:
|
257
257
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.FetchControlledVehicleEnvsRequest
|
258
258
|
|
259
|
-
Returns
|
259
|
+
- **Returns**:
|
260
260
|
- https://cityproto.sim.fiblab.net/#city.person.v2.FetchControlledVehicleEnvsResponse
|
261
261
|
"""
|
262
262
|
if type(req) != person_service.FetchControlledVehicleEnvsRequest:
|
@@ -280,10 +280,10 @@ class PersonService:
|
|
280
280
|
设置由外部控制行为的vehicle的行为
|
281
281
|
Set controlled vehicle actions
|
282
282
|
|
283
|
-
Args
|
283
|
+
- **Args**:
|
284
284
|
- req (dict): https://cityproto.sim.fiblab.net/#city.person.v2.SetControlledVehicleActionsRequest
|
285
285
|
|
286
|
-
Returns
|
286
|
+
- **Returns**:
|
287
287
|
- https://cityproto.sim.fiblab.net/#city.person.v2.SetControlledVehicleActionsResponse
|
288
288
|
"""
|
289
289
|
if type(req) != person_service.SetControlledVehicleActionsRequest:
|
@@ -27,10 +27,10 @@ class RoadService:
|
|
27
27
|
查询道路信息
|
28
28
|
Query road information
|
29
29
|
|
30
|
-
Args
|
30
|
+
- **Args**:
|
31
31
|
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetRoadRequest
|
32
32
|
|
33
|
-
Returns
|
33
|
+
- **Returns**:
|
34
34
|
- https://cityproto.sim.fiblab.net/#city.map.v2.GetRoadResponse
|
35
35
|
"""
|
36
36
|
if type(req) != road_service.GetRoadRequest:
|
@@ -3,7 +3,7 @@ import logging
|
|
3
3
|
import os
|
4
4
|
import time
|
5
5
|
import warnings
|
6
|
-
from subprocess import
|
6
|
+
from subprocess import Popen
|
7
7
|
from typing import Optional
|
8
8
|
|
9
9
|
from pycitydata.map import Map
|
@@ -46,7 +46,6 @@ class ControlSimEnv:
|
|
46
46
|
self,
|
47
47
|
task_name: str,
|
48
48
|
map_file: str,
|
49
|
-
# person_file,
|
50
49
|
start_step: int,
|
51
50
|
total_step: int,
|
52
51
|
log_dir: str,
|
@@ -54,9 +53,15 @@ class ControlSimEnv:
|
|
54
53
|
timeout: int = 5,
|
55
54
|
sim_addr: Optional[str] = None,
|
56
55
|
):
|
56
|
+
"""
|
57
|
+
A control environment for managing a pycityagent-sim process.
|
58
|
+
|
59
|
+
- **Description**:
|
60
|
+
- This class sets up and manages a simulation environment using the specified parameters.
|
61
|
+
- It can start a new simulation process or connect to an existing one.
|
62
|
+
"""
|
57
63
|
self._task_name = task_name
|
58
64
|
self._map_file = map_file
|
59
|
-
# self._person_file = person_file
|
60
65
|
self._start_step = start_step
|
61
66
|
self._total_step = total_step
|
62
67
|
self._log_dir = log_dir
|
@@ -80,8 +85,16 @@ class ControlSimEnv:
|
|
80
85
|
sim_addr: Optional[str] = None,
|
81
86
|
):
|
82
87
|
"""
|
83
|
-
|
84
|
-
|
88
|
+
Reset the simulation environment by either starting a new simulation process or connecting to an existing one.
|
89
|
+
|
90
|
+
- **Args**:
|
91
|
+
- `sim_addr` (`Optional[str]`): Address of an existing simulation to connect to. If `None`, a new simulation is started.
|
92
|
+
|
93
|
+
- **Returns**:
|
94
|
+
- `str`: The address of the simulation server.
|
95
|
+
|
96
|
+
- **Raises**:
|
97
|
+
- `AssertionError`: If trying to start a new simulation when one is already running.
|
85
98
|
"""
|
86
99
|
if sim_addr is None:
|
87
100
|
# 启动pycityagent-sim
|
@@ -123,6 +136,9 @@ class ControlSimEnv:
|
|
123
136
|
return sim_addr
|
124
137
|
|
125
138
|
def close(self):
|
139
|
+
"""
|
140
|
+
Terminate the simulation process if it's running.
|
141
|
+
"""
|
126
142
|
if self._sim_proc is not None:
|
127
143
|
self._sim_proc.terminate()
|
128
144
|
sim_code = self._sim_proc.wait()
|
@@ -27,10 +27,10 @@ class SocialService:
|
|
27
27
|
发送消息
|
28
28
|
Send message
|
29
29
|
|
30
|
-
Args
|
30
|
+
- **Args**:
|
31
31
|
- req (dict): https://cityproto.sim.fiblab.net/#city.social.v1.SendRequest
|
32
32
|
|
33
|
-
Returns
|
33
|
+
- **Returns**:
|
34
34
|
- https://cityproto.sim.fiblab.net/#city.social.v1.SendResponse
|
35
35
|
"""
|
36
36
|
if type(req) != social_service.SendRequest:
|
@@ -45,10 +45,10 @@ class SocialService:
|
|
45
45
|
接收消息
|
46
46
|
Receive message
|
47
47
|
|
48
|
-
Args
|
48
|
+
- **Args**:
|
49
49
|
- req (dict): https://cityproto.sim.fiblab.net/#city.social.v1.ReceiveRequest
|
50
50
|
|
51
|
-
Returns
|
51
|
+
- **Returns**:
|
52
52
|
- https://cityproto.sim.fiblab.net/#city.social.v1.ReceiveResponse
|
53
53
|
"""
|
54
54
|
if type(req) != social_service.ReceiveRequest:
|