Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DEMOSES-distributed-optimization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
DEMOSES
DEMOSES-distributed-optimization
Commits
a3ca44e9
Commit
a3ca44e9
authored
8 months ago
by
Christian Doh Dinga
Browse files
Options
Downloads
Patches
Plain Diff
solve generator agent's optimization problem
parent
7e864013
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/demoses_distibuted_optimization/solve_generator_agent.py
+84
-0
84 additions, 0 deletions
src/demoses_distibuted_optimization/solve_generator_agent.py
with
84 additions
and
0 deletions
src/demoses_distibuted_optimization/solve_generator_agent.py
0 → 100644
+
84
−
0
View file @
a3ca44e9
import
numpy
as
np
import
pyomo.environ
as
pyo
from
typing
import
Dict
from
build_generator_agent
import
build_generator_agent
def
solve_generator_agent
(
model
:
pyo
.
AbstractModel
,
data
:
Dict
,
instance_data
:
Dict
=
None
)
->
pyo
.
ConcreteModel
:
"""
Solve generator agent
'
s optimization problem.
"""
number_of_timesteps
=
data
[
"
General
"
][
"
nTimesteps
"
]
# First delete existing model components if they were previously instantiated
if
hasattr
(
model
,
'
var_g
'
):
model
.
del_component
(
model
.
var_g
)
if
hasattr
(
model
,
'
objective_function
'
):
model
.
del_component
(
model
.
objective_function
)
if
hasattr
(
model
,
'
capacity_limit
'
):
model
.
del_component
(
model
.
capacity_limit
)
# Default instance data
default_instance_data
=
{
None
:
{
'
λ_EOM
'
:
dict
(
enumerate
(
np
.
zeros
(
number_of_timesteps
))),
'
g_bar
'
:
dict
(
enumerate
(
np
.
zeros
(
number_of_timesteps
))),
'
ρ_EOM
'
:
{
None
:
data
[
"
ADMM
"
][
"
rho_EOM
"
]},
}
}
# Use default instance data if none is provided
if
instance_data
is
None
:
instance_data
=
default_instance_data
# Reconstruct and instantiate model for next round of solving
model
=
build_generator_agent
(
model
)
model_instance
=
model
.
create_instance
(
data
=
instance_data
)
solver
=
pyo
.
SolverFactory
(
'
gurobi
'
)
solver
.
solve
(
model_instance
)
return
model_instance
# # Example usage
# import yaml
# import pandas as pd
# from define_common_parameters import define_common_parameters
# from define_generator_parameters import define_generator_parameters
# def read_config(config_file):
# with open(config_file, 'r') as file:
# config = yaml.safe_load(file)
# return config
# data = read_config('config.yaml')
# generator_agents = [id for id in data['Generators'].keys()]
# ts = pd.read_csv('timeseries.csv', delimiter=';')
# mdict = {m: define_common_parameters(m, data) for m in generator_agents}
# instance_data_1 = {
# None: {
# 'λ_EOM': dict(enumerate(np.ones(24)*10)),
# 'g_bar': dict(enumerate(np.ones(24)*150)),
# 'ρ_EOM': {None: 1},
# }
# }
# instance_data_2 = {
# None: {
# 'λ_EOM': dict(enumerate(np.ones(24)*50)),
# 'g_bar': dict(enumerate(np.ones(24)*300)),
# 'ρ_EOM': {None: 1},
# }
# }
# for agent, model in mdict.items():
# model = define_generator_parameters(agent, model, data, ts)
# zero_model_instance = solve_generator_agent(model, data)
# print(zero_model_instance.name)
# print()
# zero_model_instance.objective_function.display()
# first_model_instance = solve_generator_agent(model, data, instance_data_1)
# print(first_model_instance.name)
# print()
# first_model_instance.objective_function.display()
# print()
# second_model_instance = solve_generator_agent(model, data, instance_data_2)
# print(second_model_instance.name)
# print()
# second_model_instance.objective_function.display()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment