def cost_model(E_sto, Speed, Accel, P_sto, innov):
    '''penalty on the power injected to the grid
    P_grid = P_prod - P_sto
    penal = (P_grid/power_max)**2
    '''
    P_prod = searev_power(Speed)
    P_grid = P_prod - P_sto
    penal = (P_grid / power_max)**2
    return penal


cost_label = 'quadratic cost'

### Create the system description:
searev_sys = SysDescription((3, 1, 1), name='Searev + Storage')
searev_sys.dyn = dyn_searev_sto
searev_sys.control_box = admissible_controls
searev_sys.cost = cost_model
searev_sys.perturb_laws = [innov_law]

#searev_sys.print_summary()

### Create the DP solver:
dpsolv = DPSolver(searev_sys)
# discretize the state space
N_E = 31
N_S = 61
N_A = 61
S_min, S_max = -4 * .254, 4 * 0.254
A_min, A_max = -4 * .227, 4 * .227
def cost_model(k, E_sto, P_sto):
    '''penalty on the power injected to the grid
    P_grid = P_prod - P_sto
    '''
    P_prod = P_prod_data[k]
    P_grid = P_prod - P_sto
    P_grid_over = np.where(P_grid > 0.4, P_grid - 0.4, 0)
    P_grid_neg = np.where(P_grid < 0, P_grid, 0)
    penal = P_grid_over**2 + P_grid_neg**2 + 0 * P_sto**2
    return penal


### Create the system description:
sto_sys = SysDescription((1, 1, 0),
                         name='Deterministic Storage for PV',
                         stationnary=False)
sto_sys.dyn = dyn_sto
sto_sys.control_box = admissible_controls
sto_sys.cost = cost_model

sto_sys.print_summary()

### Create the DP solver:
dpsolv = DPSolver(sto_sys)
# discretize the state space
N_E = 50

E_grid = dpsolv.discretize_state(0, E_rated, N_E)[0]
dpsolv.control_steps = (.001, )
from __future__ import division, print_function, unicode_literals
import numpy as np
import scipy.stats as stats
import matplotlib.pylab as plt

import sys
try:
    import stodynprog
except ImportError:
    sys.path.append('..')
    import stodynprog

#reload(stodynprog)

from stodynprog import SysDescription
invsys = SysDescription((1, 1, 1), name='Shop Inventory')


def dyn_inv(x, u, w):
    'dynamical equation of the inventory stock `x`. Returns x(k+1).'
    return (x + u - w, )


# Attach the dynamical equation to the system description:
invsys.dyn = dyn_inv

demand_values = [0, 1, 2, 3]
demand_proba = [0.2, 0.4, 0.3, 0.1]
demand_law = stats.rv_discrete(values=(demand_values, demand_proba))
demand_law = demand_law.freeze()
from __future__ import division, print_function, unicode_literals
import numpy as np
import scipy.stats as stats
import matplotlib.pylab as plt

import sys
try:
    import stodynprog
except ImportError:
    sys.path.append('..')
    import stodynprog

#reload(stodynprog)

from stodynprog import SysDescription
invsys = SysDescription((1,1,1), name='Shop Inventory')

def dyn_inv(x, u, w):
    'dynamical equation of the inventory stock `x`. Returns x(k+1).'
    return (x + u - w,)
# Attach the dynamical equation to the system description:
invsys.dyn = dyn_inv

demand_values = [0,   1,   2,   3]
demand_proba  = [0.2, 0.4, 0.3, 0.1]
demand_law = stats.rv_discrete(values=(demand_values, demand_proba))
demand_law = demand_law.freeze()

demand_law.pmf([0, 3]) # Probality Mass Function
demand_law.rvs(10) # Random Variables generation
Example #5
0
    import stodynprog
except ImportError:
    sys.path.append('..')
    import stodynprog


class ReachMovementTask():
    minimum_movement_length = -5
    maximum_movement_length = 5
    c = 10
    target_position = 40
    number_of_iterations = 30


from stodynprog import SysDescription
movement_sys = SysDescription((1, 1, 1), name='Movement system')


def optimize(crtReachMovementTask):
    minimum_movement_length = crtReachMovementTask.minimum_movement_length
    maximum_movement_length = crtReachMovementTask.maximum_movement_length
    c = crtReachMovementTask.c
    target_position = crtReachMovementTask.target_position
    number_of_iterations = crtReachMovementTask.number_of_iterations

    #functions defined here inside the optimizer
    def dyn_inv(x, u, w):
        'dynamical equation of the inventory stock `x`. Returns x(k+1).'
        return (x + u + w, )

    def op_cost(x, u, w):
    P_pos = np.min(( (p['E_rated']- E_sto)/dt, p['P_rated']))
    U1 = (P_neg, P_pos)
    return (U1, )

def cost_model(k, E_sto, P_sto):
    '''penalty on the power that is not absorbed
    P_dev = P_req - P_sto
    penal = P_dev**2
    '''
    P_req = p['P_req_data'][k]
    P_dev = P_req - P_sto
    penal = P_dev**2
    return penal

### Create the system description:
sto_sys = SysDescription((1,1,0), name='Deterministic Storage', stationnary=False)
sto_sys.dyn = dyn_sto
sto_sys.control_box = admissible_controls
sto_sys.cost = cost_model

sto_sys.print_summary()

### Create the DP solver:
dpsolv = DPSolver(sto_sys)
# discretize the state space
N_E = 100

E_grid = dpsolv.discretize_state(0, p['E_rated'], N_E)[0]
dpsolv.control_steps=(.001,)

dpsolv.print_summary()
def cost_model(E_sto, Speed, Accel, P_sto, innov):
    """penalty on the power injected to the grid
    P_grid = P_prod - P_sto
    penal = (P_grid/power_max)**2
    """
    P_prod = searev_power(Speed)
    P_grid = P_prod - P_sto
    penal = (P_grid / power_max) ** 2
    return penal


cost_label = "quadratic cost"

### Create the system description:
searev_sys = SysDescription((3, 1, 1), name="Searev + Storage")
searev_sys.dyn = dyn_searev_sto
searev_sys.control_box = admissible_controls
searev_sys.cost = cost_model
searev_sys.perturb_laws = [innov_law]

# searev_sys.print_summary()

### Create the DP solver:
dpsolv = DPSolver(searev_sys)
# discretize the state space
N_E = 31
N_S = 61
N_A = 61
S_min, S_max = -4 * 0.254, 4 * 0.254
A_min, A_max = -4 * 0.227, 4 * 0.227