2
* Copyright Peter G. Jensen, all rights reserved.
5
#include "PetriEngine/PQL/Contexts.h"
9
namespace PetriEngine {
12
bool ColoredAnalysisContext::resolvePlace(const std::string& place, std::unordered_map<uint32_t, std::string>& out)
14
auto it = _coloredPlaceNames.find(place);
15
if (it != _coloredPlaceNames.end()) {
22
bool ColoredAnalysisContext::resolveTransition(const std::string& transition, std::vector<std::string>& out)
24
auto it = _coloredTransitionNames.find(transition);
25
if (it != _coloredTransitionNames.end()) {
33
AnalysisContext::ResolutionResult AnalysisContext::resolve(const std::string& identifier, bool place)
35
ResolutionResult result;
37
result.success = false;
38
auto& map = place ? _placeNames : _transitionNames;
39
auto it = map.find(identifier);
40
if (it != map.end()) {
41
result.offset = (int) it->second;
42
result.success = true;
48
uint32_t SimplificationContext::getLpTimeout() const
53
double SimplificationContext::getReductionTime()
55
// duration in seconds
56
auto end = std::chrono::high_resolution_clock::now();
57
return (std::chrono::duration_cast<std::chrono::microseconds>(end - _start).count())*0.000001;
60
glp_prob* SimplificationContext::makeBaseLP() const
62
if (_base_lp == nullptr)
63
_base_lp = buildBase();
64
if (_base_lp == nullptr)
66
auto* tmp_lp = glp_create_prob();
67
glp_copy_prob(tmp_lp, _base_lp, GLP_OFF);
71
glp_prob* SimplificationContext::buildBase() const
73
constexpr auto infty = std::numeric_limits<double>::infinity();
77
auto* lp = glp_create_prob();
81
const uint32_t nCol = _net->numberOfTransitions();
82
const int nRow = _net->numberOfPlaces();
83
std::vector<int32_t> indir(std::max<uint32_t>(nCol, nRow) + 1);
85
glp_add_cols(lp, nCol + 1);
86
glp_add_rows(lp, nRow + 1);
88
std::vector<double> col = std::vector<double>(nRow + 1);
89
for (size_t t = 0; t < _net->numberOfTransitions(); ++t) {
90
auto pre = _net->preset(t);
91
auto post = _net->postset(t);
93
while (pre.first != pre.second ||
94
post.first != post.second) {
95
if (pre.first == pre.second || (post.first != post.second && post.first->place < pre.first->place)) {
96
col[l] = post.first->tokens;
97
indir[l] = post.first->place + 1;
100
else if (post.first == post.second || (pre.first != pre.second && pre.first->place < post.first->place)) {
101
if(!pre.first->inhibitor)
102
col[l] = -(double) pre.first->tokens;
105
indir[l] = pre.first->place + 1;
109
assert(pre.first->place == post.first->place);
110
if(!pre.first->inhibitor)
111
col[l] = (double) post.first->tokens - (double) pre.first->tokens;
113
col[l] = (double) post.first->tokens;
114
indir[l] = pre.first->place + 1;
120
glp_set_mat_col(lp, t + 1, l - 1, indir.data(), col.data());
122
std::cerr << "glpk: construction timeout" << std::endl;
129
for (size_t p = 0; p < _net->numberOfPlaces(); p++) {
130
glp_set_row_bnds(lp, rowno, GLP_LO, (0.0 - (double) _marking[p]), infty);
133
std::cerr << "glpk: construction timeout" << std::endl;
b'\\ No newline at end of file'