Browse Source
several extensions to program graphs
several extensions to program graphs
Former-commit-id:main52162888a4
[formerly5b4787851c
] Former-commit-id:c5b4a7d868
8 changed files with 289 additions and 24 deletions
-
15src/storage/ppg/ProgramAction.cpp
-
158src/storage/ppg/ProgramAction.h
-
18src/storage/ppg/ProgramEdge.cpp
-
13src/storage/ppg/ProgramEdge.h
-
22src/storage/ppg/ProgramEdgeGroup.h
-
68src/storage/ppg/ProgramGraph.h
-
18src/storage/ppg/ProgramLocation.h
-
1src/storage/ppg/defines.h
@ -0,0 +1,15 @@ |
|||||
|
#include "ProgramAction.h"
|
||||
|
#include "ProgramGraph.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace ppg { |
||||
|
|
||||
|
ProbabilisticProgramAction::ProbabilisticProgramAction(ProgramGraph* graph, ProgramActionIdentifier actId, int64_t from, int64_t to) : ProgramAction(graph, actId) { |
||||
|
assert(from <= to); |
||||
|
storm::expressions::Expression prob = graph->getExpressionManager()->integer(1) / graph->getExpressionManager()->integer(to - from + 1); |
||||
|
for(int64_t i = from; i <= to; ++i) { |
||||
|
values.emplace_back(i, prob); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,158 @@ |
|||||
|
#pragma once |
||||
|
#include "defines.h" |
||||
|
#include "src/storage/expressions/Expression.h" |
||||
|
#include "src/storage/expressions/Variable.h" |
||||
|
#include "src/storage/expressions/ExpressionManager.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace ppg { |
||||
|
|
||||
|
class ProgramAction { |
||||
|
public: |
||||
|
ProgramAction(ProgramGraph* graph, ProgramActionIdentifier id) : graph(graph), actId(id) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
ProgramActionIdentifier id() const { |
||||
|
return actId; |
||||
|
} |
||||
|
|
||||
|
ProgramGraph const& getProgramGraph() const { |
||||
|
return *graph; |
||||
|
} |
||||
|
|
||||
|
virtual bool isProbabilistic() const = 0; |
||||
|
private: |
||||
|
ProgramGraph* graph; |
||||
|
ProgramActionIdentifier actId; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
struct ValueProbabilityPair { |
||||
|
ValueProbabilityPair(int64_t value, storm::expressions::Expression const& probability) : value(value), probability(probability) { |
||||
|
// Intentionally left empty. |
||||
|
} |
||||
|
|
||||
|
int64_t value; |
||||
|
storm::expressions::Expression probability; |
||||
|
}; |
||||
|
|
||||
|
class ProbabilisticProgramAction : public ProgramAction { |
||||
|
public: |
||||
|
// TODO in the long run, we probably need own iterators for this. |
||||
|
using iterator = std::vector<ValueProbabilityPair>::iterator; |
||||
|
using const_iterator = std::vector<ValueProbabilityPair>::const_iterator; |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Constructs a uniform assignment operation to a variable; |
||||
|
* Action assigns a variable according to a uniform distribution [from, to] |
||||
|
*/ |
||||
|
ProbabilisticProgramAction(ProgramGraph* graph, ProgramActionIdentifier actId, int64_t from, int64_t to); |
||||
|
|
||||
|
bool isProbabilistic() const override{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
iterator begin() { |
||||
|
return values.begin(); |
||||
|
} |
||||
|
|
||||
|
iterator end() { |
||||
|
return values.end(); |
||||
|
} |
||||
|
|
||||
|
const_iterator begin() const { |
||||
|
return values.begin(); |
||||
|
} |
||||
|
|
||||
|
const_iterator end() const { |
||||
|
return values.end(); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
// TODO not the smartest representation (but at least it is internal!) |
||||
|
std::vector<ValueProbabilityPair> values; |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
|
||||
|
struct AssignmentGroup { |
||||
|
using iterator = std::unordered_map<uint64_t, storm::expressions::Expression>::iterator; |
||||
|
using const_iterator = std::unordered_map<uint64_t, storm::expressions::Expression>::const_iterator; |
||||
|
|
||||
|
storm::expressions::Expression& operator[](uint64_t varIndex) { |
||||
|
return map[varIndex]; |
||||
|
} |
||||
|
|
||||
|
bool hasVariable(uint64_t varIndex) const { |
||||
|
return map.count(varIndex) > 0; |
||||
|
} |
||||
|
|
||||
|
iterator begin() { |
||||
|
return map.begin(); |
||||
|
} |
||||
|
|
||||
|
iterator end() { |
||||
|
return map.end(); |
||||
|
} |
||||
|
|
||||
|
const_iterator begin() const { |
||||
|
return map.begin(); |
||||
|
} |
||||
|
|
||||
|
const_iterator end() const { |
||||
|
return map.end(); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
std::unordered_map<uint64_t, storm::expressions::Expression> map; |
||||
|
}; |
||||
|
|
||||
|
class DeterministicProgramAction : public ProgramAction { |
||||
|
|
||||
|
public: |
||||
|
using iterator = std::vector<AssignmentGroup>::iterator; |
||||
|
using const_iterator = std::vector<AssignmentGroup>::const_iterator; |
||||
|
|
||||
|
DeterministicProgramAction(ProgramGraph* graph, ProgramActionIdentifier actId) : ProgramAction(graph, actId) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
void addAssignment(uint64_t varIndex, storm::expressions::Expression const& expr, uint64_t level=0) { |
||||
|
if(assignments.size() <= level) { |
||||
|
assignments.resize(level+1); |
||||
|
} |
||||
|
assert(!assignments[level].hasVariable(varIndex)); |
||||
|
assignments[level][varIndex] = expr; |
||||
|
} |
||||
|
|
||||
|
iterator begin() { |
||||
|
return assignments.begin(); |
||||
|
} |
||||
|
|
||||
|
iterator end() { |
||||
|
return assignments.end(); |
||||
|
} |
||||
|
|
||||
|
const_iterator begin() const { |
||||
|
return assignments.begin(); |
||||
|
} |
||||
|
|
||||
|
const_iterator end() const { |
||||
|
return assignments.end(); |
||||
|
} |
||||
|
|
||||
|
bool isProbabilistic() const override{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
protected: |
||||
|
std::vector<AssignmentGroup> assignments; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -1,9 +1,11 @@ |
|||||
//
|
|
||||
// ProgramEdge.cpp
|
|
||||
// storm
|
|
||||
//
|
|
||||
// Created by Sebastian Junges on 09/09/16.
|
|
||||
//
|
|
||||
//
|
|
||||
|
|
||||
#include "ProgramEdge.h"
|
#include "ProgramEdge.h"
|
||||
|
#include "ProgramGraph.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace ppg { |
||||
|
|
||||
|
ProgramAction const& ProgramEdge::getAction() const { |
||||
|
return group->getGraph().getAction(action); |
||||
|
} |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue