Skip to content

Commit 6d71790

Browse files
authored
Merge pull request #36 from sillydan1/patch/correct-cross-edge
This MR fixes an issue during tock-change evaluation, when there are multiple edges with guards containing external variables - then GetNextTockStates calculated all changes combined. This MR changes that, so each edge and guard expression is handled individually.
2 parents dca1412 + c8e23a2 commit 6d71790

File tree

6 files changed

+23
-31
lines changed

6 files changed

+23
-31
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# 3.16+ because of target_precompiled_header
1818
cmake_minimum_required(VERSION 3.16)
19-
project(aaltitoad VERSION 0.10.0)
19+
project(aaltitoad VERSION 0.10.1)
2020
configure_file(src/config.h.in config.h)
2121
set(THREADS_PREFER_PTHREAD_FLAG ON)
2222
find_package(Threads REQUIRED)

src/cli/CLIConfig.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ std::vector<option_t> CLIConfig::GetCLIOptionsOnly() {
8282
std::transform(cliOptions.begin(), cliOptions.end(),
8383
std::back_inserter(output),
8484
[](std::pair<option_requirement, option_t> element) -> option_t { return element.second; });
85-
add_help_option(output);
8685
return output;
8786
}
8887

src/verifier/ReachabilitySearcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool ReachabilitySearcher::ForwardReachabilitySearch(const nondeterminism_strate
255255
stateit = PickStateFromWaitingList(strategy);
256256
}
257257
spdlog::info("Found a negative result after searching: {0} states", Passed.size());
258-
if(CLIConfig::getInstance()["verbosity"].as_integer() >= 6)
258+
if(CLIConfig::getInstance()["verbosity"].as_integer_or_default(0) >= 6)
259259
debug_print_passed_list(*this);
260260
if(!CLIConfig::getInstance()["notrace"])
261261
return query_results.size() - PrintResults(query_results) == 0;

src/verifier/TTASuccessorGenerator.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ std::vector<TTA::StateChange> TTASuccessorGenerator::GetNextTickStates(const TTA
2525
return tta.GetNextTickStates(nondeterminism_strategy_t::VERIFICATION);
2626
}
2727

