Proposed Base Class architecture#47
Draft
StefanHamm wants to merge 7 commits intoTUDelft-CNS-ATM:mainfrom
Draft
Conversation
…Waypoints to WaypointsMixin, and HasPolygons to PolygonMixin
Author
|
Added Observer pattern for overlay underlay drawing. Overlay get registered on init as callback. Drawbacks: E.g. each mixin has its own function how to draw a intruder, how to draw the polygon, how to draw the agent, etc. In the end render_world calls all render calls from the Mixins. Could be similar made as observer pattern as overlays and underlays. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses the modularity and rendering issues defined in #46 by introducing a refined class hierarchy and a unified rendering system.
1. Architecture:
BaseEnv(gym.Env)The new
BaseEnvserves as the foundation for all environments, reducing boilerplate and enforcing structure.NUM_INTRUDERS) are replaced with overridableClassVarsfor better configuration management.stepandresetmethods are handled internally. Subclasses implementing specific logic via protected hooks (e.g.,_is_terminated,_is_truncated,_get_action,_get_reward).lat, lon, altare converted to framex, ycoordinates, decoupling logic from display.2. Mixin Classes (Cooperative Inheritance)
Functionality is now composed using Mixin classes. These handle common logic for specific features and chain their initialization via Python's MRO (Method Resolution Order).
HasIntrudersMixin:intruder_speed,intrusion_distance, andintrusion_penalty.num_intruders._check_horizontal_intrusion).HasWaypointsMixin:_create_waypointon reset based on configuration._create_waypointto return a singleWaypointobject.This structure allows for easy future extensions, such as
PolygonMixinorAirportMixin.3. Visualizer Class
Rendering logic has been extracted into a standalone
Visualizerclass to eliminate code duplication across environments.lat,lon), projects them internally, and draws to the provided canvas.draw_horizontal_ownshipdraw_all_horizontal_intrudersdraw_all_waypointsdraw_horizontal_line4. Utilities
types.py: Introduced dataclasses (e.g.,Waypoint) for stronger typing and clearer data structures.constants.py: Centralized shared constants (e.g.,NM2KM) to ensure consistency across environments.5. Example Class
horizontal_cr_envV1.py show how this can be used.
class HorizontalCrEnv(WaypointsMixin,IntrudersMixin,BaseEnv):
6. Wrappers
Should be perfectly aligned with wrappers. For them these Mixins are invisible.
7 Summary
This is still in early stages, some visualizations are still bugged.