Skip to content

Commit

Permalink
Merge pull request #43 from tand00/main
Browse files Browse the repository at this point in the history
SMC features for discrete verification
  • Loading branch information
srba authored Sep 17, 2024
2 parents 7d0ac09 + fdd09b0 commit 6ed88bc
Show file tree
Hide file tree
Showing 49 changed files with 3,907 additions and 122 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand All @@ -26,17 +26,17 @@ jobs:
- name: Prebuild
run: |
mkdir build && cd build
CC=gcc-10 CXX=g++-10 cmake ../ -DCMAKE_BUILD_TYPE=Prebuild
CC=gcc-11 CXX=g++-11 cmake ../ -DCMAKE_BUILD_TYPE=Prebuild
make
- name: Build
run: |
cd build
CC=gcc-10 CXX=g++-10 cmake ../ -DCMAKE_BUILD_TYPE=Release
CC=gcc-11 CXX=g++-11 cmake ../ -DCMAKE_BUILD_TYPE=Release
make
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: verifydtapn-linux64
path: '${{github.workspace}}/build/verifydtapn/bin/verifydtapn-linux64'
6 changes: 3 additions & 3 deletions .github/workflows/build-macos-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ jobs:
- name: Prebuild
run: |
mkdir build && cd build
CC=gcc-11 CXX=g++-11 cmake ../ -DCMAKE_BUILD_TYPE=Prebuild -DBISON_EXECUTABLE=/opt/homebrew/opt/bison/bin/bison -DFLEX_EXECUTABLE=/opt/homebrew/opt/flex/bin/flex
CC=gcc-14 CXX=g++-14 cmake ../ -DCMAKE_BUILD_TYPE=Prebuild -DBISON_EXECUTABLE=/opt/homebrew/opt/bison/bin/bison -DFLEX_EXECUTABLE=/opt/homebrew/opt/flex/bin/flex
make
- name: Build
run: |
cd build
CC=gcc-11 CXX=g++-11 cmake ../ -DCMAKE_BUILD_TYPE=Release -DBISON_EXECUTABLE=/opt/homebrew/opt/bison/bin/bison -DFLEX_EXECUTABLE=/opt/homebrew/opt/flex/bin/flex
CC=gcc-14 CXX=g++-14 cmake ../ -DCMAKE_BUILD_TYPE=Release -DBISON_EXECUTABLE=/opt/homebrew/opt/bison/bin/bison -DFLEX_EXECUTABLE=/opt/homebrew/opt/flex/bin/flex
make
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: verifydtapn-arm64
path: '${{github.workspace}}/build/verifydtapn/bin/verifydtapn-osx64'
6 changes: 3 additions & 3 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ jobs:
- name: Prebuild
run: |
mkdir build && cd build
CC=gcc-11 CXX=g++-11 cmake ../ -DCMAKE_BUILD_TYPE=Prebuild -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison -DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex
CC=gcc-14 CXX=g++-14 cmake ../ -DCMAKE_BUILD_TYPE=Prebuild -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison -DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex
make
- name: Build
run: |
cd build
CC=gcc-11 CXX=g++-11 cmake ../ -DCMAKE_BUILD_TYPE=Release -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison -DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex
CC=gcc-14 CXX=g++-14 cmake ../ -DCMAKE_BUILD_TYPE=Release -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison -DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex
make
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: verifydtapn-osx64
path: '${{github.workspace}}/build/verifydtapn/bin/verifydtapn-osx64'
4 changes: 3 additions & 1 deletion .github/workflows/build-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install flex bison mingw-w64-x86-64-dev mingw-w64-tools g++-mingw-w64-x86-64 wine wine-binfmt
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
- name: Prebuild
run: |
Expand All @@ -39,7 +41,7 @@ jobs:
CPATH=$PREFIX/include make
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: verifydtapn-win64
path: '${{runner.workspace}}/verifydtapn/build/verifydtapn/bin/verifydtapn-win64.exe'
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if (VERIFYDTAPN_GetDependencies)

ExternalProject_add(unfoldtacpn-ext
GIT_REPOSITORY https://github.com/TAPAAL/unfoldTACPN
GIT_TAG 5948ffff5a084eccef7c2758b8df371b170fa68d
GIT_TAG main #5948ffff5a084eccef7c2758b8df371b170fa68d
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DFLEX_EXECUTABLE=${FLEX_EXECUTABLE} -DBISON_EXECUTABLE=${BISON_EXECUTABLE}
)

Expand Down
14 changes: 13 additions & 1 deletion include/Core/Query/AST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,16 @@ namespace VerifyTAPN {
int place;
};

// EF : Reachability
// AG : Safety
// EG : Preservability
// AF : Liveness
// CF : Control liveness
// CG : Control Safety
// PF : Probability Finally
// PG : Probability Globally
enum Quantifier {
EF, AG, EG, AF, CF, CG
EF, AG, EG, AF, CF, CG, PF, PG
};

