forked from helenese/MDP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solving.py
29 lines (23 loc) · 858 Bytes
/
solving.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import reward, constants, numpy, functions
from scipy.sparse.linalg import spsolve
def equationsystem(matrix, vector):
val=numpy.linalg.solve(matrix, vector)
return(val)
def position_starting(states):
pos=[]
for i in range(len(states)):
if states[i][0]=='port' and states[i][2]==constants.default_sc['repairtime_max_plus1']-1 and states[i][3]==0:
pos.append(i)
return(pos)
def probability_wave(state, data):
val=data[functions.binning(state)]
return(val)
def evaluation(strat, rewardtype, states, data, data1):
m=strat.define_matrix(states,data)
v=reward.define_vector(states,rewardtype, strat)
les=equationsystem(m, v)
pos=position_starting(states)
val=0
for i in pos:
val=val+les[i]*probability_wave(states[i],data1)
return(val)