def calc_oper(mdl): endresults_nom, resgraph, mdlhist =propagate.nominal(mdl) opercost = endresults_nom['classification']['expected cost'] g_soc = 20 - mdlhist['functions']['StoreEE']['soc'][-1] g_faults = any(endresults_nom['faults']) g_max_height = sum([i for i in mdlhist['flows']['DOFs']['elev']-122 if i>0]) return opercost, g_soc, g_faults, g_max_height
def calc_oper(mdl): endresults_nom, resgraph, mdlhist =propagate.nominal(mdl) opercost = endresults_nom['classification']['expected cost'] g_soc = 20 - mdlhist['functions']['StoreEE']['soc'][-1] g_faults = any(endresults_nom['faults']) g_max_height = sum([i for i in mdlhist['flows']['DOFs']['elev']-122 if i>0]) landtime = find_landtime(mdlhist) mdl.params['landtime']=landtime mdl.phases['forward'][1] = landtime mdl.phases['taxis'][0] = landtime return opercost, g_soc, g_faults, g_max_height
def test_model_2(): x0 = [0.1 , 2 , 5 , 10 , 0.05 , 10 ] result0=list(SimplePandemicModel(x0)) sus_simp = result0[1] inf_simp = result0[2] rec_simp = result0[3] fmdmdl = PandemicModel(params={'x0':x0}) endresults, resgraph, mdlhist_nom = nominal(fmdmdl) sus_mdl = mdlhist_nom['functions']['City']['Susceptible'] inf_mdl = mdlhist_nom['functions']['City']['Infected'] rec_mdl = mdlhist_nom['functions']['City']['Recovered'] sus_err = np.average(abs((sus_simp-sus_mdl)/(sus_mdl+0.1))) inf_err = np.average(abs((inf_simp-inf_mdl)/(inf_mdl+0.1))) rec_err = np.average(abs((rec_simp-rec_mdl)/(rec_mdl+0.1))) assert sus_err < 0.06 assert inf_err < 0.06 assert rec_err < 0.06
# -*- coding: utf-8 -*- """ Created on Sun Jul 5 14:58:54 2020 @author: danie """ import sys sys.path.append('../') import fmdtools.faultsim.propagate as propagate import fmdtools.resultdisp as rd import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from drone_mdl import * import time from drone_opt import * mdl = x_to_mdl([0, 2, 100, 0, 0]) params = mdl.params endresults, resgraph, mdlhist = propagate.nominal(mdl) rd.plot.mdlhistvals(mdlhist, fxnflowvals={'StoreEE': 'soc'}) #plot_nomtraj(mdlhist, params) #plot_xy(mdlhist, endresults)
# -*- coding: utf-8 -*- """ Created on Fri Sep 11 10:23:55 2020 @author: Daniel Hulse """ from drone_opt import * import fmdtools.faultsim.propagate as propagate import fmdtools.resultdisp.graph as graph mdl_med = x_to_mdl([1,1,80,1,1]) calc_oper(mdl_med) endresults_med, resgraph, mdlhist_med =propagate.nominal(mdl_med) plot_xy(mdlhist_med, endresults_med, title='Flight plan at 80 m') app_med = SampleApproach(mdl_med, faults='single-component', phases={'forward'}) faulttime_med = app_med.times landtime_med = min([i for i,a in enumerate(mdlhist_med['functions']['Planpath']['mode']) if a=='taxi']) rcost_med = calc_res(mdl_med) rcost_med2 = x_to_rcost([1,1],[80],[1,1]) mdl_low = x_to_mdl([1,1,50,1,1]) calc_oper(mdl_low) endresults_low, resgraph, mdlhist_low =propagate.nominal(mdl_low) plot_xy(mdlhist_low, endresults_low, title='Flight plan at 50 m') app_low = SampleApproach(mdl_low, faults='single-component', phases={'forward'}) faulttime_low = app_low.times landtime_low = min([i for i,a in enumerate(mdlhist_low['functions']['Planpath']['mode']) if a=='taxi']) rcost_low = calc_res(mdl_low) rcost_low2 = x_to_rcost([1,1],[50],[1,1])
import fmdtools.faultsim.propagate as propagate import fmdtools.resultdisp as rd from ex_pump import * #required to import entire module import time mdl = Pump() ##NOMINAL PLOTS #Before seeing how faults propogate, it's useful to see how the model performs #in the nominal state to check to see that the model has been defined correctly. # Some things worth checking: # -are all functions on the graph? # -are the functions connected with the correct flows? # -do any faults occur in the nominal state? # -do all the flow states proceed as desired over time? endresults, resgraph, mdlhist = propagate.nominal(mdl, track=True) #plot graph rd.graph.show(resgraph) #plot the flows over time rd.plot.mdlhist(mdlhist, 'Nominal') #we can also look at the value of states over time with a table nominal_state_table = rd.tabulate.hist(mdlhist) print(nominal_state_table) #this table is a pandas dataframe we can export with: # nominal_state_table.to_csv("filename.csv") #plots can be made on the bipartite version of the graph endresults_bip, resgraph_bip, mdlhist2 = propagate.nominal(mdl, gtype='bipartite') rd.graph.show(resgraph_bip, gtype='bipartite', scale=2)
def objective(x): dm1 = PandemicModel(x) endresults, resgraph, mdlhist_nom = propagate.nominal(dm1) print('hi') return endresults['classification']['total cost']
import fmdtools.faultsim.propagate as propagate import fmdtools.resultdisp as rd import csv import time import numpy as np from fmd_model import PandemicModel from scipy.optimize import differential_evolution #from disease_model import * #x0 = np.array([0.11 , 1 , 5 , 9.27 , 0.05 , 10 ]) x0 = [0.1, 2, 5, 10, 0.05, 10] dm1 = PandemicModel(params={'x0': x0}) rd.graph.show(dm1.graph) endresults, resgraph, mdlhist_nom = propagate.nominal(dm1) #rd.plot.mdlhist(mdlhist_nom, fxnflows=['Campus']) #normal_state_table = rd.tabulate.hist(mdlhist_nom) #normal_state_table.to_csv('normal_state_table.csv') rd.plot.mdlhistvals( mdlhist_nom, fxnflowvals={'City': ['Susceptible', 'Infected', 'Recovered']}) def objective(x): dm1 = PandemicModel(x) endresults, resgraph, mdlhist_nom = propagate.nominal(dm1) print('hi')