Mentions légales du service

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • ct/gallery
  • ldellelc/gallery
  • pomet/gallery
3 results
Select Git revision
Show changes
Commits on Source (1431)
Showing
with 5883 additions and 18 deletions
......@@ -6,11 +6,16 @@
# gitignore template for Jupyter Notebooks
# website: http://jupyter.org/
*.*~
*.msg
.ipynb_checkpoints
*/.ipynb_checkpoints/*
*.so
*.so.dSYM
*.so.dSYM/*
.nfs*
*__pycache__*
# IPython
profile_default/
......@@ -23,5 +28,8 @@ ipython_config.py
# bocop files (build and exec)
build/
bocop
bocopApp
bocopwrapper.py
!bocop/
*.sol
libbocop.dylib
image: intelpython/intelpython3_full:latest
pages:
tags:
- ci.inria.fr
- small
stage: deploy
before_script:
- conda install -c conda-forge pandoc
script:
- python --version
- python -m pip install $(cat requirements.txt)
- python -m pip install -r pkg/requirements.txt
- pip list
- conda list
- python -m sphinx -b html examples/ public
......
# ct (control toolbox) gallery
# Welcome to ct (control toolbox) gallery
Jupyter notebooks for use cases using solvers of the nutopy package and others.
Examples from the ct (control toolbox) project
using [bocop](https://ct.gitlabpages.inria.fr/bocop3), [nutopy](https://ct.gitlabpages.inria.fr/nutopy) and other packages. Please visit the [gallery](https://ct.gitlabpages.inria.fr/gallery) or explore the dashboards apps or the notebooks codes by clicking on the following images!
[![Online examples](https://img.shields.io/badge/ct-gallery-blue.svg)](https://ct.gitlabpages.inria.fr/gallery)
[![Full directory](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.inria.fr%2Fct%2Fgallery.git/master?urlpath=lab/)
[<img src="examples/notebook-logo.png" alt="Visit the notebooks" width="270"/>](https://ct.gitlabpages.inria.fr/gallery/notebooks.html)
[<img src="examples/dashboard-logo.png" alt="Visit the dashboards" width="300"/>](https://ct.gitlabpages.inria.fr/gallery/dashboards.html)
You can execute the code online and make your own experiments by clicking on <img alt="Binder badge" src="https://static.mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"> when you find it on a notebook or a dashboard.
Special thanks: [A. Hurtig](http://www.alain.les-hurtig.org) for the logos ligatures
name: ct-gallery
channels:
- control-toolbox
- conda-forge
- dtk-forge
dependencies:
- scipy
- matplotlib=3.1.*
- nutopy=0.3.*
- bocop>3.0.0
- cmake
- gfortran_linux-64
:root {
--sd-color-primary: #f37726;
}
./*.def
./*.out
This diff is collapsed.
examples/bacteria/bacteria-panel.jpeg

957 KiB

This diff is collapsed.
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.2
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info < (2, 7, 0):
raise RuntimeError("Python 2.7 or later required")
# Import the low-level C/C++ module
if __package__ or "." in __name__:
from . import _bocopwrapper
else:
import _bocopwrapper
try:
import builtins as __builtin__
except ImportError:
import __builtin__
_swig_new_instance_method = _bocopwrapper.SWIG_PyInstanceMethod_New
_swig_new_static_method = _bocopwrapper.SWIG_PyStaticMethod_New
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
def _swig_setattr_nondynamic_instance_variable(set):
def set_instance_attr(self, name, value):
if name == "thisown":
self.this.own(value)
elif name == "this":
set(self, name, value)
elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
set(self, name, value)
else:
raise AttributeError("You cannot add instance attributes to %s" % self)
return set_instance_attr
def _swig_setattr_nondynamic_class_variable(set):
def set_class_attr(cls, name, value):
if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
set(cls, name, value)
else:
raise AttributeError("You cannot add class attributes to %s" % cls)
return set_class_attr
def _swig_add_metaclass(metaclass):
"""Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
def wrapper(cls):
return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
return wrapper
class _SwigNonDynamicMeta(type):
"""Meta class to enforce nondynamic attributes (no new attributes) for a class"""
__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
import weakref
class SwigPyIterator(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
def __init__(self, *args, **kwargs):
raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _bocopwrapper.delete_SwigPyIterator
value = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_value)
incr = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_incr)
decr = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_decr)
distance = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_distance)
equal = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_equal)
copy = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_copy)
next = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_next)
__next__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___next__)
previous = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_previous)
advance = _swig_new_instance_method(_bocopwrapper.SwigPyIterator_advance)
__eq__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___eq__)
__ne__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___ne__)
__iadd__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___iadd__)
__isub__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___isub__)
__add__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___add__)
__sub__ = _swig_new_instance_method(_bocopwrapper.SwigPyIterator___sub__)
def __iter__(self):
return self
# Register SwigPyIterator in _bocopwrapper:
_bocopwrapper.SwigPyIterator_swigregister(SwigPyIterator)
class VecDouble(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
__repr__ = _swig_repr
iterator = _swig_new_instance_method(_bocopwrapper.VecDouble_iterator)
def __iter__(self):
return self.iterator()
__nonzero__ = _swig_new_instance_method(_bocopwrapper.VecDouble___nonzero__)
__bool__ = _swig_new_instance_method(_bocopwrapper.VecDouble___bool__)
__len__ = _swig_new_instance_method(_bocopwrapper.VecDouble___len__)
__getslice__ = _swig_new_instance_method(_bocopwrapper.VecDouble___getslice__)
__setslice__ = _swig_new_instance_method(_bocopwrapper.VecDouble___setslice__)
__delslice__ = _swig_new_instance_method(_bocopwrapper.VecDouble___delslice__)
__delitem__ = _swig_new_instance_method(_bocopwrapper.VecDouble___delitem__)
__getitem__ = _swig_new_instance_method(_bocopwrapper.VecDouble___getitem__)
__setitem__ = _swig_new_instance_method(_bocopwrapper.VecDouble___setitem__)
pop = _swig_new_instance_method(_bocopwrapper.VecDouble_pop)
append = _swig_new_instance_method(_bocopwrapper.VecDouble_append)
empty = _swig_new_instance_method(_bocopwrapper.VecDouble_empty)
size = _swig_new_instance_method(_bocopwrapper.VecDouble_size)
swap = _swig_new_instance_method(_bocopwrapper.VecDouble_swap)
begin = _swig_new_instance_method(_bocopwrapper.VecDouble_begin)
end = _swig_new_instance_method(_bocopwrapper.VecDouble_end)
rbegin = _swig_new_instance_method(_bocopwrapper.VecDouble_rbegin)
rend = _swig_new_instance_method(_bocopwrapper.VecDouble_rend)
clear = _swig_new_instance_method(_bocopwrapper.VecDouble_clear)
get_allocator = _swig_new_instance_method(_bocopwrapper.VecDouble_get_allocator)
pop_back = _swig_new_instance_method(_bocopwrapper.VecDouble_pop_back)
erase = _swig_new_instance_method(_bocopwrapper.VecDouble_erase)
def __init__(self, *args):
_bocopwrapper.VecDouble_swiginit(self, _bocopwrapper.new_VecDouble(*args))
push_back = _swig_new_instance_method(_bocopwrapper.VecDouble_push_back)
front = _swig_new_instance_method(_bocopwrapper.VecDouble_front)
back = _swig_new_instance_method(_bocopwrapper.VecDouble_back)
assign = _swig_new_instance_method(_bocopwrapper.VecDouble_assign)
resize = _swig_new_instance_method(_bocopwrapper.VecDouble_resize)
insert = _swig_new_instance_method(_bocopwrapper.VecDouble_insert)
reserve = _swig_new_instance_method(_bocopwrapper.VecDouble_reserve)
capacity = _swig_new_instance_method(_bocopwrapper.VecDouble_capacity)
__swig_destroy__ = _bocopwrapper.delete_VecDouble
# Register VecDouble in _bocopwrapper:
_bocopwrapper.VecDouble_swigregister(VecDouble)
class VecVecdouble(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
__repr__ = _swig_repr
iterator = _swig_new_instance_method(_bocopwrapper.VecVecdouble_iterator)
def __iter__(self):
return self.iterator()
__nonzero__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___nonzero__)
__bool__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___bool__)
__len__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___len__)
__getslice__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___getslice__)
__setslice__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___setslice__)
__delslice__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___delslice__)
__delitem__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___delitem__)
__getitem__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___getitem__)
__setitem__ = _swig_new_instance_method(_bocopwrapper.VecVecdouble___setitem__)
pop = _swig_new_instance_method(_bocopwrapper.VecVecdouble_pop)
append = _swig_new_instance_method(_bocopwrapper.VecVecdouble_append)
empty = _swig_new_instance_method(_bocopwrapper.VecVecdouble_empty)
size = _swig_new_instance_method(_bocopwrapper.VecVecdouble_size)
swap = _swig_new_instance_method(_bocopwrapper.VecVecdouble_swap)
begin = _swig_new_instance_method(_bocopwrapper.VecVecdouble_begin)
end = _swig_new_instance_method(_bocopwrapper.VecVecdouble_end)
rbegin = _swig_new_instance_method(_bocopwrapper.VecVecdouble_rbegin)
rend = _swig_new_instance_method(_bocopwrapper.VecVecdouble_rend)
clear = _swig_new_instance_method(_bocopwrapper.VecVecdouble_clear)
get_allocator = _swig_new_instance_method(_bocopwrapper.VecVecdouble_get_allocator)
pop_back = _swig_new_instance_method(_bocopwrapper.VecVecdouble_pop_back)
erase = _swig_new_instance_method(_bocopwrapper.VecVecdouble_erase)
def __init__(self, *args):
_bocopwrapper.VecVecdouble_swiginit(self, _bocopwrapper.new_VecVecdouble(*args))
push_back = _swig_new_instance_method(_bocopwrapper.VecVecdouble_push_back)
front = _swig_new_instance_method(_bocopwrapper.VecVecdouble_front)
back = _swig_new_instance_method(_bocopwrapper.VecVecdouble_back)
assign = _swig_new_instance_method(_bocopwrapper.VecVecdouble_assign)
resize = _swig_new_instance_method(_bocopwrapper.VecVecdouble_resize)
insert = _swig_new_instance_method(_bocopwrapper.VecVecdouble_insert)
reserve = _swig_new_instance_method(_bocopwrapper.VecVecdouble_reserve)
capacity = _swig_new_instance_method(_bocopwrapper.VecVecdouble_capacity)
__swig_destroy__ = _bocopwrapper.delete_VecVecdouble
# Register VecVecdouble in _bocopwrapper:
_bocopwrapper.VecVecdouble_swigregister(VecVecdouble)
class CallbackF(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
__repr__ = _swig_repr
handle = _swig_new_instance_method(_bocopwrapper.CallbackF_handle)
__swig_destroy__ = _bocopwrapper.delete_CallbackF
def __init__(self):
if self.__class__ == CallbackF:
_self = None
else:
_self = self
_bocopwrapper.CallbackF_swiginit(self, _bocopwrapper.new_CallbackF(_self, ))
def __disown__(self):
self.this.disown()
_bocopwrapper.disown_CallbackF(self)
return weakref.proxy(self)
# Register CallbackF in _bocopwrapper:
_bocopwrapper.CallbackF_swigregister(CallbackF)
solve = _bocopwrapper.solve
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display, clear_output
import ipywidgets as widgets
class PyCallback(CallbackF):
def __init__(self):
super().__init__()
self.initialized = False
self.g_state = [] #for each iter, 2 dims np array
self.g_control = []
self.out = widgets.Output()
self.outText = widgets.Output(layout={'border': '1px solid black'})
def update(self, iteration):
if self.initialized:
len_state = len(self.g_state[iteration])
clear_output(wait=True)
for i in range(len_state):
self.axs[i].clear()
self.axs[i].plot(self.x_state ,self.g_state[iteration][i])
self.axs[i].title.set_text(f"State {i}")
self.axs[i].relim()
self.axs[i].autoscale()
self.fig.canvas.blit(self.axs[i].bbox)
for i in range(len(self.g_control[iteration])):
self.axs[len_state + i].clear()
self.axs[len_state + i].plot(self.x_control ,self.g_control[iteration][i], color='r')
self.axs[len_state + i].relim()
self.axs[len_state + i].set_title(f"Control {i}")
self.axs[len_state + i].autoscale()
self.fig.canvas.blit(self.axs[len_state + i].bbox)
self.outText.clear_output()
with self.outText:
objective = self.g_state[iteration][-1][-1]
print(f"iteration {iteration} objective : {objective}")
display(self.fig)
display(self.outText)
def handle(self, state, control):
if not self.initialized:
self.initialized = True
plt.ioff()
nrows = len(state) + len(control)
with self.out:
self.fig, self.axs = plt.subplots(nrows=nrows, ncols=1)
self.fig.tight_layout()
self.fig.canvas.header_visible = False # Hide the Figure name at the top of the figure
# If true then scrolling while the mouse is over the canvas will not move the entire notebook
self.fig.canvas.capture_scroll = True
self.x_state = np.arange(len(state[0]))
self.x_control = np.arange(len(control[0]))
plt.ion()
self.g_state.append(np.asarray(state))
self.g_control.append(np.asarray(control))
self.update(len(self.g_state) -1)
# Definition file
# Dimensions
dim.state 4
dim.control 1
dim.boundaryconditions 4
dim.pathconstraints 0
dim.parameters 0
dim.constants 4
# Time interval
initial.time 0
final.time 20
# Constants
constant.0 0.6
constant.1 0.003
constant.2 0.5
constant.3 0.07
# Time discretisation
ode.discretization midpoint_implicit
time.steps 200
# Bounds for constraints (initial conditions for our case)
boundarycond.0.lowerbound 0.03
boundarycond.0.upperbound 0.03
boundarycond.1.lowerbound 0.1
boundarycond.1.upperbound 0.1
boundarycond.2.lowerbound 0.2
boundarycond.2.upperbound 0.2
boundarycond.3.lowerbound 0.003
boundarycond.3.upperbound 0.003
# Bounds for variables (dynamical bound for each variable and control)
state.0.lowerbound 0
state.1.lowerbound 0
state.2.lowerbound 0
state.3.lowerbound 0
#Optimal value calculated for our initial conditions
control.0.lowerbound 0.4679139313552532
control.0.upperbound 0.4679139313552532
# Initialization for discretized problem (initial point for the optimization algorithm.. this we can touch only if the algorithm is not working, otherwise we can leave it like this)
state.0.init 0.1
state.1.init 0.1
state.2.init 0.1
state.3.init 0.1
control.0.init 0.4679139313552532
# Ipopt
ipoptIntOption.print_level 5
ipoptIntOption.max_iter 1000
ipoptStrOption.mu_strategy adaptive
ipoptNumOption.tol 1e-12
# Misc
ad.retape 0
# Definition file
# Dimensions
dim.state 4
dim.control 1
dim.boundaryconditions 4
dim.pathconstraints 0
dim.parameters 0
dim.constants 4
# Time interval
initial.time 0
final.time 20
# Constants
constant.0 0.6
constant.1 0.003
constant.2 0.5
constant.3 0.07
# Time discretisation
ode.discretization midpoint_implicit
time.steps 200
# Bounds for constraints (initial conditions for our case)
boundarycond.0.lowerbound 0.03
boundarycond.0.upperbound 0.03
boundarycond.1.lowerbound 0.1
boundarycond.1.upperbound 0.1
boundarycond.2.lowerbound 0.2
boundarycond.2.upperbound 0.2
boundarycond.3.lowerbound 0.003
boundarycond.3.upperbound 0.003
# Bounds for variables (dynamical bound for each variable and control)
state.0.lowerbound 0
state.1.lowerbound 0
state.2.lowerbound 0
state.3.lowerbound 0
control.0.lowerbound 0
control.0.upperbound 1
# Initialization for discretized problem (initial point for the optimization algorithm.. this we can touch only if the algorithm is not working, otherwise we can leave it like this)
state.0.init 0.1
state.1.init 0.1
state.2.init 0.1
state.3.init 0.1
control.0.init 0.5
# Ipopt
ipoptIntOption.print_level 5
ipoptIntOption.max_iter 1000
ipoptStrOption.mu_strategy adaptive
ipoptNumOption.tol 1e-12
# Misc
ad.retape 0
# Definition file
# Dimensions
dim.state 4
dim.control 1
dim.boundaryconditions 4
dim.pathconstraints 0
dim.parameters 0
dim.constants 4
# Time interval
initial.time 0
final.time 20
# Constants
constant.0 0.7
constant.1 0.003
constant.2 0.5
constant.3 0.07
# Time discretisation
ode.discretization midpoint_implicit
time.steps 2000
# Bounds for constraints (initial conditions for our case)
boundarycond.0.lowerbound 0.03
boundarycond.0.upperbound 0.03
boundarycond.1.lowerbound 0.17433823529411765
boundarycond.1.upperbound 0.17433823529411765
boundarycond.2.upperbound 0.3256617647058824
boundarycond.2.upperbound 0.3256617647058824
boundarycond.3.lowerbound 0.003
boundarycond.3.upperbound 0.003
# Bounds for variables (dynamical bound for each variable and control)
state.0.lowerbound 0
state.1.lowerbound 0
state.2.lowerbound 0
state.3.lowerbound 0
control.0.lowerbound 0
control.0.upperbound 1
# Initialization for discretized problem (initial point for the optimization algorithm.. this we can touch only if the algorithm is not working, otherwise we can leave it like this)
state.0.init 0.1
state.1.init 0.1
state.2.init 0.1
state.3.init 0.1
control.0.init 0.5
# Ipopt
ipoptIntOption.print_level 5
ipoptIntOption.max_iter 1000
ipoptStrOption.mu_strategy adaptive
ipoptNumOption.tol 1e-12
# Misc
ad.retape 0
# Definition file
# Dimensions
dim.state 4
dim.control 1
dim.boundaryconditions 4
dim.pathconstraints 0
dim.parameters 0
dim.constants 4
# Time interval
initial.time 0
final.time 20
# Constants
constant.0 0.7
constant.1 0.003
constant.2 0.3
constant.3 0.07
# Time discretisation
ode.discretization midpoint_implicit
time.steps 2000
# Bounds for constraints (initial conditions for our case)
boundarycond.0.lowerbound 0.0458
boundarycond.0.upperbound 0.0458
boundarycond.1.lowerbound 0.249
boundarycond.1.upperbound 0.249
boundarycond.2.upperbound 0.25
boundarycond.2.upperbound 0.25
boundarycond.3.lowerbound 0.003
boundarycond.3.upperbound 0.003
# Bounds for variables (dynamical bound for each variable and control)
state.0.lowerbound 0
state.1.lowerbound 0
state.2.lowerbound 0
state.3.lowerbound 0
control.0.lowerbound 0
control.0.upperbound 1
# Initialization for discretized problem (initial point for the optimization algorithm.. this we can touch only if the algorithm is not working, otherwise we can leave it like this)
state.0.init 0.1
state.1.init 0.1
state.2.init 0.1
state.3.init 0.1
control.0.init 0.5
# Ipopt
ipoptIntOption.print_level 5
ipoptIntOption.max_iter 1000
ipoptStrOption.mu_strategy adaptive
ipoptNumOption.tol 1e-12
# Misc
ad.retape 0
File added
max_iter 2000
print_level 5
tol 1.0e-12
output_file result.out
mu_strategy adaptive
examples/bacteria/maintenance.png

52 KiB

# Definition file
# Dimensions
dim.state 4
dim.control 1
dim.boundaryconditions 4
dim.pathconstraints 0
dim.parameters 0
dim.constants 4
# Time interval
initial.time 0
final.time 20
# Constants
constant.0 0.6
constant.1 0.003
constant.2 0.5
constant.3 0.07
# Time discretisation
ode.discretization midpoint_implicit
time.steps 200
# Bounds for constraints (initial conditions for our case)
boundarycond.0.lowerbound 0.03
boundarycond.0.upperbound 0.03
boundarycond.1.lowerbound 0.1
boundarycond.1.upperbound 0.1
boundarycond.2.lowerbound 0.2
boundarycond.2.upperbound 0.2
boundarycond.3.lowerbound 0.003
boundarycond.3.upperbound 0.003
# Bounds for variables (dynamical bound for each variable and control)
state.0.lowerbound 0
state.1.lowerbound 0
state.2.lowerbound 0
state.3.lowerbound 0
#Optimal value calculated for our initial conditions
control.0.lowerbound 0.4679139313552532
control.0.upperbound 0.4679139313552532
# Initialization for discretized problem (initial point for the optimization algorithm.. this we can touch only if the algorithm is not working, otherwise we can leave it like this)
state.0.init 0.1
state.1.init 0.1
state.2.init 0.1
state.3.init 0.1
control.0.init 0.4679139313552532
# Ipopt
ipoptIntOption.print_level 5
ipoptIntOption.max_iter 1000
ipoptStrOption.mu_strategy adaptive
ipoptNumOption.tol 1e-12
# Misc
ad.retape 0
// +++DRAFT+++ This class implements the OCP functions
// It derives from the generic class bocop3OCPBase
// OCP functions are defined with templates since they will be called
// from both the NLP solver (double arguments) and AD tool (ad_double arguments)
//#pragma once
#include <OCP.h>
// ///////////////////////////////////////////////////////////////////
template <typename Variable>
void OCP::finalCost(double initial_time, double final_time, const Variable *initial_state, const Variable *final_state, const Variable *parameters, const double *constants, Variable &final_cost)
{
// maximize the volume of the bacteria
final_cost = -final_state[3];
}
template <typename Variable>
void OCP::dynamics(double time, const Variable *state, const Variable *control, const Variable *parameters, const double *constants, Variable *state_dynamics)
{
Variable p = state[0];
Variable r = state[1];
Variable m = state[2];
Variable V = state[3];
Variable u = control[0];
double Em = constants[0];
double K = constants[1];
double rmax = constants[2];
double rmin = constants[3];
Variable vR = (r-rmin)*p/(K+p);
state_dynamics[0] = Em*m - (p+1)*vR;
state_dynamics[1] = (u*rmax-r)*vR;
state_dynamics[2] = ((1-u)*rmax-m)*vR;
state_dynamics[3] = vR*V;
}
template <typename Variable>
void OCP::boundaryConditions(double initial_time, double final_time, const Variable *initial_state, const Variable *final_state, const Variable *parameters, const double *constants, Variable *boundary_conditions)
{
boundary_conditions[0] = initial_state[0];
boundary_conditions[1] = initial_state[1];
boundary_conditions[2] = initial_state[2];
boundary_conditions[3] = initial_state[3];
}
template <typename Variable>
void OCP::pathConstraints(double time, const Variable *state, const Variable *control, const Variable *parameters, const double *constants, Variable *path_constraints)
{}
void OCP::preProcessing()
{}
// ///////////////////////////////////////////////////////////////////
// explicit template instanciation for template functions, with double and double_ad
// +++ could be in an included separate file ?
// but needs to be done for aux functions too ? APPARENTLY NOT !
template void OCP::finalCost<double>(double initial_time, double final_time, const double *initial_state, const double *final_state, const double *parameters, const double *constants, double &final_cost);
template void OCP::dynamics<double>(double time, const double *state, const double *control, const double *parameters, const double *constants, double *state_dynamics);
template void OCP::boundaryConditions<double>(double initial_time, double final_time, const double *initial_state, const double *final_state, const double *parameters, const double *constants, double *boundary_conditions);
template void OCP::pathConstraints<double>(double time, const double *state, const double *control, const double *parameters, const double *constants, double *path_constraints);
template void OCP::finalCost<double_ad>(double initial_time, double final_time, const double_ad *initial_state, const double_ad *final_state, const double_ad *parameters, const double *constants, double_ad &final_cost);
template void OCP::dynamics<double_ad>(double time, const double_ad *state, const double_ad *control, const double_ad *parameters, const double *constants, double_ad *state_dynamics);
template void OCP::boundaryConditions<double_ad>(double initial_time, double final_time, const double_ad *initial_state, const double_ad *final_state, const double_ad *parameters, const double *constants, double_ad *boundary_conditions);
template void OCP::pathConstraints<double_ad>(double time, const double_ad *state, const double_ad *control, const double_ad *parameters, const double *constants, double_ad *path_constraints);
# Definition file
# Dimensions
dim.state 4
dim.control 1
dim.boundaryconditions 4
dim.pathconstraints 0
dim.parameters 0
dim.constants 4
# Time interval
initial.time 0
final.time 20
# Constants
constant.0 0.6
constant.1 0.003
constant.2 0.5
constant.3 0.07
# Time discretisation
ode.discretization midpoint_implicit
time.steps 200
# Bounds for constraints (initial conditions for our case)
boundarycond.0.lowerbound 0.03
boundarycond.0.upperbound 0.03
boundarycond.1.lowerbound 0.1
boundarycond.1.upperbound 0.1
boundarycond.2.lowerbound 0.2
boundarycond.2.upperbound 0.2
boundarycond.3.lowerbound 0.003
boundarycond.3.upperbound 0.003
# Bounds for variables (dynamical bound for each variable and control)
state.0.lowerbound 0
state.1.lowerbound 0
state.2.lowerbound 0
state.3.lowerbound 0
control.0.lowerbound 0
control.0.upperbound 1
# Initialization for discretized problem (initial point for the optimization algorithm.. this we can touch only if the algorithm is not working, otherwise we can leave it like this)
state.0.init 0.1
state.1.init 0.1
state.2.init 0.1
state.3.init 0.1
control.0.init 0.5
# Ipopt
ipoptIntOption.print_level 5
ipoptIntOption.max_iter 1000
ipoptStrOption.mu_strategy adaptive
ipoptNumOption.tol 1e-12
# Misc
ad.retape 0