forked from anenriquez/mrta
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ropod-project/develop
New release version 0.2.0
- Loading branch information
Showing
42 changed files
with
1,059 additions
and
2,411 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import logging | ||
import time | ||
|
||
from fmlib.api import API | ||
from fleet_management.config.config import FMSBuilder | ||
from fmlib.db.mongo import Store | ||
from fmlib.db.queries import get_tasks_by_status | ||
from ropod.structs.task import TaskStatus as TaskStatusConst | ||
|
||
from mrs.config.builder import MRTABuilder | ||
from mrs.utils.datasets import load_yaml | ||
|
||
_component_modules = {'api': API, | ||
'ccu_store': Store, | ||
} | ||
|
||
_config_order = ['api', 'ccu_store'] | ||
|
||
|
||
class MRS(object): | ||
def __init__(self, config_file=None): | ||
|
||
self.logger = logging.getLogger('mrs') | ||
config_params = load_yaml(config_file) | ||
|
||
logger_config = config_params.get('logger') | ||
logging.config.dictConfig(logger_config) | ||
|
||
fms_builder = FMSBuilder(component_modules=_component_modules, | ||
config_order=_config_order) | ||
fms_builder.configure(config_params) | ||
|
||
self.api = fms_builder.get_component('api') | ||
self.ccu_store = fms_builder.get_component('ccu_store') | ||
|
||
mrta_builder = MRTABuilder.configure(self.api, self.ccu_store, config_params) | ||
self.auctioneer = mrta_builder.get_component('auctioneer') | ||
self.dispatcher = mrta_builder.get_component('dispatcher') | ||
|
||
self.api.register_callbacks(self) | ||
self.logger.info("Initialized MRS") | ||
|
||
def start_test_cb(self, msg): | ||
self.logger.debug("Start test msg received") | ||
tasks = get_tasks_by_status(TaskStatusConst.UNALLOCATED) | ||
self.auctioneer.allocate(tasks) | ||
|
||
def run(self): | ||
try: | ||
self.api.start() | ||
|
||
while True: | ||
self.auctioneer.run() | ||
self.api.run() | ||
time.sleep(0.5) | ||
except (KeyboardInterrupt, SystemExit): | ||
self.api.shutdown() | ||
self.logger.info('FMS is shutting down') | ||
|
||
def shutdown(self): | ||
self.api.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
config_file_path = '../config/config.yaml' | ||
fms = MRS(config_file_path) | ||
|
||
fms.run() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from fleet_management.exceptions.config import InvalidConfig | ||
from mrs.task_allocation import auctioneer | ||
from mrs.task_execution import dispatcher | ||
import logging | ||
|
||
|
||
class MRTABuilder: | ||
def __init__(self): | ||
self._auctioneer = None | ||
self._dispatcher = None | ||
|
||
def __call__(self, **kwargs): | ||
plugins = dict() | ||
for plugin, config in kwargs.items(): | ||
if plugin == 'auctioneer': | ||
self.auctioneer(**kwargs) | ||
plugins.update(auctioneer=self._auctioneer) | ||
if plugin == 'dispatcher': | ||
self.dispatcher(**kwargs) | ||
plugins.update(dispatcher=self._dispatcher) | ||
|
||
return plugins | ||
|
||
def auctioneer(self, **kwargs): | ||
if not self._auctioneer: | ||
try: | ||
self._auctioneer = auctioneer.configure(**kwargs) | ||
except InvalidConfig: | ||
raise InvalidConfig('MRTA plugin requires an auctioneer configuration') | ||
return self._auctioneer | ||
|
||
def dispatcher(self, **kwargs): | ||
if not self._dispatcher: | ||
try: | ||
self._dispatcher = dispatcher.configure(**kwargs) | ||
except InvalidConfig: | ||
raise InvalidConfig('MRTA plugin requires a dispatcher configuration') | ||
return self._dispatcher | ||
|
||
def get_component(self, name): | ||
if name == 'auctioneer': | ||
return self._auctioneer | ||
elif name == 'dispatcher': | ||
return self.dispatcher | ||
|
||
@classmethod | ||
def configure(cls, api, ccu_store, config_params): | ||
mrta_builder = cls() | ||
logging.info("Configuring MRTA...") | ||
mrta_config = config_params.get('plugins').get('mrta') | ||
if mrta_config is None: | ||
logging.debug("Found no mrta in the configuration file.") | ||
return None | ||
|
||
mrta_builder(api=api, ccu_store=ccu_store, **mrta_config) | ||
return mrta_builder |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import logging | ||
|
||
from mrs.db.models.performance.task import TaskPerformance | ||
from pymodm import fields, MongoModel | ||
from pymodm.context_managers import switch_collection | ||
from pymongo.errors import ServerSelectionTimeoutError | ||
from ropod.utils.uuid import generate_uuid | ||
|
||
|
||
class DatasetPerformance(MongoModel): | ||
""" Stores dataset performance information: | ||
dataset_id (UUID): uniquely identifies the dataset | ||
completion_time (float): Difference between the start navigation of the | ||
first task and the finish time of the last allocated | ||
task | ||
makespan (float): Finish time of the last allocated task | ||
fleet_work_time (float): % of time taken to perform all allocated tasks. | ||
fleet_travel_time (float): % of time taken to travel to task locations | ||
fleet_idle_time (float): % of time robots are idle (waiting) to start their next allocated task | ||
robot_usage (float): % of robots used out of all the available robots | ||
usage_most_loaded_robot (float): % of tasks allocated to the robot with most allocations | ||
""" | ||
dataset_id = fields.UUIDField(primary_key=True, default=generate_uuid()) | ||
completion_time = fields.FloatField() | ||
makespan = fields.FloatField() | ||
fleet_work_time = fields.FloatField() | ||
fleet_travel_time = fields.FloatField() | ||
fleet_idle_time = fields.FloatField() | ||
robot_usage = fields.FloatField() | ||
usage_most_loaded_robot = fields.FloatField() | ||
tasks = fields.ListField(fields.ReferenceField(TaskPerformance)) | ||
|
||
class Meta: | ||
archive_collection = 'dataset_performance_archive' | ||
ignore_unknown_fields = True | ||
|
||
def save(self): | ||
try: | ||
super().save(cascade=True) | ||
except ServerSelectionTimeoutError: | ||
logging.warning('Could not save models to MongoDB') | ||
|
||
def archive(self): | ||
with switch_collection(DatasetPerformance, DatasetPerformance.Meta.archive_collection): | ||
super().save() | ||
self.delete() | ||
|
||
@classmethod | ||
def create(cls, dataset_id, task_ids): | ||
performance = cls(dataset_id=dataset_id, tasks=task_ids) | ||
performance.save() | ||
return performance |
Oops, something went wrong.