28-
std::vector<VariablePredicate> TTASuccessorGenerator::GetInterestingVariablePredicatesInState(const TTA &ttaState) {
28+
std::vector<std::vector<VariablePredicate>> TTASuccessorGenerator::GetInterestingVariablePredicatesInState(const TTA &ttaState) {
2929
// Get all edges that we may be able to take.
3030
auto currentEdges = ttaState.GetCurrentEdges();
3131
// Filter over the "interesting" edges
3232
currentEdges.erase(std::remove_if(currentEdges.begin(), currentEdges.end(),
3333
[](const auto& edge){ return !edge.ContainsExternalChecks(); }), currentEdges.end());
3434
// Extract predicates based on the guards of those edges
35-
std::vector<VariablePredicate> preds{};
35+
std::vector<std::vector<VariablePredicate>> all_preds{};
3636
for(auto& edge : currentEdges) {
37+
std::vector<VariablePredicate> preds{};
3738
for(auto& expr : edge.externalGuardCollection)
3839
preds.push_back(ConvertFromGuardExpression(expr, ttaState));
40+
all_preds.push_back(preds);
3941
}
40-
return preds; // TODO: Check for uniqueness and/or satisfiability
42+
return all_preds; // TODO: Check for uniqueness and/or satisfiability
4143
}
4244

4345
VariablePredicate TTASuccessorGenerator::ConvertFromGuardExpression(const TTA::GuardExpression &expressionTree, const TTA& ttaState) {
@@ -193,35 +195,25 @@ std::vector<TTA::StateChange> BFSCrossProduct(const VariableValueVector& a, cons
193195
std::vector<TTA::StateChange> TTASuccessorGenerator::GetNextTockStates(const TTA& ttaState) {
194196
// Get all the interesting variable predicates
195197
auto interestingVarPredicates = GetInterestingVariablePredicatesInState(ttaState);
196-
if(interestingVarPredicates.empty())
198+
std::vector<TTA::StateChange> return_value{};
199+
for(auto& preds : interestingVarPredicates) {
200+
auto changes = GetNextTockStatesFromPredicates(preds, ttaState.GetSymbols());
201+
return_value.insert(return_value.end(), changes.begin(), changes.end());
202+
}
203+
return return_value;
204+
}
205+
206+
std::vector<TTA::StateChange> TTASuccessorGenerator::GetNextTockStatesFromPredicates(const std::vector<VariablePredicate>& predicates, const TTA::SymbolMap& symbols) {
207+
if(predicates.empty())
197208
return {};
198209
VariableValueVector positives{};
199210
VariableValueVector negatives{};
200-
for (auto& predicate : interestingVarPredicates) {
211+
for (auto& predicate : predicates) {
201212
positives.emplace_back(predicate.variable, predicate.GetValueOverTheEdge());
202213
negatives.emplace_back(predicate.variable, predicate.GetValueOnTheEdge());
203214
}
204-
int limit = -1;
205-
auto size = interestingVarPredicates.size();
206-
if(CLIConfig::getInstance()["explosion-limit"])
207-
limit = CLIConfig::getInstance()["explosion-limit"].as_integer();
215+
auto size = predicates.size();
208216
spdlog::trace("Size of the set of interesting changes is {0}, this means you will get {1} new states",
209217
size, static_cast<int>(pow(2, size)));
210-
if(size < limit || limit == -1)
211-
return SymbolsCrossProduct(positives, negatives, size, ttaState.GetSymbols());
212-
spdlog::warn("The Tock explosion was too large, trying a weaker strategy - This will likely result in wrong answers.");
213-
// TODO: This is technically incorrect. These state changes may have an effect on the reachable state space if they are applied together
214-
std::vector<TTA::StateChange> allChanges{};
215-
for(auto& positive : positives) {
216-
TTA::StateChange stP{}; // Positive path
217-
AssignVariable(stP.symbols, ttaState.GetSymbols(), positive.varname, positive.symbol);
218-
allChanges.push_back(stP);
219-
}
220-
for(auto& negative : negatives) {
221-
TTA::StateChange stN{}; // Negative path
222-
AssignVariable(stN.symbols, ttaState.GetSymbols(), negative.varname, negative.symbol);
223-
allChanges.push_back(stN);
224-
}
225-
spdlog::trace("Amount of Tock changes: {0}", allChanges.size());
226-
return allChanges;
218+
return SymbolsCrossProduct(positives, negatives, size, symbols);
227219
}

src/verifier/TTASuccessorGenerator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class TTASuccessorGenerator {
2626
/// Gets the set of states that are reachable in the given state (no tocking implications)
2727
static std::vector<TTA::StateChange> GetNextTickStates(const TTA& ttaStateAndGraph);
2828
/// Gets all the predicates
29-
static std::vector<VariablePredicate> GetInterestingVariablePredicatesInState(const TTA& ttaState);
29+
static std::vector<std::vector<VariablePredicate>> GetInterestingVariablePredicatesInState(const TTA& ttaState);
3030
/// A more efficient way of checking if the state is interesting, than getting an empty vector
3131
static bool IsStateInteresting(const TTA& ttaState);
3232
/// Finds and applies all available interesting predicates
3333
static std::vector<TTA::StateChange> GetNextTockStates(const TTA& ttaState);
34+
static std::vector<TTA::StateChange> GetNextTockStatesFromPredicates(const std::vector<VariablePredicate>& predicates, const TTA::SymbolMap& symbols);
3435

3536
private:
3637
static VariablePredicate ConvertFromGuardExpression(const TTA::GuardExpression& expressionTree, const TTA& ttaState);

0 commit comments

Comments
 (0)