예제 #1
0
    def test_value(self):
        boundaryconditions = mpcpy.Disturbances(bcs)
        
        t0 = 1*24*3600.
        val = boundaryconditions(t0)

        self.assertEqual(val,{'time':t0,'y0':np.interp(t0,time,y0),'y1':np.interp(t0,time,y1)})
예제 #2
0
    def test_value_notperiodic(self):
        boundaryconditions = mpcpy.Disturbances(bcs, periodic=False)
        
        t0 = 1*24*3600.
        t1 = t0 + time[-1]
        
        val0 = boundaryconditions(time[-1])
        val1 = boundaryconditions(t1)

        self.assertEqual(val0['y0'],val1['y0'])
        self.assertEqual(val0['y1'],val1['y1'])
예제 #3
0
    def test_value_periodic_timeoffset(self):
        bcs_timeoffset = dict(bcs)
        bcs_timeoffset['time'] = bcs_timeoffset['time'] + 2*24*3600.
        boundaryconditions = mpcpy.Disturbances(bcs_timeoffset)
        
        t0 = 3*24*3600.
        t1 = t0 + (time[-1]-time[0])
        
        val0 = boundaryconditions(t0)
        val1 = boundaryconditions(t1)

        self.assertEqual(val0['y0'],val1['y0'])
        self.assertEqual(val0['y1'],val1['y1'])
예제 #4
0
 def test_create_extratime(self):
     boundaryconditions = mpcpy.Disturbances(bcs, extra_time=1 * 24 * 3600)
     boundaryconditions = mpcpy.Disturbances(bcs, periodic=False, extra_time=1 * 24 * 3600)
예제 #5
0
 def test_getitem(self):
     boundaryconditions = mpcpy.Disturbances(bcs)
     temp = boundaryconditions['y0']
예제 #6
0
 def test_create_periodic(self):
     boundaryconditions = mpcpy.Disturbances(bcs, periodic=True)
     boundaryconditions = mpcpy.Disturbances(bcs, periodic=False)
예제 #7
0
 def test_create(self):
     boundaryconditions = mpcpy.Disturbances(bcs)
예제 #8
0
파일: quickstart.py 프로젝트: gide87/mpcpy
                    initial_conditions={'x': 0})

# test the emulator with some random data
time = np.arange(0., 1001., 10.)
np.random.seed(0)
d = np.random.random(len(time)) - 0.5
u = 1.0 * np.ones(len(time))

emulator.initialize()
res = emulator(time, {'time': time, 'd': d, 'u': u})
print(res)

# create a disturbances object
time = np.arange(0., 1001., 10.)
d = 0.5 * np.sin(2 * np.pi * time / 1000)
disturbances = mpcpy.Disturbances({'time': time, 'd': d})

bcs = disturbances(np.array([0, 20, 40, 60, 100]))
print(bcs)

# create a stateestimation object
stateestimation = StateestimationPerfect(emulator)
sta = stateestimation(0)
print(sta)

# create a prediction object
prediction = mpcpy.Prediction(disturbances)
pre = prediction(np.array([0, 20, 40, 60, 100]))
print(pre)

# create a control object and mpc object
예제 #9
0
import mpcpy

# Disturbances
time = np.arange(0.,24.01*3600.,3600.)
dst = {
    'time': time,
    'T_am': 5 + 2*np.sin(2*np.pi*time/24./3600.)+273.15,
    'Q_flow_so': 500 + 500*np.sin(2*np.pi*time/24./3600.),
    'p_el': 0.2 + 0.05*np.sin(2*np.pi*time/24./3600.),
    'Q_flow_hp_max': 5000*np.ones_like(time),
    'T_in_min': 20*np.ones_like(time)+273.15,
    'T_em_max': 30*np.ones_like(time)+273.15
}

disturbances = mpcpy.Disturbances(dst, periodic=False)
# test
print(disturbances(1800))
print(disturbances(24.5 * 3600))  # extrapolation


# Emulator
class Emulator(mpcpy.Emulator):
    """
    A custom system emulator
    """
    def simulate(self, starttime, stoptime, input):
        dt = 60
        time = np.arange(starttime, stoptime+dt, dt, dtype=np.float)

        # initialize
예제 #10
0
#
#    You should have received a copy of the GNU General Public License
#    along with mpcpy.  If not, see <http://www.gnu.org/licenses/>.
################################################################################

import unittest
import mpcpy
import numpy as np

# define variables
time = np.arange(0.0, 7 * 24 * 3600. + 1., 900.)
y0 = np.sin(time / (24 * 3600.))
y1 = np.random.random(len(time))
bcs = {'time': time, 'y0': y0, 'y1': y1}

boundaryconditions = mpcpy.Disturbances(bcs)


class TestPrediction(unittest.TestCase):
    def test_create(self):
        prediction = mpcpy.Prediction(boundaryconditions)

    def test_value(self):
        prediction = mpcpy.Prediction(boundaryconditions)

        t0 = 1 * 24 * 3600.

        self.assertEqual(prediction(t0), boundaryconditions(t0))


if __name__ == '__main__':