Skip to content

Commit

Permalink
introduced JSONConfigurable class and demanded class entry in config
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikgro committed May 26, 2022
1 parent 36024c8 commit 473ddf7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions recommerce/configuration/hyperparameter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,6 @@ def load(cls, filename: str) -> AttrDict:
config = json.load(config_file)
# HyperparameterConfigValidator.validate_config(config)
# config_attr_dict = cls.flat_and_convert_to_attrdict(config)
assert 'class' in config, "Every config file must contain a 'class' key"
print(config)
return AttrDict(config)
8 changes: 8 additions & 0 deletions recommerce/configuration/json_configurable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from abc import ABC, abstractmethod


class JSONConfigurable(ABC):
@staticmethod
@abstractmethod
def get_configurable_fields(cls):
raise NotImplementedError
4 changes: 4 additions & 0 deletions recommerce/market/circular/circular_sim_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def get_competitor_classes() -> list:
import recommerce.market.circular.circular_vendors as c_vendors
return sorted(ut.filtered_class_str_from_dir('recommerce.market.circular.circular_vendors', dir(c_vendors), '.*CE.*Agent.*'))

@staticmethod
def get_configurable_fields() -> list:
return ['max_price', 'max_quality', 'production_price', 'number_of_customers']

def _setup_action_observation_space(self, support_continuous_action_space: bool) -> None:
# cell 0: number of products in the used storage, cell 1: number of products in circulation
self.max_storage = self.config.max_storage
Expand Down
4 changes: 4 additions & 0 deletions recommerce/market/linear/linear_sim_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def get_competitor_classes() -> list:
import recommerce.market.linear.linear_vendors as l_vendors
return sorted(ut.filtered_class_str_from_dir('recommerce.market.linear.linear_vendors', dir(l_vendors), '.*LE.*Agent.*'))

@staticmethod
def get_configurable_fields() -> list:
return ['max_price', 'max_quality', 'production_price', 'number_of_customers']

def _setup_action_observation_space(self, support_continuous_action_space: bool) -> None:
"""
The observation array has the following format:
Expand Down
5 changes: 3 additions & 2 deletions recommerce/market/sim_market.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from abc import ABC, abstractmethod
from abc import abstractmethod
from typing import Tuple

import gym
import numpy as np
from attrdict import AttrDict

from recommerce.configuration.json_configurable import JSONConfigurable
from recommerce.configuration.utils import filtered_class_str_from_dir

# An offer is a market state that contains all prices and qualities
Expand All @@ -15,7 +16,7 @@
# Third: vendor's actions from the former round which needs to be saved and influence the other's decision e.g. prices


class SimMarket(gym.Env, ABC):
class SimMarket(gym.Env, JSONConfigurable):
"""
The superclass to all market environments.
Abstract class that cannot be instantiated.
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/configuration_files/market_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"class": "recommerce.market.circular.circular_sim_market.CircularEconomyRebuyPriceMonopoly",
"max_storage": 100,
"episode_length": 50,
"max_price": 10,
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/configuration_files/rl_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"class": "recommerce.rl.q_learning.q_learning_agent.QLearningAgent",
"gamma": 0.99,
"batch_size": 8,
"replay_size": 350,
Expand Down

0 comments on commit 473ddf7

Please sign in to comment.