1
/* PeTe - Petri Engine exTremE
2
* Copyright (C) 2011 Jonas Finnemann Jensen <jopsen@gmail.com>,
3
* Thomas Søndersø Nielsen <primogens@gmail.com>,
4
* Lars Kærlund Østergaard <larsko@gmail.com>,
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "RandomQueryGenerator.h"
21
#include "../PQL/PQL.h"
22
#include "../PQL/Contexts.h"
23
#include "../Structures/StateSet.h"
24
#include "../Structures/StateAllocator.h"
34
using namespace PetriEngine::PQL;
35
using namespace PetriEngine::Structures;
37
namespace PetriEngine {
38
namespace Reachability {
40
/** Generate a random query */
41
std::string RandomQueryGenerator::gen(const PetriNet& net,
44
srand(time(0)); // Chosen by fair dice roll
46
StateAllocator<> allocator(net);
47
State* s = allocator.createState();
48
memcpy(s->marking(), m0, sizeof(MarkVal)*net.numberOfPlaces());
49
memcpy(s->valuation(), v0, sizeof(VarVal)*net.numberOfVariables());
51
int countdown = rand() % 5000000;
53
State* ns = allocator.createState();
54
while(countdown-- > 0){
55
unsigned int tstart = rand() % net.numberOfTransitions();
57
for(unsigned int t = tstart; t < net.numberOfTransitions(); t++){
58
if(net.fire(t, s, ns)){
64
for(unsigned int t = 0; t < tstart; t++){
65
if(net.fire(t, s, ns)){
79
ss<<net.placeNames()[0]<<" == "<<s->marking()[0];
80
for(unsigned int p = 1; p < net.numberOfPlaces(); p++)
81
ss<<" and "<<net.placeNames()[p]<<" == "<<s->marking()[p];
82
for(unsigned int x = 0; x < net.numberOfVariables(); x++)
83
ss<<" and "<<net.variableNames()[x]<<" == "<<s->valuation()[x];