UnCoVer (Using Coverability for Verification)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
PreparedGTS.h
1 /***************************************************************************
2  * Copyright (C) 2014 by Jan Stückrath <jan.stueckrath@uni-due.de> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
18  ***************************************************************************/
19 
20 #ifndef PREPAREDGTS_H_
21 #define PREPAREDGTS_H_
22 
23 #include "../graphs/GTS.h"
24 #include "RulePreparer.h"
25 #include "../graphs/UQRuleInstance.h"
26 
27 namespace uncover {
28  namespace analysis {
29 
40  class PreparedGTS: public graphs::GTS {
41 
42  public:
43 
53 
54  friend class PreparedGTS;
55 
56  public:
57 
64 
69 
75 
85 
90  bool hasEnded();
91 
92  private:
93 
101  uqinst_iterator(graphs::UQRule_sp rule, RulePreparer_sp rulepreparer, unsigned int bound);
102 
110  void loadNextRule(bool firstTime = false);
111 
117  unsigned int sumCurrentQuant();
118 
123 
128 
133  vector<unsigned int>* currentQuant;
134 
139  vector<graphs::UQRuleInstance_sp>* currentInstances;
140 
144  unsigned int bound;
145 
146  };
147 
157  PreparedGTS(GTS const& gts, RulePreparer_sp rulePrep, bool opt = true);
158 
162  virtual ~PreparedGTS();
163 
174 
181  shared_ptr<vector<graphs::AnonRule_csp>> getOriginalRules(IDType id) const;
182 
183  protected:
184 
191  void createInstancesUpTo(IDType const& ruleID, size_t bound);
192 
197 
203  map<IDType, vector<IDType>> prepFrom;
204 
209 
214  unordered_map<IDType, vector<graphs::UQRuleInstance_sp>> uqRuleInstances;
215 
221  unordered_map<IDType, vector<size_t>> uqRuleLengths;
222 
231  class StdRuleMapCB : public basic_types::CollectionCallback<graphs::Rule_sp> {
232 
233  public:
234 
240 
244  virtual ~StdRuleMapCB() {}
245 
251  virtual void insert(graphs::Rule_sp rule) {
252  gts.addStdRule(rule);
253  gts.prepFrom[rule->getID()].push_back(currentRuleID);
254  }
255 
261  currentRuleID = id;
262  }
263 
264  private:
265 
270 
276 
277  };
278 
279  };
280 
284  typedef shared_ptr<PreparedGTS> PreparedGTS_sp;
285 
289  typedef shared_ptr<PreparedGTS const> PreparedGTS_csp;
290 
291 
292  } /* namespace analysis */
293 } /* namespace uncover */
294 
295 #endif /* PREPAREDGTS_H_ */
unordered_map< IDType, vector< size_t > > uqRuleLengths
For each ID of a UQRule (key) this map stores a vector of positions (value).
Definition: PreparedGTS.h:221
The StdRuleMapCB is a helper class defining a CollectionCallback to a PreparedGTS standard rule map...
Definition: PreparedGTS.h:231
void loadNextRule(bool firstTime=false)
Drops the current UQRuleInstance and computes the next one if possible.
Definition: PreparedGTS.cpp:179
bool addStdRule(Rule_sp rule)
Adds the given Rule to the standard rules of this GTS.
Definition: GTS.cpp:41
graphs::UQRule_sp rule
Stores the UQRule used by this iterator.
Definition: PreparedGTS.h:122
PreparedGTS(GTS const &gts, RulePreparer_sp rulePrep, bool opt=true)
Creates a Prepared GTS using the given GTS and RulePreparer.
Definition: PreparedGTS.cpp:33
map< IDType, vector< IDType > > prepFrom
Stores for every new (prepared) rule the ID of the original rules from which it was prepared...
Definition: PreparedGTS.h:203
RulePreparer_sp rulePreparer
Stores the RulePreparer used by this iterator.
Definition: PreparedGTS.h:127
IDType currentRuleID
Stores an ID which will be set as the original rule ID from which any rules added by insert(...
Definition: PreparedGTS.h:275
StdRuleMapCB(PreparedGTS &gts)
Creates a new CollectionCallback to the given PreparedGTS standard rule map.
Definition: PreparedGTS.h:239
vector< unsigned int > * currentQuant
Stores a count for each Quantification of the UQRule storing how often each Quantification will be us...
Definition: PreparedGTS.h:133
shared_ptr< RulePreparer > RulePreparer_sp
Alias for a shared pointer of a RulePreparer.
Definition: RulePreparer.h:105
shared_ptr< Rule > Rule_sp
Alias for a shared pointer to a Rule.
Definition: Rule.h:105
void createInstancesUpTo(IDType const &ruleID, size_t bound)
Creates and stores all UQRuleInstances for the given UQRule up to the given bound.
Definition: PreparedGTS.cpp:108
unsigned int sumCurrentQuant()
Sums up how much instantiations will be performed when using the current value of currentQuant...
Definition: PreparedGTS.cpp:223
uqinst_iterator(PreparedGTS::uqinst_iterator &&old)
Move constructor.
Definition: PreparedGTS.cpp:146
shared_ptr< UQRuleInstance > UQRuleInstance_sp
Alias of a shared pointer to a UQRuleIstance.
Definition: UQRuleInstance.h:139
shared_ptr< PreparedGTS const > PreparedGTS_csp
Alias of a shared pointer to a constant PreparedGTS.
Definition: PreparedGTS.h:289
unsigned int bound
Stores the bound to which UQRuleInstances are generated.
Definition: PreparedGTS.h:144
PreparedGTS::uqinst_iterator & operator++()
Computes the next UQRuleInstance of the UQRule corresponding to this iterator.
Definition: PreparedGTS.cpp:232
shared_ptr< vector< graphs::AnonRule_csp > > getOriginalRules(IDType id) const
Creates a new collection which contains all original rules from which the prepared rule with the give...
Definition: PreparedGTS.cpp:75
This template provides a possibility to add elements to a collection without having a reference to th...
Definition: CollectionCallback.h:34
vector< graphs::UQRuleInstance_sp > * currentInstances
Stores the UQRuleInstances generated by preparing a last computed UQRuleInstance. ...
Definition: PreparedGTS.h:139
PreparedGTS::uqinst_iterator beginUQInstances(IDType const &ruleID, graphs::Hypergraph const &graph)
Creates and returns an iterator, iterating over all UQRuleInstances of the UQRule with the given ID...
Definition: PreparedGTS.cpp:95
RulePreparer_sp rulePreparer
Stores the RulePreparer used by this PreparedGTS.
Definition: PreparedGTS.h:208
virtual ~PreparedGTS()
Destroys this PreparedGTS.
Definition: PreparedGTS.cpp:72
A Hypergraph represents a graph with a unique identifier.
Definition: Hypergraph.h:35
virtual void insert(graphs::Rule_sp rule)
Adds the given Rule to the standard rule map of the PreparedGTS.
Definition: PreparedGTS.h:251
The uqinst_iterator generates UQRuleInstances for backward application.
Definition: PreparedGTS.h:52
shared_ptr< UQRule > UQRule_sp
Alias for a shared pointer to a UQRule.
Definition: UQRule.h:261
graphs::UQRuleInstance_sp operator*()
Returns the last UQRuleInstance computed by this iterator (i.e.
Definition: PreparedGTS.cpp:237
const RuleMap oldStdRules
Stores the RuleMap containing the (unprepared) rules of the original GTS.
Definition: PreparedGTS.h:196
unordered_map< IDType, Rule_sp > RuleMap
An alias for the map storing standard rules.
Definition: GTS.h:44
bool hasEnded()
Returns true, if this iterator has ended, i.e.
Definition: PreparedGTS.cpp:245
void setCurrentRuleID(IDType id)
Sets the ID of the rule which was used to generate any subsequently added (prepared) rules (until the...
Definition: PreparedGTS.h:260
The GTS class is the data structure for a graph transformation system.
Definition: GTS.h:36
unordered_map< IDType, vector< graphs::UQRuleInstance_sp > > uqRuleInstances
For each ID of a UQRule (key) this map stores all UQRuleInstances (value) generated for the correspon...
Definition: PreparedGTS.h:214
~uqinst_iterator()
Destroys this iterator.
Definition: PreparedGTS.cpp:174
GTS(string name="", RuleMap const &rules=(RuleMap()), UQRuleMap const &uqRules=(UQRuleMap()), vector< Hypergraph_sp > const &initialGraphs=vector< Hypergraph_sp >())
Generates a new GTS with the given name, standard rule set, quantified rule set and initial graphs...
Definition: GTS.cpp:29
PreparedGTS & gts
Stores a reference to the PreparedGTS to which Rules will be added by this callback.
Definition: PreparedGTS.h:269
The PreparedGTS class represents a graph transformation system that was prepared for use in the backw...
Definition: PreparedGTS.h:40
shared_ptr< PreparedGTS > PreparedGTS_sp
Alias of a shared pointer to a PreparedGTS.
Definition: PreparedGTS.h:284
unsigned int IDType
IDType is an (unsigned) integer specifically used as an Identifier of graphs, elements of graphs or a...
Definition: globals.h:53
virtual ~StdRuleMapCB()
Destroys this StdRuleMapCB, not affecting the references PreparedGTS.
Definition: PreparedGTS.h:244