class Query : public Visitable {
Expand Down Expand Up @@ -492,6 +500,10 @@ namespace VerifyTAPN {
quantifier = q;
}

bool hasSMCQuantifier() const {
return quantifier == PF || quantifier == PG;
}

private:
Quantifier quantifier;
Expression *expr;
Expand Down
65 changes: 65 additions & 0 deletions include/Core/Query/SMCQuery.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef SMCQUERIES_H
#define SMCQUERIES_H

#include "AST.hpp"
#include <PQL/SMCExpressions.h>

namespace VerifyTAPN::AST {

struct SMCSettings {
int timeBound;
int stepBound;
float falsePositives;
float falseNegatives;
float indifferenceRegionUp;
float indifferenceRegionDown;
float confidence;
float estimationIntervalWidth;
bool compareToFloat;
float geqThan;

static SMCSettings fromPQL(unfoldtacpn::PQL::SMCSettings settings);
};

class SMCQuery : public Query {
public:

SMCQuery(Quantifier quantifier, SMCSettings settings, Expression *expr)
: Query(quantifier, expr), smcSettings(settings)
{ };

SMCQuery(const SMCQuery &other)
: Query(other.quantifier, other.expr->clone()), smcSettings(other.smcSettings)
{ };

SMCQuery &operator=(const SMCQuery &other) {
if (&other != this) {
delete expr;
expr = other.expr->clone();
smcSettings = other.smcSettings;
}
return *this;
}

virtual SMCQuery *clone() const;

void accept(Visitor &visitor, Result &context) override;


void setSMCSettings(SMCSettings newSettings) {
smcSettings = newSettings;
}

SMCSettings& getSmcSettings() {
return smcSettings;
}

private:
Quantifier quantifier;
Expression *expr;
SMCSettings smcSettings;
};

}

#endif
2 changes: 2 additions & 0 deletions include/Core/Query/TranslationVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace VerifyTAPN {
void _accept(const unfoldtacpn::PQL::EGCondition *condition) override;
void _accept(const unfoldtacpn::PQL::AGCondition *condition) override;
void _accept(const unfoldtacpn::PQL::AFCondition *condition) override;
void _accept(const unfoldtacpn::PQL::PFCondition *condition) override;
void _accept(const unfoldtacpn::PQL::PGCondition *condition) override;
void _accept(const unfoldtacpn::PQL::BooleanCondition *element) override;
void _accept(const unfoldtacpn::PQL::UnfoldedIdentifierExpr *element) override;
void _accept(const unfoldtacpn::PQL::LiteralExpr *element) override;
Expand Down
117 changes: 117 additions & 0 deletions include/Core/TAPN/StochasticStructure.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#ifndef STOCHASTIC_STRUCTURE
#define STOCHASTIC_STRUCTURE

#include <random>
#include <sstream>
#include <string>

namespace VerifyTAPN::SMC {

enum FiringMode {
Oldest,
Youngest,
Random
};

std::string firingModeName(FiringMode type);

enum DistributionType {
Constant,
Uniform,
Exponential,
Normal,
Gamma,
Erlang,
DiscreteUniform,
Geometric
};

std::string distributionName(DistributionType type);

struct SMCUniformParameters {
double a;
double b;
};
struct SMCExponentialParameters {
double rate;
};
struct SMCNormalParameters {
double mean;
double stddev;
};
struct SMCConstantParameters {
double value;
};
struct SMCGammaParameters {
double shape;
double scale;
};
struct SMCDiscreteUniformParameters {
int a;
int b;
};
struct SMCGeometricParameters {
double p;
};

union DistributionParameters {
SMCUniformParameters uniform;
SMCExponentialParameters exp;
SMCNormalParameters normal;
SMCConstantParameters constant;
SMCGammaParameters gamma;
SMCDiscreteUniformParameters discreteUniform;
SMCGeometricParameters geometric;
};

struct Distribution {
DistributionType type;
DistributionParameters parameters;

template<typename T>
double sample(T& engine, const unsigned int precision = 0) const {
double date = 0;
switch(type) {
case Constant:
date = parameters.constant.value;
break;
case Uniform:
date = std::uniform_real_distribution(parameters.uniform.a, parameters.uniform.b)(engine);
break;
case Exponential:
date = std::exponential_distribution(parameters.exp.rate)(engine);
break;
case Normal:
date = std::normal_distribution(parameters.normal.mean, parameters.normal.stddev)(engine);
break;
case Gamma:
case Erlang:
date = std::gamma_distribution(parameters.gamma.shape, parameters.gamma.scale)(engine);
break;
case DiscreteUniform:
date = std::uniform_int_distribution(parameters.discreteUniform.a, parameters.discreteUniform.b)(engine);
break;
case Geometric:
date = std::geometric_distribution(parameters.geometric.p)(engine);
break;
}
if(precision > 0) {
double factor = pow(10.0, precision);
date = round(date * factor) / factor;
}
return std::max(date, 0.0);
}

static Distribution urgent();

static Distribution defaultDistribution();

static Distribution fromParams(int distrib_id, double param1, double param2);

std::string toXML() const;

};

}

#endif
2 changes: 1 addition & 1 deletion include/Core/TAPN/TAPNModelBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace VerifyTAPN {
double y = 0) override;

virtual void addTransition(const std::string &name, int player, bool urgent,
double, double) override;
double, double, int distrib_id = 0, double param1 = 1.0, double param2 = 0.0, double weight = 1.0, int firingMode = 0) override;

virtual void addInputArc(const std::string &place,
const std::string &transition,
Expand Down
7 changes: 7 additions & 0 deletions include/Core/TAPN/TimeInterval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ namespace VerifyTAPN { namespace TAPN {
return number >= lowerBound && number <= upperBound;
}

inline bool contains(double number) const {
return
(number >= (double) lowerBound && number <= (double) upperBound) ||
(std::abs(number - (double) lowerBound) <= std::numeric_limits<double>::epsilon() * 4) ||
(std::abs(number - (double) upperBound) <= std::numeric_limits<double>::epsilon() * 4);
}

inline bool intersects(const TimeInterval &other) const {
assert(!leftStrict);
assert(!other.leftStrict);
Expand Down
Loading

0 comments on commit 6ed88bc

Please sign in to comment.