Browse Source

Small update to both the Java and C part of the simulator to facilitate the display of (instant) state rewards of the most current state.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@174 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Mark Kattenbelt 19 years ago
parent
commit
5e00f01dc0
  1. 16
      prism/src/simulator/simpath.cc
  2. 58
      prism/src/userinterface/simulator/GUISimulator.java
  3. 35
      prism/src/userinterface/simulator/GUISimulatorPathTable.java

16
prism/src/simulator/simpath.cc

@ -552,7 +552,6 @@ int Get_Path_Data(int var_index, int state_index)
*/ */
double Get_Time_Spent_In_Path_State(int state_index) double Get_Time_Spent_In_Path_State(int state_index)
{ {
if(state_index == current_index) return UNDEFINED_DOUBLE; if(state_index == current_index) return UNDEFINED_DOUBLE;
else else
{ {
@ -568,8 +567,7 @@ double Get_Time_Spent_In_Path_State(int state_index)
*/ */
double Get_State_Reward_Of_Path_State(int state_index, int i) double Get_State_Reward_Of_Path_State(int state_index, int i)
{ {
if(state_index == current_index) return UNDEFINED_DOUBLE;
if(state_index > current_index) return UNDEFINED_DOUBLE;
else else
return stored_path[state_index]->state_instant_cost[i]; return stored_path[state_index]->state_instant_cost[i];
} }
@ -580,8 +578,7 @@ double Get_State_Reward_Of_Path_State(int state_index, int i)
*/ */
double Get_Transition_Reward_Of_Path_State(int state_index, int i) double Get_Transition_Reward_Of_Path_State(int state_index, int i)
{ {
if(state_index == current_index) return UNDEFINED_DOUBLE;
if(state_index >= current_index) return UNDEFINED_DOUBLE;
else else
return stored_path[state_index]->transition_cost[i]; return stored_path[state_index]->transition_cost[i];
} }
@ -680,12 +677,15 @@ inline void Add_Current_State_To_Path()
CPathState* curr_state = stored_path[current_index]; CPathState* curr_state = stored_path[current_index];
curr_state->Make_This_Current_State(); curr_state->Make_This_Current_State();
Calculate_State_Reward(curr_state->variables);
for(int i = 0; i < no_reward_structs; i++) {
curr_state->state_instant_cost[i] = Get_State_Reward(i);
}
if(current_index > 0) if(current_index > 0)
{ {
CPathState * last_state = stored_path[current_index-1]; CPathState * last_state = stored_path[current_index-1];
for(int i = 0; i < no_reward_structs; i++) {
last_state->state_instant_cost[i] = Get_State_Reward(i);
}
if(model_type == STOCHASTIC) if(model_type == STOCHASTIC)
{ {
double time_in_state = Get_Sampled_Time(); double time_in_state = Get_Sampled_Time();

58
prism/src/userinterface/simulator/GUISimulator.java

@ -2251,11 +2251,20 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect
private Double stateReward; private Double stateReward;
private Double transitionReward; private Double transitionReward;
private boolean transitionRewardUnknown;
private boolean stateRewardVisible;
private boolean transitionRewardVisible;
public RewardStructureValue(RewardStructure rewardStructure, Double stateReward, Double transitionReward) public RewardStructureValue(RewardStructure rewardStructure, Double stateReward, Double transitionReward)
{ {
this.rewardStructure = rewardStructure; this.rewardStructure = rewardStructure;
this.stateReward = stateReward; this.stateReward = stateReward;
this.transitionReward = transitionReward; this.transitionReward = transitionReward;
this.transitionRewardUnknown = false;
this.stateRewardVisible = true;
this.transitionRewardVisible = true;
} }
public RewardStructure getRewardStructure() public RewardStructure getRewardStructure()
@ -2278,6 +2287,36 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect
public void setTransitionReward(Double transitionReward) { public void setTransitionReward(Double transitionReward) {
this.transitionReward = transitionReward; this.transitionReward = transitionReward;
} }
public void setStateRewardVisible(boolean b)
{
this.stateRewardVisible = b;
}
public boolean isStateRewardVisible()
{
return this.stateRewardVisible;
}
public void setTransitionRewardVisible(boolean b)
{
this.transitionRewardVisible = b;
}
public boolean isTransitionRewardVisible()
{
return this.transitionRewardVisible;
}
public void setTransitionRewardUnknown()
{
this.transitionRewardUnknown = true;
}
public boolean isTransitionRewardUnknown()
{
return this.transitionRewardUnknown;
}
} }
public class SimulationView extends Observable public class SimulationView extends Observable
@ -2693,21 +2732,22 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect
else if (rewardStart <= columnIndex) else if (rewardStart <= columnIndex)
{ {
RewardStructure reward = (RewardStructure)view.getVisibleRewards().get(columnIndex - rewardStart); RewardStructure reward = (RewardStructure)view.getVisibleRewards().get(columnIndex - rewardStart);
if (rowIndex < SimulatorEngine.getPathSize() - 1)
if (rowIndex == SimulatorEngine.getPathSize() - 1)
{ {
RewardStructureValue value = new RewardStructureValue(reward, SimulatorEngine.getStateRewardOfPathState(rowIndex, reward.getIndex()), SimulatorEngine.getTransitionRewardOfPathState(rowIndex, reward.getIndex())); RewardStructureValue value = new RewardStructureValue(reward, SimulatorEngine.getStateRewardOfPathState(rowIndex, reward.getIndex()), SimulatorEngine.getTransitionRewardOfPathState(rowIndex, reward.getIndex()));
if (reward.isStateEmpty() && view.hideEmptyRewards())
{ value.setStateReward(null); }
if (reward.isTransitionEmpty() && view.hideEmptyRewards())
{ value.setTransitionReward(null); }
value.setTransitionRewardUnknown();
value.setStateRewardVisible(!(reward.isStateEmpty() && view.hideEmptyRewards()));
value.setTransitionRewardVisible(!(reward.isTransitionEmpty() && view.hideEmptyRewards()));
return value; return value;
} }
else
else if (rowIndex < SimulatorEngine.getPathSize() - 1)
{ {
return "...";
RewardStructureValue value = new RewardStructureValue(reward, SimulatorEngine.getStateRewardOfPathState(rowIndex, reward.getIndex()), SimulatorEngine.getTransitionRewardOfPathState(rowIndex, reward.getIndex()));
value.setStateRewardVisible(!(reward.isStateEmpty() && view.hideEmptyRewards()));
value.setTransitionRewardVisible(!(reward.isTransitionEmpty() && view.hideEmptyRewards()));
return value;
} }
} }
} }

35
prism/src/userinterface/simulator/GUISimulatorPathTable.java

@ -381,25 +381,44 @@ public class GUISimulatorPathTable extends GUIGroupedTable
else if (value instanceof GUISimulator.RewardStructureValue) else if (value instanceof GUISimulator.RewardStructureValue)
{ {
GUISimulator.RewardStructureValue rewardValue = (GUISimulator.RewardStructureValue)value; GUISimulator.RewardStructureValue rewardValue = (GUISimulator.RewardStructureValue)value;
if (rewardValue.getStateReward() != null && rewardValue.getTransitionReward() != null)
//GUISimulator.RewardStructure reward = rewardValue.getRewardStructure();
String text = "";
String tooltipText = "";
if (rewardValue.isStateRewardVisible())
{ {
field.setText(rewardValue.getStateReward().toString() + " [ " + rewardValue.getTransitionReward().toString() + " ]");
text += rewardValue.getStateReward().toString();
tooltipText += "State reward";
} }
else if (rewardValue.getStateReward() == null && rewardValue.getTransitionReward() != null)
if (rewardValue.isStateRewardVisible() && rewardValue.isTransitionRewardVisible())
{ {
field.setText("[ " + rewardValue.getTransitionReward().toString() + " ]");
text += " ";
tooltipText += " ";
} }
else if (rewardValue.getStateReward() != null && rewardValue.getTransitionReward() == null)
if (rewardValue.isTransitionRewardVisible())
{ {
field.setText(rewardValue.getStateReward().toString());
text += "[ ";
text += (rewardValue.isTransitionRewardUnknown()) ? "..." : rewardValue.getTransitionReward().toString();
text += " ]";
if (rewardValue.isTransitionRewardUnknown())
{
tooltipText = "The transition reward is still unknown";
} }
else else
{ {
field.setText("");
tooltipText += "[ Transition reward ]";
} }
}
field.setText(text);
field.setHorizontalAlignment(JTextField.CENTER); field.setHorizontalAlignment(JTextField.CENTER);
field.setToolTipText("State Reward [ Transition Reward ]");
field.setToolTipText(tooltipText);
} }
else else
{ {

Loading…
Cancel
Save