Skip to content

Commit

Permalink
Merge pull request #24 from wouterbles/enhanchement_branch
Browse files Browse the repository at this point in the history
Enhanchement branch
  • Loading branch information
wouterbles authored Feb 26, 2024
2 parents f7aff91 + d53c9c7 commit 83b6d44
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.0.8

- Add method to check if user-provided model component names mask pyaugmecon-added component names
- Update LICENSE

## 1.0.7

- Update readme to include other solvers
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Electrical Energy Systems Group, Department of Electrical
Copyright (c) 2021-2024 Electrical Energy Systems Group, Department of Electrical
Engineering, Eindhoven University of Technology.

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
31 changes: 31 additions & 0 deletions pyaugmecon/pyaugmecon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pyaugmecon.process_handler import ProcessHandler
from pyaugmecon.queue_handler import QueueHandler

augmecon_reserved_component_names = {'Os', 'Slack', 'e', 'con_list', 'pcon_list'}

class PyAugmecon:
def __init__(self, model: PyomoModel, opts: Options, solver_opts={}):
Expand All @@ -38,6 +39,9 @@ def __init__(self, model: PyomoModel, opts: Options, solver_opts={}):
self.logger = logging.getLogger(self.opts.log_name)
self.logger.setLevel(logging.INFO)

# Check the user-defined pyomo model for component name conflicts
self._check_user_model(model)

# Log options and initialize Model object with the given model
self.opts.log()
self.model = Model(model, self.opts)
Expand All @@ -50,6 +54,33 @@ def __init__(self, model: PyomoModel, opts: Options, solver_opts={}):
self.unique_sols = None
self.unique_pareto_sols = None

def _check_user_model(self, user_model):
"""
Check the component names of the user-provided pyomo model.
PyAugmecon modifies the user-provided pyomo model by adding components. If the modeller uses one of these
reserved names for a component it will be "overwritten", resulting in errors.
"""
self.names_in_user_model = list()

# It doesn't matter what type of Pyomo component masks a reserved component name
for c_ in user_model.component_objects():
self.names_in_user_model.append(c_.name)

self.names_in_user_model = set(self.names_in_user_model)
self.component_conflicts = self.names_in_user_model.intersection(augmecon_reserved_component_names)
self.num_conflicts = len(self.component_conflicts)

if self.num_conflicts != 0:
self.logger.info(f'Your model contains {self.num_conflicts} component name conflicts.'
f' Rename: {self.component_conflicts}')

raise Exception(f'{self.num_conflicts} of your pyomo model names raised a conflict'
f' with PyAugmecon reserved component names.\n'
f'To avoid errors, you must rename the following components: {self.component_conflicts}')


def _find_solutions(self):
"""
Find solutions to the optimization problem using the AUGMECON method.
Expand Down

0 comments on commit 83b6d44

Please sign in to comment.