Browse Source

Underlying code for cumulative time in simulator. Not used and not tested. Bound to break something.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@186 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Mark Kattenbelt 19 years ago
parent
commit
4b79591e88
  1. 8
      prism/include/SimulatorEngine.h
  2. 2
      prism/include/simengine.h
  3. 5
      prism/include/simpath.h
  4. 1
      prism/include/simstate.h
  5. 6
      prism/src/simulator/SimulatorEngine.cc
  6. 10
      prism/src/simulator/SimulatorEngine.java
  7. 5
      prism/src/simulator/simengine.cc
  8. 29
      prism/src/simulator/simpath.cc
  9. 2
      prism/src/simulator/simstate.cc

8
prism/include/SimulatorEngine.h

@ -143,6 +143,14 @@ JNIEXPORT jint JNICALL Java_simulator_SimulatorEngine_getPathData
JNIEXPORT jdouble JNICALL Java_simulator_SimulatorEngine_getTimeSpentInPathState
(JNIEnv *, jclass, jint);
/*
* Class: simulator_SimulatorEngine
* Method: getCumulativeTimeSpentInPathState
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_simulator_SimulatorEngine_getCumulativeTimeSpentInPathState
(JNIEnv *, jclass, jint);
/*
* Class: simulator_SimulatorEngine
* Method: getStateRewardOfPathState

2
prism/include/simengine.h

@ -97,6 +97,8 @@ int Engine_Get_Path_Data(int var_index, int state_index);
double Engine_Get_Time_Spent_In_Path_State(int state_index);
double Engine_Get_Cumulative_Time_Spent_In_Path_State(int state_index);
double Engine_Get_State_Reward_Of_Path_State(int state_index);
double Engine_Get_Transition_Reward_Of_Path_State(int state_index);

5
prism/include/simpath.h

@ -170,6 +170,11 @@ int Get_Path_Data(int var_index, int state_index);
*/
double Get_Time_Spent_In_Path_State(int state_index);
/*
* Returns the cumulative time spent in the path_state at state_index.
*/
double Get_Cumulative_Time_Spent_In_Path_State(int state_index);
/*
* Returns the reward accumulated in the path state at
* state_index.

1
prism/include/simstate.h

@ -69,6 +69,7 @@ class CPathState
int choice_made; //the choice made to get out of this state
double probability; //this is used to determine which choice was made, if choice_made is -1
double time_spent_in_state; //The time spent in that state
double cumulative_time_spent_in_state; //Total path time upto and including current state.
bool time_known;
double *state_cost; //The costs accumulated in that state (for real time models)
double *state_instant_cost; //The instant state costs of that state

6
prism/src/simulator/SimulatorEngine.cc

@ -249,6 +249,12 @@ JNIEXPORT jdouble JNICALL Java_simulator_SimulatorEngine_getTimeSpentInPathState
return Get_Time_Spent_In_Path_State(stateIndex);
}
JNIEXPORT jdouble JNICALL Java_simulator_SimulatorEngine_getCumulativeTimeSpentInPathState
(JNIEnv *env, jclass cls, jint stateIndex)
{
return Get_Cumulative_Time_Spent_In_Path_State(stateIndex);
}
JNIEXPORT jdouble JNICALL Java_simulator_SimulatorEngine_getStateRewardOfPathState
(JNIEnv *env, jclass cls, jint stateIndex, jint i)
{

10
prism/src/simulator/SimulatorEngine.java

@ -98,8 +98,11 @@ import prism.*;
* <LI> <tt>getDataSize()</tt></LI>
* <LI> <tt>getPathData(int pathIndex, int variableIndex)</tt></LI>
* <LI> <tt>getTimeSpentInPathState(int pathIndex)</tt></LI>
* <LI> <tt>getCumulativeTimeSpentInPathState(int pathIndex)</tt></LI>
* <LI> <tt>getStateRewardOfPathState(int pathIndex, int i)</tt></LI>
* <LI> <tt>getTotalStateRewardOfPathState(int pathIndex, int i)</tt> (Cumulative)</LI>
* <LI> <tt>getTransitionRewardOfPathState(int pathIndex, int i)</tt></LI>
* <LI> <tt>getTotalTransitionRewardOfPathState(int pathIndex, int i)</tt> (Cumulative)</LI>
* </UL>
*
* The simulator engine automatically detects loops in execution paths, and
@ -931,6 +934,13 @@ public class SimulatorEngine
*/
public static native double getTimeSpentInPathState(int stateIndex);
/**
* Returns the cumulative time spent in the states upto a given path index.
* @param stateIndex the index of the path state of interest
* @return the time spent in the state at the given path index.
*/
public static native double getCumulativeTimeSpentInPathState(int stateIndex);
/**
* Returns the ith state reward of the state at the given path index.
* @param stateIndex the index of the path state of interest

5
prism/src/simulator/simengine.cc

@ -245,6 +245,11 @@ double Engine_Get_Time_Spent_In_Path_State(int state_index)
return Get_Time_Spent_In_Path_State(state_index);
}
double Engine_Get_Cumulative_Time_Spent_In_Path_State(int state_index)
{
return Get_Cumulative_Time_Spent_In_Path_State(state_index);
}
double Engine_Get_State_Reward_Of_Path_State(int state_index, int i)
{
return Get_State_Reward_Of_Path_State(state_index, i);

29
prism/src/simulator/simpath.cc

@ -415,7 +415,9 @@ void Backtrack(int step)
for(int i = 0; i < current_index; i++)
{
if(stored_path[i]->time_known)path_timer += stored_path[i]->time_spent_in_state;
if(stored_path[i]->time_known)
path_timer += stored_path[i]->time_spent_in_state;
for (int j = 0; j < no_reward_structs; j++) {
total_state_cost[j] += stored_path[i]->state_cost[j];
total_transition_cost[j] += stored_path[i]->transition_cost[j];
@ -561,6 +563,20 @@ double Get_Time_Spent_In_Path_State(int state_index)
}
}
/*
* Returns the cumulative time spent in the path_state at state_index.
*/
double Get_Cumulative_Time_Spent_In_Path_State(int state_index)
{
if(state_index == current_index) return UNDEFINED_DOUBLE;
else
{
CPathState* ps = stored_path[state_index];
//cout << ps->To_String() << endl;
return ps->cumulative_time_spent_in_state;
}
}
/*
* Returns the reward accumulated in the path state at
* state_index.
@ -705,6 +721,17 @@ inline void Add_Current_State_To_Path()
double time_in_state = Get_Sampled_Time();
last_state->time_spent_in_state = (time_in_state);
if (current_index > 1)
{
CPathState * state_before_last_state = stored_path[current_index-2];
last_state->cumulative_time_spent_in_state = last_state->cumulative_time_spent_in_state + state_before_last_state->cumulative_time_spent_in_state;
}
else
{
last_state->cumulative_time_spent_in_state = last_state->cumulative_time_spent_in_state;
}
last_state->time_known = true;
path_timer += time_in_state;

2
prism/src/simulator/simstate.cc

@ -87,6 +87,7 @@ CPathState::CPathState()
variables[i] = UNDEFINED_INT;
}
this->time_spent_in_state = 0.0;
this->cumulative_time_spent_in_state = 0.0;
this->time_known = false;
this->state_cost = new double[no_reward_structs];
this->state_instant_cost = new double[no_reward_structs];
@ -131,6 +132,7 @@ void CPathState::Make_This_Current_State()
for(int i = 0; i < no_state_variables; i++)
variables[i] = state_variables[i];
this->time_spent_in_state = 0.0;
this->cumulative_time_spent_in_state = 0.0;
this->time_known = false;
for(int i = 0; i < no_reward_structs; i++) {

Loading…
Cancel
Save