mirror of
http://172.16.200.102/MOISE/Timed-Altarica-To-Fiacre-Translator.git
synced 2025-12-03 08:17:58 +01:00
Initial commit.
This commit is contained in:
1
src/CMakeFiles/progress.marks
Normal file
1
src/CMakeFiles/progress.marks
Normal file
@@ -0,0 +1 @@
|
||||
100
|
||||
45
src/CMakeLists.txt
Normal file
45
src/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
# This file is part of EPOCH.
|
||||
# File: CMakeLists.txt
|
||||
# Author: Florent Teichteil-Königsbuch
|
||||
# Contact: florent.teichteil@onera.fr
|
||||
#
|
||||
# EPOCH is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# EPOCH is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
FIND_PACKAGE (BISON REQUIRED)
|
||||
FIND_PACKAGE (FLEX REQUIRED)
|
||||
FIND_PACKAGE (BLAS)
|
||||
FIND_PACKAGE (UMFPACK REQUIRED)
|
||||
FIND_PACKAGE (LAPACK REQUIRED)
|
||||
|
||||
|
||||
IF (BLAS_FOUND)
|
||||
ADD_DEFINITIONS(-DHAVE_BLAS)
|
||||
MESSAGE (STATUS "System's BLAS implementation found: ${BLAS_LIBRARIES}")
|
||||
ELSE (BLAS_FOUND)
|
||||
MESSAGE (STATUS "Using BOOST uBlas implementation of BLAS (may lead to poor performances)")
|
||||
ENDIF (BLAS_FOUND)
|
||||
|
||||
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/sdk ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)
|
||||
|
||||
ADD_SUBDIRECTORY (grammars)
|
||||
#ADD_SUBDIRECTORY (solvers)
|
||||
ADD_SUBDIRECTORY (console)
|
||||
#ADD_SUBDIRECTORY (graph)
|
||||
#ADD_SUBDIRECTORY (symbolic)
|
||||
#ADD_SUBDIRECTORY (unittests)
|
||||
|
||||
IF (BUILD_GUI)
|
||||
ADD_SUBDIRECTORY (gui)
|
||||
ENDIF (BUILD_GUI)
|
||||
|
||||
230
src/algebra/ScalarBackend.hh
Normal file
230
src/algebra/ScalarBackend.hh
Normal file
@@ -0,0 +1,230 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SCALAR_BACKEND_HH
|
||||
#define SCALAR_BACKEND_HH
|
||||
|
||||
#include <boost/numeric/ublas/traits.hpp>
|
||||
|
||||
namespace epoch {
|
||||
namespace algebra {
|
||||
class ScalarBackend {
|
||||
public :
|
||||
|
||||
struct NoTransformation {
|
||||
template <typename T>
|
||||
inline const T& operator()(const T& x) const {
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
struct ConjugateTransformation {
|
||||
template <typename T>
|
||||
inline T operator()(const T& x) const {
|
||||
return conj(x);
|
||||
}
|
||||
};
|
||||
|
||||
struct MakeRealTransformation {
|
||||
template <typename T>
|
||||
inline typename T::value_type operator()(const T& x) const {
|
||||
return 2.0 * real(x);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Scalar
|
||||
* @tparam T Type of scalar
|
||||
*/
|
||||
template <typename T>
|
||||
struct Scalar {
|
||||
/** Actual implementation */
|
||||
typedef T Implementation;
|
||||
|
||||
/**
|
||||
* Generates an identity scalar
|
||||
* @param dim USELESS
|
||||
* @return identity scalar
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> identity(const std::size_t& dim) {
|
||||
return std::auto_ptr<T>(new T(1.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a zero scalar
|
||||
* @param dim1 USELESS
|
||||
* @param dim2 USELESS
|
||||
* @return zero scalar
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2) {
|
||||
return std::auto_ptr<T>(new T(0.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given scalar
|
||||
* @param s Scalar
|
||||
* @return Conjugate of the given scalar
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& s) {
|
||||
return std::auto_ptr<T>(new T(boost::numeric::ublas::type_traits<T>::conj(s)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the real part of a given scalar
|
||||
* @param s Scalar
|
||||
* @return Real part of the given scalar
|
||||
*/
|
||||
inline static std::auto_ptr<typename boost::numeric::ublas::type_traits<T>::real_type> real(const Implementation& s) {
|
||||
return std::auto_ptr<typename boost::numeric::ublas::type_traits<T>::real_type>(
|
||||
new typename boost::numeric::ublas::type_traits<T>::real_type(boost::numeric::ublas::type_traits<T>::real(s)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given scalar
|
||||
* @param s Scalar
|
||||
* @return Imaginary part of the given scalar
|
||||
*/
|
||||
inline static std::auto_ptr<typename boost::numeric::ublas::type_traits<T>::real_type> imag(const Implementation& s) {
|
||||
return std::auto_ptr<typename boost::numeric::ublas::type_traits<T>::real_type>(
|
||||
new typename boost::numeric::ublas::type_traits<T>::real_type(boost::numeric::ublas::type_traits<T>::imag(s)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a scalar in a given output stream
|
||||
* @param s Sclar
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& s, std::ostream& o) {
|
||||
o << s;
|
||||
}
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename Tc>
|
||||
inline static void computeF1(const T& a, const T& b, const T& c, const typename Scalar<Tc>::Implementation& L, Implementation& res) {
|
||||
res += a * ((b * std::real(L)) - (c * std::imag(L)));
|
||||
}
|
||||
|
||||
/** Computes res += a * L */
|
||||
inline static void computeF2(const T& a, const Implementation& L, Implementation& res) {
|
||||
res += a * L;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline std::auto_ptr<T> initialize() const {
|
||||
return std::auto_ptr<T>(new T());
|
||||
};
|
||||
|
||||
// computeO1(a, M, tm, V, tv, res): res = a * tm(M) * tv(V)
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline void computeO1(const T1& a,
|
||||
const T2& M, const T3& mTransformation,
|
||||
const T4& V, const T5& vTransformation,
|
||||
T6& res) const {
|
||||
res = a * mTransformation(M) * vTransformation(V);
|
||||
}
|
||||
|
||||
// computeO2p(V, tv, res): res += tv(V)
|
||||
template <typename T1, typename T2, typename T3>
|
||||
inline void computeO2p(const T1& V, const T2& vTransformation,
|
||||
T3& res) const {
|
||||
res += vTransformation(V);
|
||||
};
|
||||
|
||||
// computeO2m(V, tv, res): res -= tv(V)
|
||||
template <typename T1, typename T2, typename T3>
|
||||
inline void computeO2m(const T1& V, const T2& vTransformation,
|
||||
T3& res) const {
|
||||
res -= vTransformation(V);
|
||||
};
|
||||
|
||||
// computeO3(a, M, tm, V, tv, res): res = a * ((tm(M) * tv(V)) - res)
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline void computeO3(const T1& a,
|
||||
const T2& M, const T3& mTransformation,
|
||||
const T4& V, const T5& vTransformation,
|
||||
T6& res) const {
|
||||
res = a * ((mTransformation(M) * vTransformation(V)) - res);
|
||||
};
|
||||
|
||||
// computeO4p(M, tM, V, tV, res, mr): res += mr(tm(M) * tv(V))
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline void computeO4p(const T1& M, const T2& mTransformation,
|
||||
const T3& V, const T4& vTransformation,
|
||||
T5& res, const T6& resTransformation) const {
|
||||
res += resTransformation(mTransformation(M) * vTransformation(V));
|
||||
}
|
||||
|
||||
// computeO4m(M, tM, V, tV, res, mr): res -= mr(tm(M) * tv(V))
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline void computeO4m(const T1& M, const T2& mTransformation,
|
||||
const T3& V, const T4& vTransformation,
|
||||
T5& res, const T6& resTransformation) const {
|
||||
res -= resTransformation(mTransformation(M) * vTransformation(V));
|
||||
}
|
||||
|
||||
// computeO5(a, M, tm, res): res = a * tm(M)
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
inline void computeO5(const T1& a,
|
||||
const T2& M, const T3& mTransformation,
|
||||
T4& res) const {
|
||||
res = a * mTransformation(M);
|
||||
}
|
||||
|
||||
// computeO6(a, M1, tm1, M2, tm2, res): res = a * (tm1(M1) - tm2(M2))
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline void computeO6(const T1& a,
|
||||
const T2& M1, const T3& m1Transformation,
|
||||
const T4& M2, const T5& m2Transformation,
|
||||
T6& res) const {
|
||||
res = a * (m1Transformation(M1) - m2Transformation(M2));
|
||||
}
|
||||
|
||||
// computeO7(M, tm, V, tv, res): res = tm(M) * tv(V)
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline void computeO7(const T1& M, const T2& mTransformation,
|
||||
const T3& V, const T4& vTransformation,
|
||||
T5& res) const {
|
||||
res = mTransformation(M) * vTransformation(V);
|
||||
}
|
||||
|
||||
// computeO8(a, res): res *= a
|
||||
template <typename T1, typename T2>
|
||||
inline void computeO8(const T1& a, T2& res) const {
|
||||
res *= a;
|
||||
}
|
||||
|
||||
// computeO9(a, M, res): res = a * (res - M)
|
||||
template <typename T1, typename T2, typename T3>
|
||||
inline void computeO9(const T1& a,
|
||||
const T2& M,
|
||||
T3& res) const {
|
||||
res = a * (res - M);
|
||||
}
|
||||
}; // class ScalarBackend
|
||||
} // namespace algebra
|
||||
} // namespace epoch
|
||||
|
||||
#endif // SCALAR_BACKEND_HH
|
||||
844
src/algebra/UblasBackend.hh
Normal file
844
src/algebra/UblasBackend.hh
Normal file
@@ -0,0 +1,844 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef UBLAS_BACKEND_HH
|
||||
#define UBLAS_BACKEND_HH
|
||||
|
||||
#include <boost/numeric/ublas/matrix_proxy.hpp>
|
||||
#include <boost/numeric/ublas/vector_proxy.hpp>
|
||||
#include <boost/numeric/ublas/operation.hpp>
|
||||
#include <boost/numeric/ublas/triangular.hpp>
|
||||
#include <boost/numeric/ublas/io.hpp>
|
||||
|
||||
#include <boost/numeric/bindings/lapack.hpp>
|
||||
#include <boost/numeric/bindings/blas.hpp>
|
||||
#include <boost/numeric/bindings/ublas/vector.hpp>
|
||||
#include <boost/numeric/bindings/ublas/matrix.hpp>
|
||||
#include <boost/numeric/bindings/ublas/banded.hpp>
|
||||
#include <boost/numeric/bindings/ublas/triangular.hpp>
|
||||
#include <boost/numeric/bindings/conj.hpp>
|
||||
#include <boost/numeric/bindings/trans.hpp>
|
||||
#include <boost/numeric/bindings/herm.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ScalarBackend.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace algebra {
|
||||
/** Ublas standard backend with upper Hessenberg matrices as banded matrices */
|
||||
struct UblasBandedHessenberg {
|
||||
/**
|
||||
* Implementation of upper Hessenberg matrices
|
||||
* @tparam Type of elements stored in matrices and vectors
|
||||
*/
|
||||
template <typename T>
|
||||
struct MatrixType {
|
||||
typedef boost::numeric::ublas::banded_matrix<T, boost::numeric::ublas::column_major> Implementation;
|
||||
|
||||
/**
|
||||
* Generates a square identity upper Hessenberg matrix
|
||||
* @param dim Dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to identity
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> identity(const std::size_t& dim);
|
||||
|
||||
/**
|
||||
* Generates a zero upper Hessenberg matrix
|
||||
* @param dim1 First dimension of the matrix
|
||||
* @param dim2 Second dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to zero
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2);
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Conjugate of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the real part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Real part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> real(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Imaginary part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> imag(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Prints an upper Hessenberg matrix in a given output stream
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& m, std::ostream& o);
|
||||
};
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename T, typename Tc>
|
||||
static void computeF1(const T& a, const T& b, const T& c, const typename MatrixType<Tc>::Implementation& L, typename MatrixType<T>::Implementation& res);
|
||||
|
||||
/** Computes res += a * L */
|
||||
template <typename T>
|
||||
static void computeF2(const T& a, const typename MatrixType<T>::Implementation& L, typename MatrixType<T>::Implementation& res);
|
||||
};
|
||||
|
||||
|
||||
/** Ublas standard backend with upper Hessenberg matrices as triangular matrices plus a vector representing the additional diagonal */
|
||||
struct UblasTriangularHessenberg {
|
||||
/**
|
||||
* Implementation of upper Hessenberg matrices
|
||||
* @tparam Type of elements stored in matrices and vectors
|
||||
*/
|
||||
template <typename T>
|
||||
struct MatrixType {
|
||||
struct Implementation {
|
||||
typedef boost::numeric::ublas::triangular_matrix<T, boost::numeric::ublas::upper, boost::numeric::ublas::column_major> UpperTriangleType;
|
||||
typedef boost::numeric::ublas::vector<T> DiagonalVectorType;
|
||||
|
||||
UpperTriangleType upperTriangle;
|
||||
DiagonalVectorType diagonalVector;
|
||||
|
||||
const T& operator()(const std::size_t& i, const std::size_t& j) const;
|
||||
T& operator()(const std::size_t& i, const std::size_t& j);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a square identity upper Hessenberg matrix
|
||||
* @param dim Dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to identity
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> identity(const std::size_t& dim);
|
||||
|
||||
/**
|
||||
* Generates a zero upper Hessenberg matrix
|
||||
* @param dim1 First dimension of the matrix
|
||||
* @param dim2 Second dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to zero
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2);
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Conjugate of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the real part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Real part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> real(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Imaginary part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> imag(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Prints an upper Hessenberg matrix in a given output stream
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& m, std::ostream& o);
|
||||
};
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename T, typename Tc>
|
||||
static void computeF1(const T& a, const T& b, const T& c, const typename MatrixType<Tc>::Implementation& L, typename MatrixType<T>::Implementation& res);
|
||||
|
||||
/** Computes res += a * L */
|
||||
template <typename T>
|
||||
static void computeF2(const T& a, const typename MatrixType<T>::Implementation& L, typename MatrixType<T>::Implementation& res);
|
||||
};
|
||||
|
||||
|
||||
/** Ublas BLAS backend with dense upper Hessenberg matrices (time efficient, but memory inefficient) */
|
||||
struct UblasDenseHessenberg {
|
||||
/**
|
||||
* Implementation of upper Hessenberg matrices
|
||||
* @tparam Type of elements stored in matrices and vectors
|
||||
*/
|
||||
template <typename T>
|
||||
struct MatrixType {
|
||||
typedef boost::numeric::ublas::matrix<T, boost::numeric::ublas::column_major> Implementation;
|
||||
|
||||
/**
|
||||
* Generates a square identity upper Hessenberg matrix
|
||||
* @param dim Dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to identity
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> identity(const std::size_t& dim);
|
||||
|
||||
/**
|
||||
* Generates a zero upper Hessenberg matrix
|
||||
* @param dim1 First dimension of the matrix
|
||||
* @param dim2 Second dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to zero
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2);
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Conjugate of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the real part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Real part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> real(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Imaginary part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> imag(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Prints an upper Hessenberg matrix in a given output stream
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& m, std::ostream& o);
|
||||
};
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename T, typename Tc>
|
||||
static void computeF1(const T& a, const T& b, const T& c, const typename MatrixType<Tc>::Implementation& L, typename MatrixType<T>::Implementation& res);
|
||||
|
||||
/** Computes res += a * L */
|
||||
template <typename T>
|
||||
static void computeF2(const T& a, const typename MatrixType<T>::Implementation& L, typename MatrixType<T>::Implementation& res);
|
||||
};
|
||||
|
||||
/** Standard Ublas backend */
|
||||
struct UblasBackendStandard {};
|
||||
|
||||
/** Optimized BLAS Ublas backend */
|
||||
struct UblasBackendBLAS {};
|
||||
|
||||
/**
|
||||
* Class representing uBlas-based backend for EPOCH algorithms
|
||||
* @tparam T Type of real numbers
|
||||
*/
|
||||
template <typename Thessenberg = UblasBandedHessenberg, typename Tbackend = UblasBackendStandard>
|
||||
class UblasBackend {
|
||||
public :
|
||||
/**
|
||||
* Default matrix
|
||||
* @tparam T Type of elements of the matrix
|
||||
*/
|
||||
template <typename T>
|
||||
struct Matrix {
|
||||
/** Actual implementation */
|
||||
typedef boost::numeric::ublas::matrix<T, boost::numeric::ublas::column_major> Implementation;
|
||||
|
||||
/**
|
||||
* Generates a square identity dense matrix
|
||||
* @param dim Dimension of the matrix
|
||||
* @return Dense matrix equal to identity
|
||||
*/
|
||||
static std::auto_ptr<Implementation> identity(const std::size_t& dim);
|
||||
|
||||
/**
|
||||
* Generates a zero dense matrix
|
||||
* @param dim1 First dimension of the matrix
|
||||
* @param dim2 Second dimension of the matrix
|
||||
* @return Dense matrix equal to zero
|
||||
*/
|
||||
static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2);
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given matrix
|
||||
* @param m Matrix
|
||||
* @return Conjugate of the given matrix
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the real part of a given matrix
|
||||
* @param m matrix
|
||||
* @return Real part of the given matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename Matrix<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> real(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given matrix
|
||||
* @param m Matrix
|
||||
* @return Imaginary part of the given matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename Matrix<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> imag(const Implementation& m);
|
||||
|
||||
/**
|
||||
* Prints a matrix in a given output stream
|
||||
* @param m Matrix
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& m, std::ostream& o);
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename Tc>
|
||||
static void computeF1(const T& a, const T& b, const T& c, const typename Matrix<Tc>::Implementation& L, Implementation& res);
|
||||
|
||||
/** Computes res += a * L */
|
||||
static void computeF2(const T& a, const Implementation& L, Implementation& res);
|
||||
};
|
||||
|
||||
/**
|
||||
* Upper Hessenberg matrix
|
||||
* @tparam T Type of elements of the matrix
|
||||
*/
|
||||
template <typename T>
|
||||
struct HessenbergMatrix {
|
||||
/** Actual implementation */
|
||||
typedef typename Thessenberg::template MatrixType<T>::Implementation Implementation;
|
||||
|
||||
/**
|
||||
* Generates a square identity upper Hessenberg matrix
|
||||
* @param dim Dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to identity
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> identity(const std::size_t& dim) {
|
||||
return Thessenberg::template MatrixType<T>::identity(dim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a zero upper Hessenberg matrix
|
||||
* @param dim1 First dimension of the matrix
|
||||
* @param dim2 Second dimension of the matrix
|
||||
* @return Upper Hessenberg matrix equal to zero
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2) {
|
||||
return Thessenberg::template MatrixType<T>::zero(dim1, dim2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Conjugate of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& m) {
|
||||
return Thessenberg::template MatrixType<T>::conj(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the real part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Real part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename Thessenberg::template MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> real(const Implementation& m) {
|
||||
return Thessenberg::template MatrixType<T>::real(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given upper Hessenberg matrix
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @return Imaginary part of the given upper Hessenberg matrix
|
||||
*/
|
||||
inline static std::auto_ptr<typename Thessenberg::template MatrixType<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> imag(const Implementation& m) {
|
||||
return Thessenberg::template MatrixType<T>::imag(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an upper Hessenberg matrix in a given output stream
|
||||
* @param m Upper Hessenberg matrix
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& m, std::ostream& o) {
|
||||
Thessenberg::template MatrixType<T>::print(m, o);
|
||||
}
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename Tc>
|
||||
inline static void computeF1(const T& a, const T& b, const T& c, const typename HessenbergMatrix<Tc>::Implementation& L, Implementation& res) {
|
||||
Thessenberg::template computeF1(a, b, c, L, res);
|
||||
}
|
||||
|
||||
/** Computes res += a * L */
|
||||
inline static void computeF2(const T& a, const Implementation& L, Implementation& res) {
|
||||
Thessenberg::template computeF2(a, L, res);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Vector type
|
||||
* @tparam T Type of elements of the matrix
|
||||
*/
|
||||
template <typename T>
|
||||
struct Vector {
|
||||
/** Actual implementation */
|
||||
typedef boost::numeric::ublas::vector<T> Implementation;
|
||||
|
||||
/**
|
||||
* Generates a vector whose all entries are equal to 1
|
||||
* @param dim Dimension of the vector
|
||||
* @return Vector with all entries equal to 1
|
||||
*/
|
||||
static std::auto_ptr<Implementation> identity(const std::size_t& dim);
|
||||
|
||||
/**
|
||||
* Generates a zero vector
|
||||
* @param dim1 Dimension of the vector
|
||||
* @param dim2 Useless
|
||||
* @return Zero vector
|
||||
*/
|
||||
static std::auto_ptr<Implementation> zero(const std::size_t& dim1, const std::size_t& dim2);
|
||||
|
||||
/**
|
||||
* Computes the conjugate of a given vector
|
||||
* @param v Vector
|
||||
* @return Conjugate of the given vector
|
||||
*/
|
||||
inline static std::auto_ptr<Implementation> conj(const Implementation& v);
|
||||
|
||||
/**
|
||||
* Computes the real part of a given vector
|
||||
* @param v Vector
|
||||
* @return Real part of the given vector
|
||||
*/
|
||||
inline static std::auto_ptr<typename Vector<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> real(const Implementation& v);
|
||||
|
||||
/**
|
||||
* Computes the imaginary part of a given vector
|
||||
* @param v Vector
|
||||
* @return Imaginary part of the given vector
|
||||
*/
|
||||
inline static std::auto_ptr<typename Vector<typename boost::numeric::ublas::type_traits<T>::real_type>::Implementation> imag(const Implementation& v);
|
||||
|
||||
/**
|
||||
* Prints a vector in a given output stream
|
||||
* @param v Vector
|
||||
* @param o Output stream
|
||||
*/
|
||||
inline static void print(const Implementation& v, std::ostream& o);
|
||||
|
||||
/** Computes res += a * ((b * real(L)) - (c * imag(L))) */
|
||||
template <typename Tc>
|
||||
static void computeF1(const T& a, const T& b, const T& c, const typename Vector<Tc>::Implementation& L, Implementation& res);
|
||||
|
||||
/** Computes res += a * L */
|
||||
static void computeF2(const T& a, const Implementation& L, Implementation& res);
|
||||
};
|
||||
|
||||
/** NoTransformation functor */
|
||||
struct NoTransformation : public ScalarBackend::NoTransformation {
|
||||
template <typename T>
|
||||
inline const T& opsM(const T& t) const {return t;}
|
||||
|
||||
template <typename T>
|
||||
inline const T& opbM(const T& t) const {return t;}
|
||||
|
||||
template <typename T>
|
||||
inline const T& opsV(const T& t) const {return t;}
|
||||
|
||||
template <typename T>
|
||||
inline const T& opbV(const T& t) const {return t;}
|
||||
};
|
||||
|
||||
/** ConjugateTransformation functor */
|
||||
struct ConjugateTransformation : public ScalarBackend::ConjugateTransformation {
|
||||
template <typename E>
|
||||
inline typename boost::numeric::ublas::matrix_unary1_traits<E, boost::numeric::ublas::scalar_conj<typename E::value_type> >::result_type
|
||||
opsM(const boost::numeric::ublas::matrix_expression<E> &e) const {
|
||||
return boost::numeric::ublas::conj(e);
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
typename boost::numeric::bindings::result_of::conj<const M>::type const opbM(const M& m) const {
|
||||
return boost::numeric::bindings::conj(m);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
typename boost::numeric::ublas::vector_unary_traits<E, boost::numeric::ublas::scalar_conj<typename E::value_type> >::result_type
|
||||
opsV(const boost::numeric::ublas::vector_expression<E> &e) const {
|
||||
return boost::numeric::ublas::conj(e);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
typename boost::numeric::bindings::result_of::conj<const V>::type const opbV(const V& v) const {
|
||||
return boost::numeric::bindings::conj(v);
|
||||
}
|
||||
};
|
||||
|
||||
/** MakeRealTransformation functor */
|
||||
struct MakeRealTransformation : public ScalarBackend::MakeRealTransformation {
|
||||
template <typename T>
|
||||
struct makeRealFunctor {
|
||||
typedef T value_type;
|
||||
typedef typename T::value_type result_type;
|
||||
inline makeRealFunctor() {}
|
||||
|
||||
inline static result_type apply(const value_type& x) {
|
||||
return (2.0 * real(x));
|
||||
}
|
||||
};
|
||||
|
||||
// (op v) [i] = op( v [i] )
|
||||
template<class OP, class E>
|
||||
BOOST_UBLAS_INLINE
|
||||
typename boost::numeric::ublas::vector_unary_traits<E, OP>::result_type
|
||||
vectorApplyToAll (const boost::numeric::ublas::vector_expression<E> &e, const OP& op = OP() ) const {
|
||||
typedef typename boost::numeric::ublas::vector_unary_traits<E, OP>::expression_type expression_type;
|
||||
return expression_type (e ());
|
||||
}
|
||||
|
||||
// (op m) [i] = op( m [i] )
|
||||
template<class OP, class E>
|
||||
BOOST_UBLAS_INLINE
|
||||
typename boost::numeric::ublas::matrix_unary1_traits<E, OP>::result_type
|
||||
matrixApplyToAll (const boost::numeric::ublas::matrix_expression<E> &e, const OP& op = OP() ) const {
|
||||
typedef typename boost::numeric::ublas::matrix_unary1_traits<E, OP>::expression_type expression_type;
|
||||
return expression_type (e ());
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
inline typename boost::numeric::ublas::matrix_unary1_traits<E, makeRealFunctor<typename E::value_type> >::result_type
|
||||
opsM(const boost::numeric::ublas::matrix_expression<E> &e) const {
|
||||
return matrixApplyToAll<makeRealFunctor<typename E::value_type> >(e);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
inline typename boost::numeric::ublas::matrix_unary1_traits<E, makeRealFunctor<typename E::value_type> >::result_type
|
||||
opbM(const boost::numeric::ublas::matrix_expression<E> &e) const {
|
||||
return matrixApplyToAll<makeRealFunctor<typename E::value_type> >(e);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
inline typename boost::numeric::ublas::vector_unary_traits<E, makeRealFunctor<typename E::value_type> >::result_type
|
||||
opsV(const boost::numeric::ublas::vector_expression<E> &e) const {
|
||||
return vectorApplyToAll<makeRealFunctor<typename E::value_type> >(e);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
inline typename boost::numeric::ublas::vector_unary_traits<E, makeRealFunctor<typename E::value_type> >::result_type
|
||||
opbV(const boost::numeric::ublas::vector_expression<E> &e) const {
|
||||
return vectorApplyToAll<makeRealFunctor<typename E::value_type> >(e);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes the real Schur decomposition of a matrix: A -> sv * A * trans(sv)
|
||||
* @param A Input/Output matrix to decompose
|
||||
* @param eig Output vector of eigenvalues
|
||||
* @param sv Output matrix of Schur vectors
|
||||
* @tparam TrealMatrix Type of input/output matrix
|
||||
* @tparam TcomplexVector Type of output eigenvalue vector
|
||||
*/
|
||||
template <typename TrealMatrix, typename TcomplexVector>
|
||||
static void realSchurDecomposition(TrealMatrix& A, TcomplexVector& eig, TrealMatrix& sv);
|
||||
|
||||
/**
|
||||
* Computes a 1x(dim-i) vector res such that:
|
||||
* res = M(i-1, i:(dim-i))
|
||||
* M must be square, dim is its dimension
|
||||
*/
|
||||
template <typename T>
|
||||
static void subvector(const typename Matrix<T>::Implementation& M,
|
||||
const std::size_t& index,
|
||||
typename Vector<T>::Implementation& res);
|
||||
|
||||
/**
|
||||
* Computes a 2x(dim-i) matrix res such that:
|
||||
* res(0) = a * M(i-2, i:(dim-i)) + b * M(i-1, i:(dim-i))
|
||||
* res(1) = c * M(i-2, i:(dim-i)) + d * M(i-1, i:(dim-i))
|
||||
* M must be square, dim is its dimension
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void submatrix(const typename Matrix<T1>::Implementation& M,
|
||||
const std::size_t& index,
|
||||
const T2& a,
|
||||
const T3& b,
|
||||
const T4& c,
|
||||
const T5& d,
|
||||
typename Matrix<T6>::Implementation& res);
|
||||
|
||||
/** computeO1a(a, M, tm, V, tv, res): res = a * tv(trans(V)) * tm(M)
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO1a(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
const typename Vector<T4>::Implementation& V, const T5& vTransformation,
|
||||
typename Vector<T6>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO1b(a, M, tm, V, tv, res): res = a * tv(V) * tm(M)
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO1b(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
const typename Matrix<T4>::Implementation& V, const T5& vTransformation,
|
||||
typename Matrix<T6>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/** computeO1c(a, M, tm, V, tv, res): res = a * tm(M) * tv(V) */
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO1c(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
const typename Vector<T4>::Implementation& V, const T5& vTransformation,
|
||||
typename Vector<T6>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO2pa(V, tv, res): res += tv(V)
|
||||
* Operates on the subvector of res at row i, starting from column i+1
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO2pa(const typename Vector<T1>::Implementation& V, const T2& vTransformation,
|
||||
typename HessenbergMatrix<T3>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO2ma(V, tv, res): res -= tv(V)
|
||||
* Operates on the subvector of res at row i, starting from column i+1
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO2ma(const typename Vector<T1>::Implementation& V, const T2& vTransformation,
|
||||
typename HessenbergMatrix<T3>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO2pb(M, tm, res): res += tm(M)
|
||||
* Operates on the submatrix of res at rows i and i+1, starting from column i+2
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO2pb(const typename Matrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
typename HessenbergMatrix<T3>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO2mb(M, tm, res): res -= tm(M)
|
||||
* Operates on the submatrix of res at rows i and i+1, starting from column i+2
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO2mb(const typename Matrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
typename HessenbergMatrix<T3>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/** computeO2pc(V, tv, res): res += tv(V) */
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO2pc(const typename Vector<T1>::Implementation& V, const T2& vTransformation,
|
||||
typename Vector<T3>::Implementation& res);
|
||||
|
||||
/** computeO2mc(V, tv, res): res += tv(V) */
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO2mc(const typename Vector<T1>::Implementation& V, const T2& vTransformation,
|
||||
typename Vector<T3>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO3a(a, M, tm, V, tv, res): res = a * ((tv(trans(V)) * tm(M)) - res)
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO3a(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
const typename Vector<T4>::Implementation& V, const T5& vTransformation,
|
||||
typename Vector<T6>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO3b(a, M, tm, V, tv, res): res = a * ((tv(V) * tm(M)) - res)
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO3b(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
const typename Matrix<T4>::Implementation& V, const T5& vTransformation,
|
||||
typename Matrix<T6>::Implementation& res,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO3c(a, M, tm, V, tv, res): res = a * ((tm(M) * tv(V)) - res)
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO3c(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
const typename Vector<T4>::Implementation& V, const T5& vTransformation,
|
||||
typename Vector<T6>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO4pa(M, tM, V, tV, res, mr): res += mr(tv(trans(V)) * tM(M))
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
* Operates on the subvector of res at row i-1, starting from column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO4pa(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Vector<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename HessenbergMatrix<T5>::Implementation& res, const T6& resTransformation,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO4ma(M, tM, V, tV, res, mr): res -= mr(tv(trans(V)) * tM(M))
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
* Operates on the subvector of res at row i-1, starting from column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO4ma(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Vector<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename HessenbergMatrix<T5>::Implementation& res, const T6& resTransformation,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO4pb(M, tM, V, tV, res, mr): res += mr(tv(V) * tM(M))
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
* Operates on the submatrix of res at rows i-2 and i-1, starting from column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO4pb(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Matrix<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename HessenbergMatrix<T5>::Implementation& res, const T6& resTransformation,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO4mb(M, tM, V, tV, res, mr): res -= mr(tv(V) * tM(M))
|
||||
* Operates on the square submatrix of M starting at row i and column i
|
||||
* Operates on the submatrix of res at rows i-2 and i-1, starting from column i
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO4mb(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Matrix<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename HessenbergMatrix<T5>::Implementation& res, const T6& resTransformation,
|
||||
const std::size_t& index);
|
||||
|
||||
/**
|
||||
* computeO4pc(M, tM, V, tV, res, mr): res += mr(tM(M) * tv(V))
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO4pc(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Vector<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename Vector<T5>::Implementation& res, const T6& resTransformation);
|
||||
|
||||
/**
|
||||
* computeO4mc(M, tM, V, tV, res, mr): res -= mr(tM(M) * tv(V))
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO4mc(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Vector<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename Vector<T5>::Implementation& res, const T6& resTransformation);
|
||||
|
||||
/**
|
||||
* computeO5a(a, M, tm, res): res = a * tm(M)
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
static void computeO5a(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M, const T3& mTransformation,
|
||||
typename HessenbergMatrix<T4>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO5b(a, M, tm, res): res = a * tv(V)
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
static void computeO5b(const T1& a,
|
||||
const typename Vector<T2>::Implementation& V, const T3& vTransformation,
|
||||
typename Vector<T4>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO6a(a, M1, tm1, M2, tm2, res): res = a * (tm1(M1) - tm2(M2))
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO6a(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M1, const T3& m1Transformation,
|
||||
const typename HessenbergMatrix<T4>::Implementation& M2, const T5& m2Transformation,
|
||||
typename HessenbergMatrix<T6>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO6b(a, V1, tv1, V2, tv2, res): res = a * (tv1(V1) - tv2(V2))
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
static void computeO6b(const T1& a,
|
||||
const typename Vector<T2>::Implementation& V1, const T3& v1Transformation,
|
||||
const typename Vector<T4>::Implementation& V2, const T5& v2Transformation,
|
||||
typename Vector<T6>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO7(M, tm, V, tv, res): res = tm(M) * tv(V)
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
static void computeO7(const typename HessenbergMatrix<T1>::Implementation& M, const T2& mTransformation,
|
||||
const typename Vector<T3>::Implementation& V, const T4& vTransformation,
|
||||
typename Vector<T5>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO8a(a, res): res *= a
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
static void computeO8a(const T1& a, typename HessenbergMatrix<T2>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO8b(a, res): res *= a
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
static void computeO8b(const T1& a, typename Vector<T2>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO9a(a, M, res): res = a * (res - M)
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO9a(const T1& a,
|
||||
const typename HessenbergMatrix<T2>::Implementation& M,
|
||||
typename HessenbergMatrix<T3>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO9b(a, M, res): res = a * (res - V)
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void computeO9b(const T1& a,
|
||||
const typename Vector<T2>::Implementation& V,
|
||||
typename Vector<T3>::Implementation& res);
|
||||
|
||||
/**
|
||||
* computeO10(V, M): V = trans(M) * V
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
static void computeO10(const typename Matrix<T1>::Implementation& M, typename Vector<T2>::Implementation& V);
|
||||
|
||||
/**
|
||||
* computeO11(V, M): V = M * V
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
static void computeO11(const typename Matrix<T1>::Implementation& M, typename Vector<T2>::Implementation& V);
|
||||
};
|
||||
} // namespace algebra
|
||||
} // namespace epoch
|
||||
|
||||
#include "details/UblasBackendImpl.hh"
|
||||
|
||||
#endif // UBLAS_BACKEND_HH
|
||||
3472
src/algebra/details/UblasBackendImpl.hh
Normal file
3472
src/algebra/details/UblasBackendImpl.hh
Normal file
File diff suppressed because it is too large
Load Diff
254
src/commons/Exception.cc
Normal file
254
src/commons/Exception.cc
Normal file
@@ -0,0 +1,254 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// Copyright Florent Teichteil-Koenigsbuch (2008)
|
||||
|
||||
#include "Exception.hh"
|
||||
|
||||
using namespace epoch;
|
||||
|
||||
// Class Exception
|
||||
|
||||
Exception::Exception(std::string const & error_message, std::string const & throwing_function)
|
||||
: error_message_(error_message)
|
||||
{
|
||||
if (!throwing_function.empty())
|
||||
function_backtrace_ = std::string(" from '") + throwing_function + "':\n";
|
||||
}
|
||||
|
||||
|
||||
Exception::~Exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char * Exception::what() const throw()
|
||||
{
|
||||
what_message_ = std::string("HMDP exception:\n") + function_backtrace_ + " " + error_message_;
|
||||
return what_message_.c_str();
|
||||
}
|
||||
|
||||
|
||||
void Exception::push_function_backtrace(std::string const & throwing_function)
|
||||
{
|
||||
function_backtrace_.insert(0, std::string(" from '") + throwing_function + "':\n");
|
||||
}
|
||||
|
||||
|
||||
void Exception::clear_function_backtrace()
|
||||
{
|
||||
function_backtrace_.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class ParserException
|
||||
|
||||
ParserException::ParserException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP parser exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
ParserException::~ParserException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class RequirementException
|
||||
|
||||
RequirementException::RequirementException(std::string const & error_message, std::string const & throwing_function)
|
||||
: ParserException("HMDP requirement exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
RequirementException::~RequirementException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class OverflowException
|
||||
|
||||
OverflowException::OverflowException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP overflow exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
OverflowException::~OverflowException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class NumericException
|
||||
|
||||
NumericException::NumericException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP numeric exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
NumericException::~NumericException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class RedundancyException
|
||||
|
||||
RedundancyException::RedundancyException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP redundancy exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
RedundancyException::~RedundancyException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class CloneException
|
||||
|
||||
CloneException::CloneException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP clone exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
CloneException::~CloneException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class LearnerException
|
||||
|
||||
LearnerException::LearnerException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP learner exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
LearnerException::~LearnerException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class UndecidableException
|
||||
|
||||
UndecidableException::UndecidableException(std::string const & error_message, std::string const & throwing_function)
|
||||
: LearnerException("HMDP learner exception (undecidable inference): ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
UndecidableException::~UndecidableException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class PlannerException
|
||||
|
||||
PlannerException::PlannerException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP planner exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
PlannerException::~PlannerException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Class TimeOutException
|
||||
|
||||
TimeOutException::TimeOutException(std::string const & error_message, std::string const & throwing_function)
|
||||
: PlannerException("HMDP timeout exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
TimeOutException::~TimeOutException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Class IncompatibilityException
|
||||
|
||||
IncompatibilityException::IncompatibilityException(std::string const & error_message, std::string const & throwing_function)
|
||||
: Exception("HMDP incompatibility exception: ", throwing_function)
|
||||
{
|
||||
error_message_ += error_message;
|
||||
}
|
||||
|
||||
|
||||
IncompatibilityException::~IncompatibilityException() throw()
|
||||
{
|
||||
}
|
||||
155
src/commons/Exception.hh
Normal file
155
src/commons/Exception.hh
Normal file
@@ -0,0 +1,155 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// Copyright Florent Teichteil-Koenigsbuch (2008)
|
||||
|
||||
#ifndef EXCEPTION_H_
|
||||
#define EXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
|
||||
class Exception : public std::exception
|
||||
{
|
||||
protected :
|
||||
std::string error_message_;
|
||||
std::string function_backtrace_;
|
||||
mutable std::string what_message_;
|
||||
|
||||
public :
|
||||
Exception(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~Exception() throw();
|
||||
|
||||
virtual const char * what() const throw();
|
||||
virtual void push_function_backtrace(std::string const & throwing_function);
|
||||
virtual void clear_function_backtrace();
|
||||
};
|
||||
|
||||
|
||||
class ParserException : public Exception
|
||||
{
|
||||
public :
|
||||
ParserException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~ParserException() throw();
|
||||
};
|
||||
|
||||
|
||||
class RequirementException : public ParserException
|
||||
{
|
||||
public :
|
||||
RequirementException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~RequirementException() throw();
|
||||
};
|
||||
|
||||
|
||||
class OverflowException : public Exception
|
||||
{
|
||||
public :
|
||||
OverflowException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~OverflowException() throw();
|
||||
};
|
||||
|
||||
|
||||
class NumericException : public Exception
|
||||
{
|
||||
public :
|
||||
NumericException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~NumericException() throw();
|
||||
};
|
||||
|
||||
|
||||
class RedundancyException : public Exception
|
||||
{
|
||||
public :
|
||||
RedundancyException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~RedundancyException() throw();
|
||||
};
|
||||
|
||||
|
||||
class CloneException : public Exception
|
||||
{
|
||||
public :
|
||||
CloneException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~CloneException() throw();
|
||||
};
|
||||
|
||||
class LearnerException : public Exception
|
||||
{
|
||||
public :
|
||||
LearnerException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~LearnerException() throw();
|
||||
};
|
||||
|
||||
|
||||
class UndecidableException : public LearnerException
|
||||
{
|
||||
public :
|
||||
UndecidableException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~UndecidableException() throw();
|
||||
};
|
||||
|
||||
|
||||
class PlannerException : public Exception
|
||||
{
|
||||
public :
|
||||
PlannerException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~PlannerException() throw();
|
||||
};
|
||||
|
||||
|
||||
class TimeOutException : public PlannerException
|
||||
{
|
||||
public :
|
||||
TimeOutException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~TimeOutException() throw();
|
||||
};
|
||||
|
||||
|
||||
class IncompatibilityException : public Exception
|
||||
{
|
||||
public :
|
||||
IncompatibilityException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~IncompatibilityException() throw();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /*EXCEPTION_H_*/
|
||||
70
src/console/CMakeLists.txt
Normal file
70
src/console/CMakeLists.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
# This file is part of EPOCH.
|
||||
# File: CMakeLists.txt
|
||||
# Author: Florent Teichteil-Königsbuch
|
||||
# Contact: florent.teichteil@onera.fr
|
||||
#
|
||||
# EPOCH is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# EPOCH is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
FIND_PACKAGE(LibXML++ REQUIRED)
|
||||
set(LIBS ${LIBS} ${LibXML++_LIBRARIES})
|
||||
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LibXML++_INCLUDE_DIRS} ${UMFPACK_INCLUDES})
|
||||
|
||||
SET (EPOCH_CONSOLE_LIBRARIES)
|
||||
LIST (APPEND EPOCH_CONSOLE_LIBRARIES
|
||||
epoch-altarica
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||
${Boost_FILESYSTEM_LIBRARY}
|
||||
${Boost_DATE_TIME_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
${LAPACK_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
SET (IAEPOCH_LIBRARIES)
|
||||
LIST (APPEND IAEPOCH_LIBRARIES
|
||||
epoch-altarica
|
||||
# epoch-solvers
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||
${UMFPACK_LIBRARIES})
|
||||
|
||||
ADD_EXECUTABLE (epochnogui
|
||||
epochmain.cc
|
||||
ParsingDriverConsoleReporter.cc
|
||||
epochconsolealtarica.cc
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (epochnogui ${EPOCH_CONSOLE_LIBRARIES})
|
||||
|
||||
ADD_EXECUTABLE (iaepoch
|
||||
iaepochmain.cc
|
||||
ParsingDriverConsoleReporter.cc)
|
||||
TARGET_LINK_LIBRARIES (iaepoch ${IAEPOCH_LIBRARIES} # epoch-prism
|
||||
${Boost_TIMER_LIBRARY}
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
${Boost_FILESYSTEM_LIBRARY})
|
||||
|
||||
ExternalProject_Get_Property(buddy-2.4 install_dir)
|
||||
INCLUDE_DIRECTORIES(${install_dir}/include)
|
||||
|
||||
#SET (SYMEPOCH_LIBRARIES)
|
||||
#LIST (APPEND SYMEPOCH_LIBRARIES
|
||||
# epoch-altarica
|
||||
# epoch-symbolic
|
||||
# ${Boost_SYSTEM_LIBRARY}
|
||||
# ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
|
||||
#ADD_EXECUTABLE (symepoch
|
||||
# symepochmain.cc
|
||||
# ParsingDriverConsoleReporter.cc)
|
||||
#TARGET_LINK_LIBRARIES (symepoch ${SYMEPOCH_LIBRARIES})
|
||||
42
src/console/ParsingDriverConsoleReporter.cc
Normal file
42
src/console/ParsingDriverConsoleReporter.cc
Normal file
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "console/ParsingDriverConsoleReporter.hh"
|
||||
#include <iostream>
|
||||
|
||||
namespace epoch {
|
||||
namespace console {
|
||||
|
||||
ParsingDriverConsoleReporter::ParsingDriverConsoleReporter() {
|
||||
}
|
||||
|
||||
void ParsingDriverConsoleReporter::Append(const std::string& msg) {
|
||||
std::cerr << msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
42
src/console/ParsingDriverConsoleReporter.hh
Normal file
42
src/console/ParsingDriverConsoleReporter.hh
Normal file
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef PARSING_DRIVER_CONSOLE_REPORTER_HH
|
||||
#define PARSING_DRIVER_CONSOLE_REPORTER_HH
|
||||
|
||||
#include "grammars/parsingdriverbase.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace console {
|
||||
|
||||
class ParsingDriverConsoleReporter : public epoch::ParsingDriverReporter {
|
||||
public :
|
||||
ParsingDriverConsoleReporter();
|
||||
virtual void Append(const std::string& msg);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
200
src/console/bddepochmain.cc
Normal file
200
src/console/bddepochmain.cc
Normal file
@@ -0,0 +1,200 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Xavier Pucel (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/exception/diagnostic_information.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "epochconsolealtarica.hh"
|
||||
|
||||
#include "grammars/altarica/AltaricaGenerator.hh"
|
||||
#include "grammars/altarica/Assignment.hh"
|
||||
#include "grammars/altarica/Event.hh"
|
||||
#include "grammars/altarica/MemberAccess.hh"
|
||||
#include "grammars/altarica/Synchronisation.hh"
|
||||
#include "grammars/altarica/Transition.hh"
|
||||
#include "grammars/altarica/Variable.hh"
|
||||
|
||||
//using namespace epoch;
|
||||
|
||||
int main(int ac, char* av[]) {
|
||||
unsigned int verbosity; // verbosity level
|
||||
std::string modelFile;
|
||||
std::string initFile;
|
||||
bool ds;
|
||||
bool printFlow;
|
||||
bool printNULL;
|
||||
bool printDomain;
|
||||
|
||||
try {
|
||||
boost::program_options::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help", "produce help message")
|
||||
("ds",
|
||||
boost::program_options::value<bool>(&ds)->default_value(false),
|
||||
"print semantic debug messages for discrete models")
|
||||
("file",
|
||||
boost::program_options::value<std::string>(&modelFile)->default_value(""),
|
||||
"model file (either .alt (altartica) or [.prism|.nm|.pm|.sm] (prism)")
|
||||
("init",
|
||||
boost::program_options::value<std::string>(&initFile)->default_value(""),
|
||||
"init file")
|
||||
("pf",
|
||||
boost::program_options::value<bool>(&printFlow)->default_value(false),
|
||||
"print flow vars")
|
||||
("pn",
|
||||
boost::program_options::value<bool>(&printNULL)->default_value(false),
|
||||
"print null values")
|
||||
("pd",
|
||||
boost::program_options::value<bool>(&printDomain)->default_value(false),
|
||||
"print var domains")
|
||||
;
|
||||
|
||||
boost::program_options::positional_options_description p;
|
||||
p.add("file", 1);
|
||||
|
||||
|
||||
namespace options_style_ns = boost::program_options::command_line_style;
|
||||
int options_style = options_style_ns::allow_short
|
||||
| options_style_ns::short_allow_adjacent
|
||||
| options_style_ns::short_allow_next
|
||||
| options_style_ns::allow_long
|
||||
| options_style_ns::long_allow_adjacent
|
||||
| options_style_ns::long_allow_next
|
||||
| options_style_ns::allow_sticky
|
||||
| options_style_ns::allow_dash_for_short;
|
||||
boost::program_options::variables_map vm;
|
||||
// boost::program_options::store(
|
||||
// boost::program_options::parse_command_line(ac, av, desc, options_style),
|
||||
// vm);
|
||||
boost::program_options::store
|
||||
(boost::program_options::command_line_parser(ac,av).options(desc).
|
||||
positional(p).style(options_style).run(),
|
||||
vm);
|
||||
boost::program_options::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
epoch::console::ParsingDriverConsoleReporter pdr;
|
||||
epoch::altarica::AltaricaGenerator gen(modelFile, pdr);
|
||||
gen.amodel_->setDebugSemantics(ds);
|
||||
|
||||
// if (initFile.compare("") != 0)
|
||||
// gen.amodel_->setInitInfo(initFile);
|
||||
|
||||
if (ds)
|
||||
{
|
||||
std::cout << std::endl << "MODEL STATS:" << std::endl;
|
||||
|
||||
std::cout << "number of state vars: "
|
||||
<< gen.amodel_->getNStateVars()
|
||||
<< std::endl;
|
||||
|
||||
std::cout << "number of _different_ flow vars: "
|
||||
<< gen.amodel_->getNFlowVars()
|
||||
<< std::endl;
|
||||
|
||||
std::cout << "number of atomic events: "
|
||||
<< gen.amodel_->getNEvents()
|
||||
<< std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << std::endl << "FLOW VARS" << std::endl;
|
||||
for(auto &v : gen.amodel_->getFlowVars()) {
|
||||
std::cout << v->getMA()->toString()
|
||||
<< " : "
|
||||
<< v->getDomain()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl << "STATE VARS" << std::endl;
|
||||
for(auto &v : gen.amodel_->getFlowVars()) {
|
||||
std::cout << v->getMA()->toString()
|
||||
<< " : "
|
||||
<< v->getDomain()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl << "ATOMIC EVTS" << std::endl;
|
||||
for(auto &e : gen.amodel_->getAtomicEvents()) {
|
||||
std::cout << e->getMA()->toString()
|
||||
<< " : "
|
||||
<< std::endl;
|
||||
if(e->getTrans()->size() > 0)
|
||||
for(auto &t : *e->getTrans()) {
|
||||
std::cout << " pre : "
|
||||
<< t->getPrecond()->toString()
|
||||
<< std::endl;
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
std::cout << " post: ";
|
||||
for(auto &a : *t->getAssigns()) {
|
||||
std::cout << " "
|
||||
<< a->getVar()->getMA()->toString()
|
||||
<< a->getMA()->toString()
|
||||
<< " := "
|
||||
<< a->getExpr()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl << "SYNCS" << std::endl;
|
||||
for(auto &s: gen.amodel_->getSyncs()) {
|
||||
std::cout << s->toString();
|
||||
if(s->getMA() != NULL)
|
||||
std::cout << s->getMA()->toString() << std::endl;
|
||||
if(s->getMandatoryEvents()->size() > 0) {
|
||||
std::cout << " Mandatory events:" << std::endl;
|
||||
for(auto &e : *s->getMandatoryEvents())
|
||||
std::cout << " " << e->getMA()->toString() << std::endl;
|
||||
}
|
||||
if(s->getOptionalEvents()->size() > 0) {
|
||||
std::cout << " Optional events:" << std::endl;
|
||||
for(auto &e : *s->getOptionalEvents())
|
||||
std::cout << " " << e->getMA()->toString() << std::endl;
|
||||
}
|
||||
std::cout << " Constraint type: " << s->getConstraintType() << std::endl;
|
||||
std::cout << " Numerical constant: "
|
||||
<< s->getNumericalConstant()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const boost::program_options::error& error) {
|
||||
std::cerr << error.what() << std::endl;
|
||||
return -1;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << boost::diagnostic_information(error) << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
316
src/console/epochconsolealtarica.cc
Normal file
316
src/console/epochconsolealtarica.cc
Normal file
@@ -0,0 +1,316 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
//#include "algorithms/EmptyStateVisitor.hh"
|
||||
//#include "algorithms/DotStateVisitor.hh"
|
||||
#include "grammars/altarica/FiacreTranslator.hh"
|
||||
//#include "solvers/epochsolver.hh"
|
||||
//#include "solvers/altaricaLogic.hh"
|
||||
#include "console/ParsingDriverConsoleReporter.hh"
|
||||
|
||||
#include "grammars/altarica/Assignment.hh"
|
||||
#include "grammars/altarica/AltaricaGenerator.hh"
|
||||
#include "grammars/altarica/Event.hh"
|
||||
#include "grammars/altarica/MemberAccess.hh"
|
||||
#include "grammars/altarica/Synchronisation.hh"
|
||||
#include "grammars/altarica/Transition.hh"
|
||||
#include "grammars/altarica/Variable.hh"
|
||||
|
||||
#include "grammars/altarica/Event.hh"
|
||||
#include "grammars/altarica/Assertion.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace console {
|
||||
void printStates(int ps, int maxDepth, epoch::altarica::AltaricaState* s, epoch::altarica::AltaricaModel* m) {
|
||||
|
||||
std::cerr << "\ndepth = "<< maxDepth-ps << std::endl;
|
||||
std::cerr << s->toString(true, true, true, true);
|
||||
if (ps == 0) {
|
||||
delete s;
|
||||
std::cerr << "\n!!!!!!!!!!!! GOING UP the tree\n"<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<epoch::altarica::MetaEvent*> * mev = m->getEnabledMetaEventsAll(s);
|
||||
std::cerr<<"\n # metaEvents: "<< mev->size() << std::endl;
|
||||
for (int i=0; i<mev->size(); ++i) {
|
||||
std::cerr << " MEV " << i << ": " << (*mev)[i]->toString() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<mev->size(); ++i) {
|
||||
std::cerr << "\ndoing MEV " << i << ": " << (*mev)[i]->toString() << std::endl;
|
||||
epoch::altarica::AltaricaState *s2 = m->getNextState(s,(*mev)[i]);
|
||||
m->evaluateFlowVars(s2);
|
||||
printStates(ps-1, maxDepth, s2, m);
|
||||
}
|
||||
|
||||
// std::vector<epoch::altarica::Event*> ev = m->getAtomicEvents();
|
||||
// std::cerr<<"\n # Events: "<< ev.size() << std::endl;
|
||||
// for (int i=0; i<ev.size(); ++i) {
|
||||
// std::cerr << " EV " << i << ": " << ev[i]->toString() << std::endl;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string print_pre (const epoch::altarica::AltaricaModel *amodel_, const std::vector<epoch::altarica::Event*> *ev, int n, std::ostringstream * sout) {
|
||||
|
||||
std::ostringstream sret;
|
||||
std::string s ;
|
||||
if (n < 0)
|
||||
return sout->str() + "\n";
|
||||
|
||||
// for (int i = ev->size(); i > 0; --i) {
|
||||
|
||||
// ss << "\tEvent" << i-1;
|
||||
unsigned j = 0;
|
||||
for (auto &ti : *(ev->at(n)->getTrans()) ) {
|
||||
std::ostringstream ss;
|
||||
ss << sout->str() << ti->getPrecond()->toString( ti->getNode(), amodel_);
|
||||
if ( n != 0 )
|
||||
ss << " and ";
|
||||
//ss << sout->str() << "\tE" << n << "T" << j++;
|
||||
sret << print_pre(amodel_, ev, n-1, &ss);
|
||||
|
||||
|
||||
// const std::vector<epoch::altarica::Assignment*>* effects = ti->getAssigns();
|
||||
// if(effects->size() > 0) {
|
||||
// for(auto &a : *effects) {
|
||||
// std::cout << "\tpost : "
|
||||
// << a->getVar()->toFiacre()
|
||||
// //<< a->getMA()->toString()
|
||||
// << " := "
|
||||
// << a->getExpr()->toString( a->getNode() )
|
||||
// << ";" << std::endl;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
|
||||
bool DoAltarica(const std::string& modelFile, const std::string& initFile, const std::string& var1, const std::string& value1, const std::string& var2, const std::string& value2,bool ds, int ps, bool invert_comp1, bool invert_comp2,
|
||||
int ac, char* av[], int algo, int hess, int blas, double threshold, unsigned int dtimebound, double ctimebound, bool printfunction, const std::string& printGraph) {
|
||||
epoch::console::ParsingDriverConsoleReporter pdr;
|
||||
epoch::altarica::AltaricaGenerator gen(modelFile, pdr);
|
||||
gen.amodel_->setDebugSemantics(ds);
|
||||
|
||||
// if (initFile.compare("") != 0)
|
||||
if (initFile.length() >= 4 &&
|
||||
0 == initFile.compare(initFile.length() - 4, 4, ".xml"))
|
||||
gen.amodel_->setInitInfoXML(initFile);
|
||||
else if (initFile.length() >= 5 &&
|
||||
0 == initFile.compare(initFile.length() - 4, 4, ".json"))
|
||||
gen.amodel_->setInitInfoJSON(initFile);
|
||||
|
||||
epoch::altarica::AltaricaState * i = gen.amodel_->initialState();
|
||||
gen.amodel_->evaluateFlowVars(i);
|
||||
// std::cerr << i->toString(true,true,true,true);
|
||||
std::cerr << std::endl << "MODEL STATS:" << std::endl;
|
||||
std::cerr << "number of state vars: " << gen.amodel_->getNStateVars() << std::endl;
|
||||
std::cerr << "number of _different_ flow vars: " << gen.amodel_->getNFlowVars() << std::endl;
|
||||
std::cerr << "number of atomic events: " << gen.amodel_->getNEvents() << std::endl;
|
||||
|
||||
|
||||
//// Debug printing start ////
|
||||
|
||||
if (gen.amodel_->getDebugSemantics())
|
||||
{
|
||||
std::cout << std::endl << "FLOW VARS" << std::endl;
|
||||
|
||||
for(auto &v : gen.amodel_->getFlowVars()) {
|
||||
|
||||
std::cout << v->getFullName() <<
|
||||
" : " <<
|
||||
v->getDomain()->toString() <<
|
||||
std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl << "STATE VARS" << std::endl;
|
||||
for(auto &v : gen.amodel_->getStateVars()) {
|
||||
std::cout << v->getFullName()
|
||||
<< " : "
|
||||
<< v->getDomain()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl << "ATOMIC EVTS" << std::endl;
|
||||
for(auto &e : gen.amodel_->getAtomicEvents()) {
|
||||
std::cout << e->getMA()->toString()
|
||||
<< " : "
|
||||
<< std::endl;
|
||||
if(e->getTrans()->size() > 0)
|
||||
for(auto &t : *e->getTrans()) {
|
||||
std::cout << " pre : "
|
||||
<< t->getPrecond()->toString()
|
||||
<< std::endl;
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
std::cout << " post : ";
|
||||
for(auto &a : *t->getAssigns()) {
|
||||
std::cout << " "
|
||||
// << a->getVar()->toFiacre() //getVar()->getMA()->toString()
|
||||
<< a->getMA()->toString()
|
||||
<< " := "
|
||||
<< a->getExpr()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get Syncs //
|
||||
unsigned nev=0, ne = 0;
|
||||
for(auto &sy :gen.amodel_->getSyncs())
|
||||
std::cout << sy->toString()<< std::endl;
|
||||
|
||||
std::cout << std::endl << "SYNCS" << std::endl;
|
||||
// for(auto &sy :gen.amodel_->getSyncs())
|
||||
// std::cout << sy->toString()<< std::endl;
|
||||
unsigned n=0;
|
||||
for(auto &sy :gen.amodel_->getMetaEvents()) {
|
||||
std::cout << "Meta event" << n++ << std::endl;
|
||||
if (sy->getEvents()->size() != 0) {
|
||||
for (std::vector<epoch::altarica::Event*>::iterator i = sy->getEvents()->begin();
|
||||
i!=sy->getEvents()->end(); ++i) {
|
||||
ne = 0;
|
||||
for (auto &t : *(*i)->getTrans()) {
|
||||
std::cout << nev << "." << ne++ << ". pre : " << t->getPrecond()->toString( t->getNode(), gen.amodel_) << std::endl;
|
||||
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
for(auto &a : *(t->getAssigns())) {
|
||||
std::cout << "\tpost : "
|
||||
<< a->getVar()->toFiacre()
|
||||
//<< a->getMA()->toString()
|
||||
<< " := "
|
||||
<< a->getExpr()->toString( a->getNode(), gen.amodel_ )
|
||||
<< ";" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
++nev;
|
||||
}
|
||||
}
|
||||
else
|
||||
std::cout << " NO EVENT";
|
||||
}
|
||||
|
||||
////////
|
||||
std::cout << std::endl << "SYNCS" << std::endl;
|
||||
|
||||
nev=0; ne = 0;
|
||||
for(auto &sy :gen.amodel_->getMetaEvents()) {
|
||||
std::cout << std::endl << "Meta event" << nev++ << std::endl;
|
||||
if (sy->getEvents()->size() != 0) {
|
||||
|
||||
std::ostringstream ss("init ");
|
||||
|
||||
int num = sy->getEvents()->size()-1;
|
||||
|
||||
std::cout << print_pre(gen.amodel_, sy->getEvents() , num, &ss );
|
||||
|
||||
}
|
||||
else
|
||||
std::cout << " NO EVENT";
|
||||
}
|
||||
std::cout << std::endl << "ATOMIC DIRAC EVTS" << std::endl;
|
||||
for(auto &e : gen.amodel_->getAtomicDiracEvents()) {
|
||||
std::cout << e->getMA()->toString()
|
||||
<< " : "
|
||||
<< std::endl;
|
||||
if(e->getTrans()->size() > 0)
|
||||
for(auto &t : *e->getTrans()) {
|
||||
std::cout << " pre : "
|
||||
<< t->getPrecond()->toString()
|
||||
<< std::endl;
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
std::cout << " post: ";
|
||||
for(auto &a : *t->getAssigns()) {
|
||||
std::cout << " "
|
||||
// << a->getVar()->toFiacre() //getVar()->getMA()->toString()
|
||||
<< a->getMA()->toString()
|
||||
<< " := "
|
||||
<< a->getExpr()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl << "ASSERTIONS" << std::endl;
|
||||
|
||||
for(auto &e : gen.amodel_->getAsserts()) {
|
||||
size_t et = (size_t)(e);
|
||||
std::cout << et << " "<< e->getExpr()->toString()<< std::endl;
|
||||
}
|
||||
}
|
||||
//////// Debug printing end ///////
|
||||
|
||||
|
||||
if (ps >= 0) {
|
||||
// Makes a FIACRE model
|
||||
std::cerr << "\n!!!!!!!!!!!! Printing FIACRE model\n\n"<< std::endl;
|
||||
|
||||
epoch::altarica::FiacreTranslator f(gen.amodel_);
|
||||
f.printFiacre();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
// A partir d'ici : algorithme
|
||||
//const epoch::altarica::Node& mainNode = *(gen.amodel_->findNodeByName("main"));
|
||||
|
||||
|
||||
|
||||
// Formule f1 : tout est ok
|
||||
/* epoch::solvers::AltaricaLogic* f1;
|
||||
|
||||
|
||||
if (strcmp(var1.c_str(), "") != 0)
|
||||
f1 = new epoch::solvers::AltaricaLogicF2(gen.amodel_,var1,value1, invert_comp1);
|
||||
else
|
||||
f1 = new epoch::solvers::AltaricaLogicF1();
|
||||
|
||||
epoch::solvers::AltaricaLogicF2 f2(gen.amodel_,var1,value1, invert_comp1);
|
||||
epoch::altarica::AltaricaGenerator::State is(i);
|
||||
|
||||
if (printGraph.empty()) {
|
||||
return epoch::solvers::MySolver<epoch::solvers::AltaricaLogic, epoch::altarica::AltaricaGenerator, epoch::algorithm::EmptyStateVisitor>::solve(ac, av,
|
||||
algo, hess, blas, threshold, dtimebound, ctimebound,
|
||||
printfunction, epoch::algorithm::EmptyStateVisitor(),
|
||||
gen, is, *f1, f2);
|
||||
} else {
|
||||
return epoch::solvers::MySolver<epoch::solvers::AltaricaLogic, epoch::altarica::AltaricaGenerator, epoch::algorithm::DotStateVisitor>::solve(ac, av,
|
||||
algo, hess, blas, threshold, dtimebound, ctimebound,
|
||||
printfunction, epoch::algorithm::DotStateVisitor(printGraph),
|
||||
gen, is, *f1, f2);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
106
src/console/epochconsolealtarica.hh
Normal file
106
src/console/epochconsolealtarica.hh
Normal file
@@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef EPOCH_CONSOLE_ALTARICA_HH
|
||||
#define EPOCH_CONSOLE_ALTARICA_HH
|
||||
|
||||
//#include "grammars/altarica/altarica_driver.hh"
|
||||
//#include "grammars/altarica/AltaricaState.hh"
|
||||
#include "grammars/altarica/AltaricaGenerator.hh"
|
||||
#include "grammars/altarica/expressions/Expressions.hh"
|
||||
|
||||
|
||||
#include "console/ParsingDriverConsoleReporter.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace console {
|
||||
typedef std::auto_ptr<epoch::altarica::Expression> MyExpressionPtr;
|
||||
|
||||
/*struct AltaricaLogic {
|
||||
const epoch::altarica::Node& m_rMainNode;
|
||||
MyExpressionPtr m_pExpression;
|
||||
std::auto_ptr<epoch::altarica::OpenValue> m_pConstantTrue;
|
||||
|
||||
AltaricaLogic(const epoch::altarica::Node& n, MyExpressionPtr e);
|
||||
|
||||
bool holds(const epoch::altarica::AltaricaGenerator::State& s) const;
|
||||
};
|
||||
|
||||
AltaricaLogic::AltaricaLogic(const epoch::altarica::Node& n, MyExpressionPtr e)
|
||||
: m_rMainNode(n), m_pExpression(e) {
|
||||
m_pConstantTrue = std::auto_ptr<epoch::altarica::OpenValue>(new epoch::altarica::OpenBool(true, false));
|
||||
}
|
||||
|
||||
bool AltaricaLogic::holds(const epoch::altarica::AltaricaGenerator::State& s) const {
|
||||
epoch::altarica::OpenValue* v = m_pExpression->evaluate(s.as_, &m_rMainNode);
|
||||
bool r = v->equals(m_pConstantTrue.get());
|
||||
delete v;
|
||||
return r;
|
||||
}*/
|
||||
|
||||
// template <class T>
|
||||
// bool from_string(T& t,
|
||||
// const std::string& s,
|
||||
// std::ios_base& (*f)(std::ios_base&))
|
||||
// {
|
||||
// std::istringstream iss(s);
|
||||
// return !(iss >> f >> t).fail();
|
||||
// }
|
||||
|
||||
void printStates(int ps, int maxDepth, epoch::altarica::AltaricaState* s, epoch::altarica::AltaricaModel* m);
|
||||
|
||||
// struct AltaricaLogic {
|
||||
// virtual ~AltaricaLogic() {}
|
||||
// virtual bool holds(const epoch::altarica::AltaricaGenerator::State& s) const =0;
|
||||
// };
|
||||
|
||||
// struct AltaricaLogicF1 : public AltaricaLogic {
|
||||
// virtual ~AltaricaLogicF1() {}
|
||||
// inline virtual bool holds(const epoch::altarica::AltaricaGenerator::State& s) const {return true;}
|
||||
// };
|
||||
|
||||
// struct AltaricaLogicF2 : public AltaricaLogic {
|
||||
// epoch::altarica::AltaricaModel* m_pModel;
|
||||
// std::auto_ptr<epoch::altarica::Value> m_pConstant;
|
||||
// std::string varName;
|
||||
// bool invert;
|
||||
|
||||
// virtual ~AltaricaLogicF2() {}
|
||||
|
||||
// AltaricaLogicF2(epoch::altarica::AltaricaModel* model, std::string vn, std::string value, bool invert_comp);
|
||||
|
||||
// virtual bool holds(const epoch::altarica::AltaricaGenerator::State& s) const;
|
||||
// };
|
||||
|
||||
bool DoAltarica(const std::string& modelFile, const std::string& initFile, const std::string& var1, const std::string& value1, const std::string& var2, const std::string& value2, bool ds, int ps, bool invert_comp1, bool invert_comp2,
|
||||
int ac, char* av[], int algo, int hess, int blas, double threshold, unsigned int dtimebound, double ctimebound, bool printfunction, const std::string& printGraph);
|
||||
} // namespace console
|
||||
} // namespace epoch
|
||||
|
||||
#endif // EPOCH_CONSOLE_ALTARICA_HH
|
||||
146
src/console/epochmain.cc
Normal file
146
src/console/epochmain.cc
Normal file
@@ -0,0 +1,146 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/exception/diagnostic_information.hpp>
|
||||
|
||||
#include "epochconsolealtarica.hh"
|
||||
|
||||
//using namespace epoch;
|
||||
|
||||
int main (int ac, char* av[])
|
||||
{
|
||||
unsigned int verbosity; // verbosity level
|
||||
std::string modelFile;
|
||||
std::string initFile;
|
||||
double threshold;
|
||||
unsigned int dtimebound;
|
||||
double ctimebound;
|
||||
std::string var1, var2 ;
|
||||
std::string value1, value2;
|
||||
std::string f1;
|
||||
std::string f2;
|
||||
bool invert_comp1 = false;
|
||||
bool invert_comp2 = false;
|
||||
int algo, hess, blas;
|
||||
bool ds;
|
||||
int ps;
|
||||
bool printfunction = false;
|
||||
std::string printGraph;
|
||||
try {
|
||||
boost::program_options::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help", "produce help message")
|
||||
("ds", boost::program_options::value<bool>(&ds)->default_value(false), "print semantic debug messages for discrete models")
|
||||
("ps", boost::program_options::value<int>(&ps)->default_value(-1), "print states up to specified depth (0 for initial state only )")
|
||||
|
||||
("file", boost::program_options::value<std::string>(&modelFile)->default_value(""), "model file (either .alt (altartica) or [.prism|.nm|.pm|.sm] (prism)")
|
||||
("init", boost::program_options::value<std::string>(&initFile)->default_value(""), "init file")
|
||||
("algo", boost::program_options::value<int>(&algo)->default_value(5), "algo:\n -1 => all\n 0 => exact infinite\n 1 => iterative infinite\n 2 => bounded exact infinite\n 3 => bounded iterative infinite\n 4 => finite\n 5 => bounded finite\n 6 => coutinuous exact\n 7 => continuous bounded\nINFINITE HORIZON + EXACT COMPUTATION + MARKOV CHAIN WITH INFINITE NUMBER OF STATES => STACK OVERFLOW")
|
||||
("hess", boost::program_options::value<int>(&hess)->default_value(0), "hess:\n 0 => triangular Hessenberg matrices\n 1 => banded Hessenberg matrices\n 2 => dense Hessenberg matrices")
|
||||
("blas", boost::program_options::value<int>(&blas)->default_value(0), "blas:\n 0 => Ublas Standard\n 1 => Ublas BLAS bindings (use system's BLAS implementation)")
|
||||
("verbosity", boost::program_options::value<unsigned int>(&verbosity)->default_value(0), "verbosity level")
|
||||
("thres", boost::program_options::value<double>(&threshold)->default_value(0.001), "threshold for P(f1 U f2) >= t")
|
||||
("dhor", boost::program_options::value<unsigned int>(&dtimebound)->default_value(10), "discrete horizon time")
|
||||
("chor", boost::program_options::value<double>(&ctimebound)->default_value(100.0), "continuous horizon time")
|
||||
("var1", boost::program_options::value<std::string>(&var1)->default_value(""), "var1 to check (left side of until)")
|
||||
("value1", boost::program_options::value<std::string>(&value1)->default_value("false"),"value for variable1 (false -> var1 = false)")
|
||||
("var2", boost::program_options::value<std::string>(&var1)->default_value(""), "var2 to check ( right side of until)")
|
||||
("value2", boost::program_options::value<std::string>(&value1)->default_value("false"),"value for variable2 (false -> var2 = false)")
|
||||
("f1", boost::program_options::value<std::string>(&f1)->default_value("true"), "left-hand side formula of strong until operator")
|
||||
("f2", boost::program_options::value<std::string>(&f2)->default_value("true"), "right-hand side formula of strong until operator")
|
||||
("neg1", " replaces = with != for left side of until")
|
||||
("neg2", "replaces = with != for right side of until")
|
||||
("pfunc", "print continuous probability function")
|
||||
("pg", "print the search graph in a dot file")
|
||||
;
|
||||
|
||||
namespace options_style_ns = boost::program_options::command_line_style;
|
||||
int options_style = options_style_ns::allow_short | options_style_ns::short_allow_adjacent | options_style_ns::short_allow_next
|
||||
| options_style_ns::allow_long | options_style_ns::long_allow_adjacent | options_style_ns::long_allow_next
|
||||
| options_style_ns::allow_sticky | options_style_ns::allow_dash_for_short;
|
||||
boost::program_options::variables_map vm;
|
||||
boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc, options_style), vm);
|
||||
boost::program_options::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("neg1")) {
|
||||
invert_comp1 = true;
|
||||
}
|
||||
|
||||
if (vm.count("neg2")) {
|
||||
invert_comp2 = true;
|
||||
}
|
||||
|
||||
if (vm.count("pfunc")) {
|
||||
printfunction = true;
|
||||
}
|
||||
|
||||
|
||||
// if (!var2.empty()) {
|
||||
// if (var1.empty())
|
||||
// f1 = "true";
|
||||
// else
|
||||
// f1 = var1 + ((!invert_comp1)?(" = "):(" != ")) + value1;
|
||||
// f2 = var2 + ((!invert_comp2)?(" = "):(" != ")) + value2;
|
||||
// std::cout << "f2: (" << f2 << ")" << std::endl;
|
||||
// } else {
|
||||
// std::cout << "f1: " << f1 << std::endl;
|
||||
// std::cout << "f2: " << f2 << std::endl;
|
||||
// }
|
||||
// std::cout << "for finite time algos, dtimebound = " << dtimebound<<std::endl;
|
||||
// std::cout << "threshold for property ="<<threshold<<std::endl;
|
||||
|
||||
// Get file path
|
||||
boost::filesystem::path filepath(modelFile);
|
||||
|
||||
if (vm.count("pg")) {
|
||||
printGraph = filepath.stem().generic_string() + "_" + boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time());
|
||||
}
|
||||
|
||||
if (!filepath.has_extension()) {
|
||||
std::cerr << "File '" << filepath << "' has no extension!" << std::endl;
|
||||
return -1;
|
||||
} else if (filepath.extension().generic_string() == ".alt") { // altarica file
|
||||
return epoch::console::DoAltarica(modelFile, initFile, var1, value1, var2, value2, ds, ps, invert_comp1, invert_comp2,
|
||||
ac, av, algo, hess, blas, threshold, dtimebound, ctimebound, printfunction, printGraph);
|
||||
}
|
||||
}
|
||||
catch (const boost::program_options::error& error) {
|
||||
std::cerr << error.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& error) {
|
||||
std::cerr << boost::diagnostic_information(error) << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
233
src/console/iaepochmain.cc
Normal file
233
src/console/iaepochmain.cc
Normal file
@@ -0,0 +1,233 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/exception/diagnostic_information.hpp>
|
||||
|
||||
#include "grammars/altarica/altarica_lexer.h"
|
||||
#include "epochconsolealtarica.hh"
|
||||
//#include "epochconsoleprism.hh"
|
||||
|
||||
#include "grammars/altarica/AltaricaGenerator.hh"
|
||||
#include "grammars/altarica/AltaricaJson.hh"
|
||||
#include "grammars/altarica/AltaricaInitInfoXML2.hh"
|
||||
#include "grammars/altarica/AltaricaInteractive.hh"
|
||||
//#include "algorithms/incrTarjan.hh"
|
||||
// #include "algorithms/LinearSystemExactParametricSolver.hh"
|
||||
#include "grammars/details/parsingdriverbaseimpl.hh"
|
||||
// #include "solvers/altaricaLogic.hh"
|
||||
#include <ios>
|
||||
|
||||
//using namespace epoch;
|
||||
|
||||
int main (int ac, char* av[])
|
||||
{
|
||||
unsigned int verbosity; // verbosity level
|
||||
std::string modelFile;
|
||||
std::string jsonFile;
|
||||
bool ds;
|
||||
bool printFlow;
|
||||
bool printNULL;
|
||||
bool printDomain;
|
||||
try {
|
||||
|
||||
boost::program_options::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help", "produce help message")
|
||||
("ds", boost::program_options::value<bool>(&ds)->default_value(false), "print semantic debug messages for discrete models")
|
||||
("file", boost::program_options::value<std::string>(&modelFile)->default_value(""), "model file (either .alt (altartica) or [.prism|.nm|.pm|.sm] (prism)")
|
||||
("json", boost::program_options::value<std::string>(&jsonFile)->default_value(""), "json file (init, testcases)")
|
||||
("pf", boost::program_options::value<bool>(&printFlow)->default_value(false), "print flow vars")
|
||||
("pn", boost::program_options::value<bool>(&printNULL)->default_value(false), "print null values")
|
||||
("pd", boost::program_options::value<bool>(&printDomain)->default_value(false), "print var domains")
|
||||
;
|
||||
|
||||
boost::program_options::positional_options_description p;
|
||||
p.add("file", 1);
|
||||
|
||||
|
||||
namespace options_style_ns = boost::program_options::command_line_style;
|
||||
int options_style = options_style_ns::allow_short | options_style_ns::short_allow_adjacent | options_style_ns::short_allow_next
|
||||
| options_style_ns::allow_long | options_style_ns::long_allow_adjacent | options_style_ns::long_allow_next
|
||||
| options_style_ns::allow_sticky | options_style_ns::allow_dash_for_short;
|
||||
boost::program_options::variables_map vm;
|
||||
// boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc, options_style), vm);
|
||||
boost::program_options::store(boost::program_options::command_line_parser(ac,av).options(desc).positional(p).style(options_style).run(), vm);
|
||||
boost::program_options::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
epoch::console::ParsingDriverConsoleReporter pdr;
|
||||
|
||||
|
||||
boost::filesystem::path filepath(modelFile);
|
||||
if (!filepath.has_extension()) {
|
||||
std::cerr << "File '" << filepath << "' has no extension!" << std::endl;
|
||||
return -1;
|
||||
} else if (filepath.extension().generic_string() == ".alt") { // altarica
|
||||
epoch::altarica::AltaricaGenerator gen(modelFile, pdr);
|
||||
gen.amodel_->setDebugSemantics(ds);
|
||||
std::cout << std::endl << "MODEL STATS:" << std::endl;
|
||||
std::cout << "number of state vars: " << gen.amodel_->getNStateVars() << std::endl;
|
||||
std::cout << "number of _different_ flow vars: " << gen.amodel_->getNFlowVars() << std::endl;
|
||||
std::cout << "number of atomic events: " << gen.amodel_->getNEvents() << std::endl <<std::endl;
|
||||
|
||||
|
||||
epoch::altarica::AltaricaJson * aj;
|
||||
if (jsonFile.compare("") != 0) {
|
||||
aj = gen.amodel_->setInitInfoJSON(jsonFile);
|
||||
std::cout << aj->toString() <<std::endl;
|
||||
}
|
||||
|
||||
epoch::altarica::AltaricaState * cstate = gen.amodel_->initialState();
|
||||
std::cout << "Initial State:\n";
|
||||
if (printFlow)
|
||||
gen.amodel_->evaluateFlowVars(cstate);
|
||||
std::cout << cstate->toString(true,printFlow,printNULL,printDomain);
|
||||
|
||||
if (jsonFile.compare("") != 0) {
|
||||
if (aj->hasEvents())
|
||||
return aj->runTestCase(cstate);
|
||||
}
|
||||
if (jsonFile.compare("") == 0 || !aj->hasEvents())
|
||||
epoch::altarica::interactiveExecute(cstate, gen.amodel_,printFlow, printNULL, printDomain);
|
||||
|
||||
|
||||
|
||||
// epoch::altarica::interactiveExecute(gen.amodel_->initialState(), gen.amodel_,true, false, false);
|
||||
|
||||
// typedef epoch::algorithm::IncrTarjan<epoch::solvers::AltaricaLogic,
|
||||
// epoch::altarica::AltaricaGenerator,
|
||||
// epoch::graph::HashTable,
|
||||
// epoch::graph::List,
|
||||
// epoch::algorithm::LinearSystemExactParametricSolver> myTarjanAlt;
|
||||
// myTarjanAlt mt(gen);
|
||||
// epoch::solvers::AltaricaLogicF1 f1;
|
||||
// epoch::solvers::AltaricaLogicF2 f2(gen.amodel_, "main.s", "s9", false);
|
||||
|
||||
// mt.launch(gen.amodel_->initialState(), f1, f2);
|
||||
// delete gen.amodel_;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*** removing PRISM extension ****
|
||||
|
||||
else if (filepath.extension().generic_string() == ".prism" ||
|
||||
filepath.extension().generic_string() ==".nm" ||
|
||||
filepath.extension().generic_string() == ".pm" ||
|
||||
filepath.extension().generic_string() == ".sm") { // prism file
|
||||
epoch::prism::ParsingDriver parser(epoch::prism::ParsingDriver::PARSE_MODULES, pdr, modelFile);
|
||||
parser.context().setType(epoch::prism::Context::PRISM_TYPE_DTMC);
|
||||
parser.Parse();
|
||||
parser.context().setType(epoch::prism::Context::PRISM_TYPE_DTMC);
|
||||
epoch::prism::Generator<epoch::prism::Context::PRISM_TYPE_DTMC> gen(parser.context());
|
||||
typedef
|
||||
epoch::algorithm::IncrTarjan<epoch::solvers::PrismLogic,
|
||||
epoch::prism::Generator<epoch::prism::Context::PRISM_TYPE_DTMC>,
|
||||
epoch::graph::HashTable,
|
||||
epoch::graph::List,
|
||||
epoch::algorithm::LinearSystemExactParametricSolver> myTarjanPrism;
|
||||
myTarjanPrism mt(gen);
|
||||
|
||||
typename epoch::prism::Generator<epoch::prism::Context::PRISM_TYPE_DTMC>::State is(parser.context());
|
||||
for (epoch::prism::Context::BooleanVariableMap::const_iterator bi = parser.context().getBooleanVariables().begin() ; bi != parser.context().getBooleanVariables().end() ; ++bi) {
|
||||
if (!(bi->second->isInitialValueSpecified())) {
|
||||
std::cerr << "Initial value not specified for variable '" << *(bi->first) << "': assuming lowest value of its range" << std::endl;
|
||||
}
|
||||
is.m_BooleanVariables[bi->second->getIndex()] = bi->second->getInitialValue();
|
||||
}
|
||||
for (epoch::prism::Context::IntegerVariableMap::const_iterator ii = parser.context().getIntegerVariables().begin() ; ii != parser.context().getIntegerVariables().end() ; ++ii) {
|
||||
if (!(ii->second->isInitialValueSpecified())) {
|
||||
std::cerr << "Initial value not specified for variable '" << *(ii->first) << "': assuming lowest value of its range" << std::endl;
|
||||
}
|
||||
is.m_IntegerVariables[ii->second->getIndex()] = ii->second->getInitialValue();
|
||||
}
|
||||
for (epoch::prism::Context::DecimalVariableMap::const_iterator di = parser.context().getDecimalVariables().begin() ; di != parser.context().getDecimalVariables().end() ; ++di) {
|
||||
if (!(di->second->isInitialValueSpecified())) {
|
||||
std::cerr << "Initial value not specified for variable '" << *(di->first) << "': assuming lowest value of its range" << std::endl;
|
||||
}
|
||||
is.m_DecimalVariables[di->second->getIndex()] = di->second->getInitialValue();
|
||||
}
|
||||
for (epoch::prism::Context::ModuleMap::const_iterator mi = parser.context().getModules().begin() ; mi != parser.context().getModules().end() ; ++mi) {
|
||||
for (epoch::prism::Context::BooleanVariableMap::const_iterator bi = mi->second->getBooleanVariables().begin() ; bi != mi->second->getBooleanVariables().end() ; ++bi) {
|
||||
if (!(bi->second->isInitialValueSpecified())) {
|
||||
std::cerr << "Initial value not specified for variable '" << *(bi->first) << "': assuming lowest value of its range" << std::endl;
|
||||
}
|
||||
is.m_BooleanVariables[bi->second->getIndex()] = bi->second->getInitialValue();
|
||||
}
|
||||
for (epoch::prism::Context::IntegerVariableMap::const_iterator ii = mi->second->getIntegerVariables().begin() ; ii != mi->second->getIntegerVariables().end() ; ++ii) {
|
||||
if (!(ii->second->isInitialValueSpecified())) {
|
||||
std::cerr << "Initial value not specified for variable '" << *(ii->first) << "': assuming lowest value of its range" << std::endl;
|
||||
}
|
||||
is.m_IntegerVariables[ii->second->getIndex()] = ii->second->getInitialValue();
|
||||
}
|
||||
for (epoch::prism::Context::DecimalVariableMap::const_iterator di = mi->second->getDecimalVariables().begin() ; di != mi->second->getDecimalVariables().end() ; ++di) {
|
||||
if (!(di->second->isInitialValueSpecified())) {
|
||||
std::cerr << "Initial value not specified for variable '" << *(di->first) << "': assuming lowest value of its range" << std::endl;
|
||||
}
|
||||
is.m_DecimalVariables[di->second->getIndex()] = di->second->getInitialValue();
|
||||
}
|
||||
}
|
||||
epoch::solvers::PrismLogic F1("", parser.context(),pdr);
|
||||
epoch::solvers::PrismLogic F2("", parser.context(),pdr);
|
||||
|
||||
mt.launch(is, F1, F2);
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// epoch::altarica::AltaricaInitInfoXML2 *aix2 = new epoch::altarica::AltaricaInitInfoXML2(jsonFile, gen.amodel_);
|
||||
// std::cout << aix2->toString();
|
||||
// exit(0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exit(0);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (const boost::program_options::error& error) {
|
||||
std::cerr << error.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& error) {
|
||||
std::cerr << boost::diagnostic_information(error) << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
211
src/console/symepochmain.cc
Normal file
211
src/console/symepochmain.cc
Normal file
@@ -0,0 +1,211 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Xavier Pucel (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/exception/diagnostic_information.hpp>
|
||||
|
||||
#include "epochconsolealtarica.hh"
|
||||
|
||||
#include "grammars/altarica/AltaricaGenerator.hh"
|
||||
#include "grammars/altarica/Assignment.hh"
|
||||
#include "grammars/altarica/Event.hh"
|
||||
#include "grammars/altarica/MemberAccess.hh"
|
||||
#include "grammars/altarica/Node.hh"
|
||||
#include "grammars/altarica/Synchronisation.hh"
|
||||
#include "grammars/altarica/Transition.hh"
|
||||
#include "grammars/altarica/Variable.hh"
|
||||
|
||||
#include "symbolic/SymModel.hh"
|
||||
//using namespace epoch;
|
||||
|
||||
int main(int ac, char* av[]) {
|
||||
unsigned int verbosity; // verbosity level
|
||||
std::string modelFile;
|
||||
std::string initFile;
|
||||
bool ds;
|
||||
bool printFlow;
|
||||
bool printNULL;
|
||||
bool printDomain;
|
||||
|
||||
// try {
|
||||
boost::program_options::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help", "produce help message")
|
||||
("ds",
|
||||
boost::program_options::value<bool>(&ds)->default_value(false),
|
||||
"print semantic debug messages for discrete models")
|
||||
("file",
|
||||
boost::program_options::value<std::string>(&modelFile)-> default_value(""),
|
||||
"model file (either .alt (altartica) or [.prism|.nm|.pm|.sm] (prism)")
|
||||
("init",
|
||||
boost::program_options::value<std::string>(&initFile)->default_value(""),
|
||||
"init file")
|
||||
("pf",
|
||||
boost::program_options::value<bool>(&printFlow)->default_value(false),
|
||||
"print flow vars")
|
||||
("pn",
|
||||
boost::program_options::value<bool>(&printNULL)->default_value(false),
|
||||
"print null values")
|
||||
("pd",
|
||||
boost::program_options::value<bool>(&printDomain)->default_value(false),
|
||||
"print var domains")
|
||||
;
|
||||
|
||||
boost::program_options::positional_options_description p;
|
||||
p.add("file", 1);
|
||||
|
||||
|
||||
namespace options_style_ns = boost::program_options::command_line_style;
|
||||
int options_style = options_style_ns::allow_short
|
||||
| options_style_ns::short_allow_adjacent
|
||||
| options_style_ns::short_allow_next
|
||||
| options_style_ns::allow_long
|
||||
| options_style_ns::long_allow_adjacent
|
||||
| options_style_ns::long_allow_next
|
||||
| options_style_ns::allow_sticky
|
||||
| options_style_ns::allow_dash_for_short;
|
||||
boost::program_options::variables_map vm;
|
||||
// boost::program_options::store
|
||||
// (boost::program_options::parse_command_line(ac, av, desc, options_style),
|
||||
// vm);
|
||||
boost::program_options::store
|
||||
(boost::program_options::command_line_parser(ac,av).options(desc).
|
||||
positional(p).style(options_style).run(),
|
||||
vm);
|
||||
boost::program_options::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
epoch::console::ParsingDriverConsoleReporter pdr;
|
||||
epoch::altarica::AltaricaGenerator gen(modelFile, pdr);
|
||||
gen.amodel_->setDebugSemantics(ds);
|
||||
|
||||
// if (initFile.compare("") != 0)
|
||||
// gen.amodel_->setInitInfo(initFile);
|
||||
|
||||
// std::cout << std::endl << "MODEL STATS:" << std::endl;
|
||||
|
||||
// std::cout << "number of state vars: "
|
||||
// << gen.amodel_->getNStateVars()
|
||||
// << std::endl;
|
||||
|
||||
// std::cout << "number of _different_ flow vars: "
|
||||
// << gen.amodel_->getNFlowVars()
|
||||
// << std::endl;
|
||||
|
||||
// std::cout << "number of atomic events: "
|
||||
// << gen.amodel_->getNEvents()
|
||||
// << std::endl
|
||||
// << std::endl;
|
||||
|
||||
std::cout << std::endl << "FLOW VARS" << std::endl;
|
||||
for(auto &v : gen.amodel_->getFlowVars()) {
|
||||
std::cout << v->getFullName() << " : "
|
||||
<< v->getDomain()->toString()
|
||||
// << std::endl
|
||||
// << "var at " << v->getIndex()
|
||||
// << " is "
|
||||
// << gen.amodel_->getFlowVar(v->getIndex())->getFullName()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl << "STATE VARS" << std::endl;
|
||||
for(auto &v : gen.amodel_->getStateVars()) {
|
||||
std::cout << v->getFullName()
|
||||
<< " : "
|
||||
<< v->getDomain()->toString()
|
||||
// << std::endl
|
||||
// << "var at " << v->getIndex()
|
||||
// << " is "
|
||||
// << gen.amodel_->getStateVar(v->getIndex())->getFullName()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl << "ATOMIC EVTS" << std::endl;
|
||||
for(auto &e : gen.amodel_->getAtomicEvents()) {
|
||||
std::cout << e->getFullName()
|
||||
<< " : "
|
||||
<< std::endl;
|
||||
if(e->getTrans()->size() > 0)
|
||||
for(auto &t : *e->getTrans()) {
|
||||
std::cout << " pre : "
|
||||
<< t->getPrecond()->toString()
|
||||
<< std::endl;
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
std::cout << " post: " << std::endl;
|
||||
for(auto &a : *t->getAssigns()) {
|
||||
std::cout << " "
|
||||
<< a->getVar()->toString()
|
||||
<< " := "
|
||||
<< a->getExpr()->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl << "SYNCS" << std::endl;
|
||||
for(auto &s: gen.amodel_->getSyncs()) {
|
||||
if(s->getMA() != NULL)
|
||||
std::cout << s->toString() << std::endl;
|
||||
if(s->getMandatoryEvents()->size() > 0) {
|
||||
std::cout << " Mandatory events:" << std::endl;
|
||||
for(auto &e : *s->getMandatoryEvents())
|
||||
std::cout << " " << e->getFullName() << std::endl;
|
||||
}
|
||||
if(s->getOptionalEvents()->size() > 0) {
|
||||
std::cout << " Optional events:" << std::endl;
|
||||
for(auto &e : *s->getOptionalEvents())
|
||||
std::cout << " " << e->getFullName() << std::endl;
|
||||
}
|
||||
if(s->getNumericalConstant() >= 0) {
|
||||
std::cout << " Constraint type: " << s->getConstraintType() << std::endl;
|
||||
std::cout << " Numerical constant: "
|
||||
<< s->getNumericalConstant()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
epoch::symbolic::SymModel bddmodel(gen.amodel_);
|
||||
|
||||
// }
|
||||
// catch (const boost::program_options::error& error) {
|
||||
// std::cerr << error.what() << std::endl;
|
||||
// return -1;
|
||||
// } catch (const epoch::altarica::AltaricaException& error) {
|
||||
// std::cerr << error.what() << std::endl;
|
||||
// return -1;
|
||||
// } catch (const std::exception& error) {
|
||||
// std::cerr << boost::diagnostic_information(error) << std::endl;
|
||||
// return -1;
|
||||
// }
|
||||
}
|
||||
21
src/grammars/CMakeLists.txt
Normal file
21
src/grammars/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
# This file is part of EPOCH.
|
||||
# File: CMakeLists.txt
|
||||
# Author: Florent Teichteil-Königsbuch
|
||||
# Contact: florent.teichteil@onera.fr
|
||||
#
|
||||
# EPOCH is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# EPOCH is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ADD_SUBDIRECTORY (altarica)
|
||||
#ADD_SUBDIRECTORY (prism)
|
||||
|
||||
52
src/grammars/altarica/AltaricaException.cc
Normal file
52
src/grammars/altarica/AltaricaException.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#include "AltaricaException.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
// Class Exception
|
||||
|
||||
AltaricaException::AltaricaException(std::string const & error_message, std::string const & throwing_function)
|
||||
: error_message_(error_message)
|
||||
{
|
||||
if (!throwing_function.empty())
|
||||
function_backtrace_ = std::string(" from '") + throwing_function + "':\n";
|
||||
}
|
||||
|
||||
|
||||
AltaricaException::~AltaricaException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char * AltaricaException::what() const throw()
|
||||
{
|
||||
what_message_ = function_backtrace_ + " " + error_message_;
|
||||
return what_message_.c_str();
|
||||
}
|
||||
|
||||
|
||||
60
src/grammars/altarica/AltaricaException.hh
Normal file
60
src/grammars/altarica/AltaricaException.hh
Normal file
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef ALTARICA_EXCEPTION_H_
|
||||
#define ALTARICA_EXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaException : public std::exception
|
||||
{
|
||||
protected :
|
||||
std::string error_message_;
|
||||
std::string function_backtrace_;
|
||||
mutable std::string what_message_;
|
||||
|
||||
public :
|
||||
AltaricaException(std::string const & error_message, std::string const & throwing_function = "");
|
||||
virtual ~AltaricaException() throw();
|
||||
|
||||
virtual const char * what() const throw();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /*EXCEPTION_H_*/
|
||||
90
src/grammars/altarica/AltaricaGenerator.cc
Normal file
90
src/grammars/altarica/AltaricaGenerator.cc
Normal file
@@ -0,0 +1,90 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MetaEvent.hh"
|
||||
#include "AltaricaGenerator.hh"
|
||||
#include "altarica_driver.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
AltaricaGenerator::AltaricaGenerator(std::string altaricaFile,epoch::ParsingDriverReporter & reporter) {
|
||||
altarica_driver * driver = new altarica_driver(reporter, altaricaFile, false, false);
|
||||
driver->Parse();
|
||||
amodel_ = driver->amodel;
|
||||
amodel_->finalize("main", false);
|
||||
delete driver;
|
||||
}
|
||||
|
||||
AltaricaGenerator::~AltaricaGenerator() {
|
||||
delete amodel_;
|
||||
}
|
||||
|
||||
std::size_t AltaricaGenerator::State::hash() const {
|
||||
// AltaricaState: as_
|
||||
return as_->hash();
|
||||
}
|
||||
|
||||
bool AltaricaGenerator::State::operator==(const State&o) const {
|
||||
return as_->equals(o.as_);
|
||||
}
|
||||
|
||||
bool AltaricaGenerator::State::operator<(const State&o) const {
|
||||
return as_<o.as_;
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::State::print(std::ostream& o) const {
|
||||
o << (as_->toString(true, false,false,false));
|
||||
return o;
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::State::printDot(std::ostream& o, std::string& att) const {
|
||||
return print(o);
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::Transition::print(std::ostream& o) const {
|
||||
o << "{ probability = " << m_Probability << " , reward = " << m_Reward << " }";
|
||||
return o;
|
||||
}
|
||||
|
||||
std::ostream& AltaricaGenerator::Transition::printDot(std::ostream& o, std::string& att) const {
|
||||
o << "{p=" << m_Probability << ", r=" << m_Reward << "}";
|
||||
return o;
|
||||
}
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::State& s) {
|
||||
return s.print(o);
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::Transition& t) {
|
||||
return t.print(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
src/grammars/altarica/AltaricaGenerator.hh
Normal file
96
src/grammars/altarica/AltaricaGenerator.hh
Normal file
@@ -0,0 +1,96 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_GENERATOR_HH
|
||||
#define ALTARICA_GENERATOR_HH
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "AltaricaState.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "grammars/parsingdriverbase.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
struct AltaricaGenerator {
|
||||
|
||||
epoch::altarica::AltaricaModel *amodel_;
|
||||
|
||||
struct State {
|
||||
epoch::altarica::AltaricaState *as_;
|
||||
inline State(epoch::altarica::AltaricaState *s) : as_(s) {}
|
||||
inline State() : as_(NULL) {}
|
||||
inline State(const epoch::altarica::AltaricaGenerator::State& s) {
|
||||
as_ = s.as_->clone();
|
||||
}
|
||||
~State() {delete as_;}
|
||||
|
||||
std::size_t hash() const;
|
||||
bool operator==(const State&o) const;
|
||||
bool operator<(const State& o) const;
|
||||
|
||||
std::ostream& print(std::ostream& o) const;
|
||||
std::ostream& printDot(std::ostream& o, std::string& att) const;
|
||||
};
|
||||
|
||||
struct Transition {
|
||||
double m_Probability;
|
||||
double m_Reward;
|
||||
|
||||
Transition(double probability, double reward) : m_Probability(probability), m_Reward(reward) {}
|
||||
Transition() {}
|
||||
Transition(const Transition& other) : m_Probability(other.m_Probability), m_Reward(other.m_Reward) {}
|
||||
|
||||
inline const double& getProbability() const {return m_Probability;}
|
||||
inline const double& getReward() const {return m_Reward;}
|
||||
|
||||
std::ostream& print(std::ostream& o) const;
|
||||
std::ostream& printDot(std::ostream& o, std::string& att) const;
|
||||
};
|
||||
|
||||
template <typename Tfunctor>
|
||||
void generateTransitions(const State& s, const Tfunctor& functor);
|
||||
|
||||
AltaricaGenerator(std::string altaricaFile,epoch::ParsingDriverReporter & reporter );
|
||||
~AltaricaGenerator();
|
||||
|
||||
void setDiscrete() {amodel_->setDiscrete();}
|
||||
void setContinuous() {amodel_->setContinuous();}
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::State& s);
|
||||
|
||||
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::Transition& t);
|
||||
|
||||
} // namespace altarica
|
||||
} // namespace epoch
|
||||
|
||||
#include "details/AltaricaGeneratorImpl.hh"
|
||||
|
||||
#endif // ALTARICA_GENERATOR_HH
|
||||
|
||||
164
src/grammars/altarica/AltaricaInitInfo.cc
Normal file
164
src/grammars/altarica/AltaricaInitInfo.cc
Normal file
@@ -0,0 +1,164 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "AltaricaInitInfo.hh"
|
||||
#include "AltaricaException.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Event.hh"
|
||||
#include "Variable.hh"
|
||||
#include "values/Value.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "domains/Domains.hh"
|
||||
#include "Values.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
void AltaricaInitInfo::overrideLaws() {
|
||||
for (auto i : initLaws)
|
||||
(i.first)->setLaw(i.second);
|
||||
}
|
||||
|
||||
Value * AltaricaInitInfo::getInitValue(unsigned int i) const {
|
||||
std::map<unsigned int, Value*>::const_iterator j = initValues.find(i);
|
||||
if (j!=initValues.end())
|
||||
return j->second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
std::string AltaricaInitInfo::toString() const {
|
||||
std::ostringstream oss;
|
||||
oss << std::endl
|
||||
<< "INIT VALUES:" << std::endl;
|
||||
for (auto i: initValues) {
|
||||
oss << amodel->getStateVar(i.first)->toString()
|
||||
<< " = " << i.second->toString()
|
||||
<< std::endl;
|
||||
}
|
||||
oss << "INIT LAWS:" << std::endl;
|
||||
for (auto i: initLaws) {
|
||||
oss << i.first->toString() << " : "
|
||||
<< i.second->toString() << std::endl;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
Value * AltaricaInitInfo::getValue(Variable *var, std::string valName) {
|
||||
|
||||
Value * v;
|
||||
Domain *d = var->getDomain();
|
||||
if (d != NULL) {
|
||||
PredefinedDomain *pd = dynamic_cast<PredefinedDomain*>(d);
|
||||
EnumDomain *ed = dynamic_cast<EnumDomain*>(d);
|
||||
RangeDomain *rd = dynamic_cast<RangeDomain*>(d);
|
||||
ArrayDomain *ad = dynamic_cast<ArrayDomain*>(d);
|
||||
StructuredDomain *sd = dynamic_cast<StructuredDomain*>(d);
|
||||
RealDomain *reald = dynamic_cast<RealDomain*>(d);
|
||||
|
||||
if (pd) {
|
||||
if (pd->isBooleanDomain()) {
|
||||
// scan true of false from valName
|
||||
std::transform(valName.begin(),
|
||||
valName.end(),
|
||||
valName.begin(),
|
||||
::toupper);
|
||||
if (valName.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else
|
||||
v = new ValueBool(false, true);
|
||||
} else {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
}
|
||||
} else if (ed) {
|
||||
v = new ValueSymbol(valName);
|
||||
} else if (rd) {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
} else if (reald) {
|
||||
std::istringstream stm;
|
||||
double i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueReal(i);
|
||||
} else if (ad) {
|
||||
throw AltaricaException("initing array domains not yet implemented");
|
||||
} else if (sd) {
|
||||
throw AltaricaException("initing structured domains not yet implemented");
|
||||
}
|
||||
} else {
|
||||
//identifiers starting with digit are forbidden...
|
||||
std::istringstream stm;
|
||||
int i = INT_MIN;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
if (i != INT_MIN) {
|
||||
v = new ValueInt(i);
|
||||
} else {
|
||||
std::string temp(valName);
|
||||
std::transform(temp.begin(), temp.end(),temp.begin(), ::toupper);
|
||||
if (temp.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else if (temp.compare("FALSE") == 0)
|
||||
v = new ValueBool(false, true);
|
||||
else
|
||||
v = new ValueSymbol(valName);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Node*> * AltaricaInitInfo::getNodes(std::string node_name) {
|
||||
std::vector<Node*> *altNodeVector = amodel->findNodesByType(node_name);
|
||||
if (altNodeVector == NULL) {
|
||||
altNodeVector = new std::vector<Node*>();
|
||||
Node * n = amodel->findNodeByFullName(node_name);
|
||||
if (n==NULL)
|
||||
std::cout << "cannot find node: " << node_name << std::endl;
|
||||
else {
|
||||
altNodeVector->push_back(n);
|
||||
}
|
||||
}
|
||||
return altNodeVector;
|
||||
|
||||
}
|
||||
66
src/grammars/altarica/AltaricaInitInfo.hh
Normal file
66
src/grammars/altarica/AltaricaInitInfo.hh
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INIT_INFO_HH
|
||||
#define ALTARICA_INIT_INFO_HH
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
class AltaricaModel;
|
||||
class EventLaw;
|
||||
class Event;
|
||||
class Variable;
|
||||
class Node;
|
||||
|
||||
|
||||
|
||||
class AltaricaInitInfo {
|
||||
protected:
|
||||
std::map<unsigned int, Value*> initValues;
|
||||
std::map<Event *, EventLaw *> initLaws;
|
||||
AltaricaModel * amodel;
|
||||
Value * getValue(Variable *var, std::string valName);
|
||||
|
||||
public:
|
||||
AltaricaInitInfo(AltaricaModel *am) : amodel(am) {}
|
||||
Value * getInitValue(unsigned int i) const;
|
||||
virtual std::string toString() const;
|
||||
void overrideLaws();
|
||||
std::vector<Node*> * getNodes(std::string);
|
||||
|
||||
virtual bool hasInit() {return true;}
|
||||
virtual bool hasGoal() {return false;}
|
||||
virtual bool hasEvents() {return false;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
278
src/grammars/altarica/AltaricaInitInfoXML.cc
Normal file
278
src/grammars/altarica/AltaricaInitInfoXML.cc
Normal file
@@ -0,0 +1,278 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaInitInfoXML.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Event.hh"
|
||||
#include "Node.hh"
|
||||
#include "Variable.hh"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include "domains/Domains.hh"
|
||||
#include "values/ValueBool.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueSymbol.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#include "expressions/ExpressionREAL.hh"
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
AltaricaInitInfoXML::AltaricaInitInfoXML(std::string initFile, AltaricaModel *am) : AltaricaInitInfo(am) {
|
||||
amodel = am;
|
||||
parser.set_substitute_entities();
|
||||
parser.parse_file(initFile);
|
||||
if (parser) {
|
||||
const xmlpp::Node* pNode = parser.get_document()->get_root_node();
|
||||
processRoot(pNode);
|
||||
}
|
||||
overrideLaws();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML::processRoot(const xmlpp::Node * root) {
|
||||
xmlpp::Node::NodeList list = root->get_children();
|
||||
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter) {
|
||||
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(*iter);
|
||||
if(nodeText && nodeText->is_white_space())
|
||||
continue;
|
||||
processNode(*iter);
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaInitInfoXML::processEvent(const xmlpp::Node * xmlnode, std::vector<Node *> *altNodeVector) {
|
||||
const xmlpp::Element* nodeLaw = dynamic_cast<const xmlpp::Element*>(xmlnode);
|
||||
const xmlpp::Element::AttributeList& attributes = nodeLaw->get_attributes();
|
||||
std::string eventName;
|
||||
std::string lawName;
|
||||
std::string param;
|
||||
bool expLaw = true;
|
||||
bool noParam = false;
|
||||
double paramdouble;
|
||||
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) {
|
||||
const xmlpp::Attribute* attribute = *iter;
|
||||
std::string attname = attribute->get_name();
|
||||
std::string attval = attribute->get_value();
|
||||
if (attname.compare("name") == 0)
|
||||
eventName = attval;
|
||||
else if (attname.compare("law") == 0)
|
||||
lawName = attval;
|
||||
else if (attname.compare("param") == 0)
|
||||
param = attval;
|
||||
}
|
||||
|
||||
if (lawName.compare("dirac") == 0)
|
||||
expLaw = false;
|
||||
if (param.empty())
|
||||
noParam = true;
|
||||
else {
|
||||
std::istringstream stm;
|
||||
stm.str(param);
|
||||
stm >>paramdouble;
|
||||
}
|
||||
|
||||
MemberAccess * tempMA = new MemberAccess(eventName);
|
||||
|
||||
for (std::vector<Node*>::iterator altNodeIt = altNodeVector->begin(); altNodeIt!= altNodeVector->end(); ++altNodeIt) {
|
||||
|
||||
Event * oldEvent = (*altNodeIt)->findEventByName(tempMA);
|
||||
Expression *oldLaw = NULL;
|
||||
if (expLaw && noParam) {
|
||||
oldLaw = oldEvent->getLaw()->getParam();
|
||||
}
|
||||
|
||||
EventLaw * newLaw;
|
||||
if (expLaw) {
|
||||
if (oldLaw != NULL)
|
||||
newLaw = new EventLaw(ALTARICA_EXP,oldLaw);
|
||||
else
|
||||
newLaw = new EventLaw(ALTARICA_EXP,new ExpressionREAL(paramdouble));
|
||||
} else {
|
||||
newLaw = new EventLaw(ALTARICA_DIRAC_0,0);
|
||||
}
|
||||
|
||||
initLaws[oldEvent] = newLaw;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaInitInfoXML::processValue(const xmlpp::Node * xmlnode, std::vector<Node *>* altNodeVector) {
|
||||
const xmlpp::Element* nodeValue = dynamic_cast<const xmlpp::Element*>(xmlnode);
|
||||
const xmlpp::Element::AttributeList& attributes = nodeValue->get_attributes();
|
||||
std::string varName;
|
||||
std::string valName;
|
||||
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) {
|
||||
const xmlpp::Attribute* attribute = *iter;
|
||||
std::string attname = attribute->get_name();
|
||||
std::string attval = attribute->get_value();
|
||||
if (attname.compare("var") == 0)
|
||||
varName = attval;
|
||||
else if (attname.compare("val") == 0)
|
||||
valName = attval;
|
||||
}
|
||||
|
||||
for (std::vector<Node*>::iterator altNodeIt = altNodeVector->begin(); altNodeIt!= altNodeVector->end(); ++altNodeIt) {
|
||||
Value * v;
|
||||
Variable * var = (*altNodeIt)->findStateVariableByName(varName);
|
||||
if (var == NULL)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("cannot find variable to init")));
|
||||
unsigned int varIndex = var->getIndex();
|
||||
// try to guess type from domain
|
||||
Domain * d = var->getDomain();
|
||||
if (d!= NULL) {
|
||||
PredefinedDomain *pd = dynamic_cast<PredefinedDomain*>(d);
|
||||
EnumDomain *ed = dynamic_cast<EnumDomain*>(d);
|
||||
RangeDomain *rd = dynamic_cast<RangeDomain*>(d);
|
||||
ArrayDomain *ad = dynamic_cast<ArrayDomain*>(d);
|
||||
StructuredDomain *sd = dynamic_cast<StructuredDomain*>(d);
|
||||
RealDomain *reald = dynamic_cast<RealDomain*>(d);
|
||||
|
||||
if (pd) {
|
||||
if (pd->isBooleanDomain()) {
|
||||
// scan true of false from valName
|
||||
std::transform(valName.begin(), valName.end(),valName.begin(), ::toupper);
|
||||
if (valName.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else
|
||||
v = new ValueBool(false, true);
|
||||
} else {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
}
|
||||
} else if (ed) {
|
||||
v = new ValueSymbol(valName);
|
||||
} else if (rd) {
|
||||
//scan int from valName
|
||||
std::istringstream stm;
|
||||
int i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueInt(i);
|
||||
} else if (reald) {
|
||||
std::istringstream stm;
|
||||
double i;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
v = new ValueReal(i);
|
||||
} else if (ad) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("initing array domains not yet implemented")));
|
||||
} else if (sd) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("initing structured domains not yet implemented")));
|
||||
}
|
||||
} else {
|
||||
//identifiers starting with digit are forbidden...
|
||||
std::istringstream stm;
|
||||
int i = INT_MIN;
|
||||
stm.str(valName);
|
||||
stm >>i;
|
||||
if (i != INT_MIN) {
|
||||
v = new ValueInt(i);
|
||||
} else {
|
||||
std::string temp(valName);
|
||||
std::transform(temp.begin(), temp.end(),temp.begin(), ::toupper);
|
||||
if (temp.compare("TRUE") == 0)
|
||||
v = new ValueBool(true, false);
|
||||
else if (temp.compare("FALSE") == 0)
|
||||
v = new ValueBool(false, true);
|
||||
else
|
||||
v = new ValueSymbol(valName);
|
||||
}
|
||||
}
|
||||
initValues[varIndex] = v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML::processNode(const xmlpp::Node * xmlnode) {
|
||||
|
||||
|
||||
const Glib::ustring nodename = xmlnode->get_name();
|
||||
|
||||
bool nodeisclass = false;
|
||||
std::vector<Node *> *altNodeVector;
|
||||
|
||||
|
||||
|
||||
xmlpp::Node* nodeName = *((xmlnode->get_children(Glib::ustring("name"))).begin());
|
||||
|
||||
|
||||
xmlpp::Node* nodeNameSon = *(nodeName->get_children().begin());
|
||||
std::string altaricaNodeName = (dynamic_cast<const xmlpp::TextNode*>(nodeNameSon))->get_content();
|
||||
|
||||
xmlpp::Node::NodeList nodeTypeList = xmlnode->get_children(Glib::ustring("type"));
|
||||
if (nodeTypeList.size() != 0) {
|
||||
xmlpp::Node* nodeType = *(nodeTypeList.begin());
|
||||
xmlpp::Node::NodeList nodeTypeListSons = nodeType->get_children();
|
||||
xmlpp::Node* nodeTypeSon = *(nodeTypeListSons.begin());
|
||||
const xmlpp::TextNode * texttype = dynamic_cast<const xmlpp::TextNode*>(nodeTypeSon);
|
||||
std::string altaricaNodeType = texttype->get_content();
|
||||
if (altaricaNodeType.compare("class") == 0)
|
||||
nodeisclass = true;
|
||||
}
|
||||
|
||||
|
||||
if (nodeisclass) {
|
||||
altNodeVector = amodel->findNodesByType(altaricaNodeName);
|
||||
if (altNodeVector == NULL)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("cannot find node by type")));
|
||||
} else {
|
||||
Node * n = amodel->findNodeByFullName(altaricaNodeName);
|
||||
if (n==NULL)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("cannot find node")));
|
||||
altNodeVector = new std::vector<Node*>();
|
||||
altNodeVector->push_back(n);
|
||||
}
|
||||
|
||||
xmlpp::Node::NodeList lawnode = xmlnode->get_children(Glib::ustring("laws"));
|
||||
xmlpp::Node::NodeList eventlist = (*(lawnode.begin()))->get_children(Glib::ustring("event"));
|
||||
for(xmlpp::Node::NodeList::iterator iter = eventlist.begin(); iter != eventlist.end(); ++iter) {
|
||||
processEvent(*iter, altNodeVector);
|
||||
}
|
||||
|
||||
|
||||
xmlpp::Node::NodeList valuesnode = xmlnode->get_children(Glib::ustring("values"));
|
||||
xmlpp::Node::NodeList valueList = (*(valuesnode.begin()))->get_children(Glib::ustring("value"));
|
||||
for(xmlpp::Node::NodeList::iterator iter = valueList.begin(); iter != valueList.end(); ++iter) {
|
||||
processValue(*iter, altNodeVector);
|
||||
}
|
||||
delete altNodeVector;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
66
src/grammars/altarica/AltaricaInitInfoXML.hh
Normal file
66
src/grammars/altarica/AltaricaInitInfoXML.hh
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INIT_INFO_XML_HH
|
||||
#define ALTARICA_INIT_INFO_XML_HH
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "libxml++/libxml++.h"
|
||||
#include "AltaricaInitInfo.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Value;
|
||||
class Node;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
|
||||
|
||||
class AltaricaInitInfoXML : public AltaricaInitInfo {
|
||||
private:
|
||||
xmlpp::DomParser parser;
|
||||
|
||||
// std::map<unsigned int, Value*> initValues;
|
||||
// std::map<Event *, EventLaw *> initLaws;
|
||||
|
||||
// void overrideLaws();
|
||||
// void computeInitValues();
|
||||
void processRoot(const xmlpp::Node * root);
|
||||
void processNode(const xmlpp::Node * node);
|
||||
|
||||
void processEvent(const xmlpp::Node * node, std::vector<Node *>* altNode);
|
||||
void processValue(const xmlpp::Node * node, std::vector<Node*>* altNode);
|
||||
public:
|
||||
AltaricaInitInfoXML(std::string initFile,AltaricaModel *am);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
174
src/grammars/altarica/AltaricaInitInfoXML2.cc
Normal file
174
src/grammars/altarica/AltaricaInitInfoXML2.cc
Normal file
@@ -0,0 +1,174 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaInitInfoXML2.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Event.hh"
|
||||
#include "Node.hh"
|
||||
#include "Variable.hh"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include "domains/Domains.hh"
|
||||
#include "values/ValueBool.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueSymbol.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#include "expressions/ExpressionREAL.hh"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
#include <boost/property_tree/exceptions.hpp>
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::ptree_bad_path;
|
||||
|
||||
|
||||
AltaricaInitInfoXML2::AltaricaInitInfoXML2(std::string initFile, AltaricaModel *am) : AltaricaInitInfo(am) {
|
||||
amodel = am;
|
||||
ptree pt;
|
||||
read_xml (initFile, pt);
|
||||
|
||||
|
||||
processRoot(pt);
|
||||
overrideLaws();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML2::processRoot(ptree& root) {
|
||||
for (auto&v: root.get_child("init")) {
|
||||
if (v.first.compare("node")==0)
|
||||
processNode(v.second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML2::processEvent(ptree& eventattr, std::vector<Node *> *altNodeVector) {
|
||||
|
||||
std::string lawName;
|
||||
std::string param;
|
||||
std::string eventName = eventattr.get<std::string>("name");
|
||||
|
||||
try {
|
||||
lawName = eventattr.get<std::string>("law");
|
||||
} catch (ptree_bad_path e) {
|
||||
}
|
||||
|
||||
try {
|
||||
param = eventattr.get<std::string>("param");
|
||||
} catch (ptree_bad_path e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool expLaw = true;
|
||||
bool noParam = false;
|
||||
double paramdouble;
|
||||
|
||||
if (lawName.compare("dirac") == 0)
|
||||
expLaw = false;
|
||||
if (param.empty())
|
||||
noParam = true;
|
||||
else {
|
||||
std::istringstream stm;
|
||||
stm.str(param);
|
||||
stm >>paramdouble;
|
||||
}
|
||||
|
||||
MemberAccess tempMA(eventName);
|
||||
|
||||
for (auto& altNodeIt : *altNodeVector) {
|
||||
|
||||
Event * oldEvent = altNodeIt->findEventByName(&tempMA);
|
||||
Expression *oldLaw = NULL;
|
||||
if (expLaw && noParam) {
|
||||
oldLaw = oldEvent->getLaw()->getParam();
|
||||
}
|
||||
|
||||
EventLaw * newLaw;
|
||||
if (expLaw) {
|
||||
if (oldLaw != NULL)
|
||||
newLaw = new EventLaw(ALTARICA_EXP,oldLaw);
|
||||
else
|
||||
newLaw = new EventLaw(ALTARICA_EXP,new ExpressionREAL(paramdouble));
|
||||
} else {
|
||||
newLaw = new EventLaw(ALTARICA_DIRAC_0,0);
|
||||
}
|
||||
|
||||
initLaws[oldEvent] = newLaw;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaInitInfoXML2::processValue(ptree & node, std::vector<Node *>* altNodeVector) {
|
||||
for (auto &i: *altNodeVector) {
|
||||
Variable * var = i->findStateVariableByName(node.get<std::string>("var"));
|
||||
if (var != NULL) {
|
||||
Value * v = getValue(var,node.get<std::string>("val"));
|
||||
initValues[var->getIndex()] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AltaricaInitInfoXML2::processNode(ptree& pt) {
|
||||
|
||||
std::vector<Node *> *altNodeVector = getNodes(pt.get_child("name").data());
|
||||
|
||||
for (auto &i :pt)
|
||||
if (i.first.compare("laws")==0) {
|
||||
for (auto& ii:i.second) {
|
||||
if (ii.first.compare("event") == 0)
|
||||
processEvent(ii.second.get_child("<xmlattr>"), altNodeVector);
|
||||
}
|
||||
}
|
||||
|
||||
else if (i.first.compare("values") == 0) {
|
||||
for (auto& ii:i.second) {
|
||||
if (ii.first.compare("value") == 0)
|
||||
processValue(ii.second.get_child("<xmlattr>"), altNodeVector);
|
||||
}
|
||||
|
||||
}
|
||||
delete altNodeVector;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
64
src/grammars/altarica/AltaricaInitInfoXML2.hh
Normal file
64
src/grammars/altarica/AltaricaInitInfoXML2.hh
Normal file
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INIT_INFO_XML2_HH
|
||||
#define ALTARICA_INIT_INFO_XML2_HH
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "AltaricaInitInfo.hh"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Value;
|
||||
class Node;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
|
||||
|
||||
class AltaricaInitInfoXML2 : public AltaricaInitInfo {
|
||||
private:
|
||||
void processRoot(boost::property_tree::ptree& root);
|
||||
void processNode(boost::property_tree::ptree& node);
|
||||
|
||||
void processEvent(boost::property_tree::ptree & node, std::vector<Node *>* altNode);
|
||||
// void processEvents(boost::property_tree::ptree & node, std::vector<Node *>* altNode);
|
||||
void processValue(boost::property_tree::ptree & node, std::vector<Node*>* altNode);
|
||||
// void processValues(boost::property_tree::ptree & node, std::vector<Node*>* altNode);
|
||||
public:
|
||||
AltaricaInitInfoXML2(std::string initFile,AltaricaModel *am);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
72
src/grammars/altarica/AltaricaInteractive.cc
Normal file
72
src/grammars/altarica/AltaricaInteractive.cc
Normal file
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaInteractive.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
void ::epoch::altarica::interactiveExecute(AltaricaState *cstate, AltaricaModel * amodel, bool printFlow, bool printNULL, bool printDomain) {
|
||||
int choice;
|
||||
while (true) {
|
||||
std::vector<epoch::altarica::MetaEvent*> * mev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
std::cout<<"\n # metaEvents: "<< mev->size() << std::endl;
|
||||
for (int i=0; i<mev->size(); ++i) {
|
||||
std::cout << " MEV " << i << ": " << (*mev)[i]->toString();
|
||||
}
|
||||
do {
|
||||
std::cout << "\n\ninput MEV number (-1 exits): ";
|
||||
std::string l;
|
||||
std::getline(std::cin,l);
|
||||
std::stringstream ss(l);
|
||||
ss >> choice;
|
||||
if (ss.fail()) {
|
||||
if (std::cin.eof()){
|
||||
std::cout << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
choice = std::numeric_limits<int>::max();
|
||||
}
|
||||
} while (choice > ((int)mev->size() - 1));
|
||||
|
||||
if (choice <= -1)
|
||||
exit(0);
|
||||
|
||||
std::cout << "Executing MEV: "<< (*mev)[choice]->toString() << std::endl;
|
||||
std::cout << "state reached:" << std::endl;
|
||||
cstate = amodel->getNextState(cstate, (*mev)[choice]);
|
||||
if (printFlow)
|
||||
amodel->evaluateFlowVars(cstate);
|
||||
std::cout << cstate->toString(true,printFlow,printNULL,printDomain);
|
||||
}
|
||||
|
||||
}
|
||||
42
src/grammars/altarica/AltaricaInteractive.hh
Normal file
42
src/grammars/altarica/AltaricaInteractive.hh
Normal file
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_INTERACTIVE_HH
|
||||
#define ALTARICA_INTERACTIVE_HH
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
void interactiveExecute(AltaricaState *cstate,
|
||||
AltaricaModel * amodel,
|
||||
bool printFlow = false,
|
||||
bool printNULL = false,
|
||||
bool printDomain = false);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
370
src/grammars/altarica/AltaricaJson.cc
Normal file
370
src/grammars/altarica/AltaricaJson.cc
Normal file
@@ -0,0 +1,370 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaJson.hh"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "Node.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "expressions/ExpressionREAL.hh"
|
||||
#include "Variable.hh"
|
||||
#include "domains/Domains.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "AltaricaState.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
AltaricaJson::AltaricaJson(std::string jsonFile, AltaricaModel *am) : AltaricaInitInfo(am),
|
||||
hasInit_(false),
|
||||
hasGoal_(false),
|
||||
hasEvents_(false),
|
||||
hasActive_(false),
|
||||
hasInactive_(false)
|
||||
{
|
||||
verbose = true;
|
||||
parseJsonFile(jsonFile);
|
||||
overrideLaws();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaJson::parseJsonFile(std::string jsonFile) {
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(jsonFile,pt);
|
||||
for (auto& ii : pt.get_child("init")) {
|
||||
hasInit_ = true;
|
||||
if (verbose) std::cout << "processing init info for " << ii.first << " ";
|
||||
std::string node_name = ii.first;
|
||||
std::vector<Node*> * altNodeVector = NULL;
|
||||
|
||||
|
||||
altNodeVector = getNodes(node_name);
|
||||
if (altNodeVector->size() == 0)
|
||||
{
|
||||
std::cerr << "could not find any node for: " << node_name << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for (auto& iii : ii.second.get_child("")) {
|
||||
|
||||
for (auto &n : *altNodeVector) {
|
||||
|
||||
|
||||
|
||||
if (iii.first.compare("laws") == 0) {
|
||||
if (verbose) std::cout << " applying law init info on node: " << n->getMA()->toString() << std::endl;
|
||||
for (auto& i4 : iii.second.get_child("")) {
|
||||
std::string event_name = i4.first;
|
||||
MemberAccess * tempMA = new MemberAccess(event_name);
|
||||
|
||||
Event * oldEvent = n->findEventByName(tempMA);
|
||||
if (oldEvent == NULL) {
|
||||
std::cerr << " !!!! CANNOT FIND EVENT: " << event_name << " in node " << node_name << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::string law_type;
|
||||
double param = std::numeric_limits<double>::min();
|
||||
for (auto& i5:i4.second.get_child("")) {
|
||||
if (i5.first.compare("type") == 0) {
|
||||
law_type = i5.second.get_value<std::string>();
|
||||
}
|
||||
if (i5.first.compare("param") == 0) {
|
||||
param = i5.second.get_value<float>();
|
||||
}
|
||||
|
||||
}
|
||||
EventLaw * newLaw;
|
||||
Expression * newParam;
|
||||
if (law_type.compare("") == 0) {
|
||||
newLaw = oldEvent->getLaw()->clone();
|
||||
} else if (law_type.compare("exp") == 0) {
|
||||
newLaw = new EventLaw(ALTARICA_EXP);
|
||||
} else if (law_type.compare("dirac") == 0) {
|
||||
newLaw = new EventLaw(ALTARICA_DIRAC_0);
|
||||
} else if (law_type.compare("const") == 0) {
|
||||
newLaw = new EventLaw(ALTARICA_DISCRETE);
|
||||
}
|
||||
if (param == std::numeric_limits<double>::min())
|
||||
newParam = oldEvent->getLaw()->getParam();
|
||||
else
|
||||
newParam = new ExpressionREAL(param);
|
||||
newLaw->setParam(newParam);
|
||||
initLaws[oldEvent] = newLaw;
|
||||
}
|
||||
}
|
||||
|
||||
if (iii.first.compare("values") == 0) {
|
||||
if (verbose) std::cout << " applying values init info on node: " << n->getMA()->toString() << std::endl;
|
||||
for (auto& i4 : iii.second.get_child("")) {
|
||||
for (auto& i5 : i4.second.get_child("")) {
|
||||
std::string varName = i5.first;
|
||||
if (verbose)std::cout << " on variable: " << varName << std::endl;
|
||||
Variable * var = n->findStateVariableByName(varName);
|
||||
if (var == NULL) {
|
||||
std::cerr << " !!! CANNOT FIND VARIABLE " << varName << std::endl;
|
||||
break;
|
||||
}
|
||||
Value * v = getValue(var, i5.second.get_value<std::string>());
|
||||
initValues[var->getIndex()] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& ii : pt.get_child("goal")) {
|
||||
hasGoal_ = true;
|
||||
std::string node_name = ii.first;
|
||||
std::vector<Node*> * altNodeVector = NULL;
|
||||
if (verbose) std::cout << "processing goal info for " << node_name;
|
||||
|
||||
altNodeVector = amodel->findNodesByType(node_name);
|
||||
if (altNodeVector == NULL) {
|
||||
altNodeVector = new std::vector<Node*>();
|
||||
Node *n = amodel->findNodeByFullName(node_name);
|
||||
if (n != NULL) {
|
||||
if (verbose) std::cout << " (instance)" << std::endl;
|
||||
altNodeVector->push_back(n);
|
||||
}
|
||||
} else
|
||||
if (verbose) std::cout << " (type)" << std::endl;
|
||||
if (altNodeVector->size() == 0) {
|
||||
std::cerr << "cannot find node: " << node_name << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto &n : *altNodeVector) {
|
||||
for (auto & i3 : ii.second.get_child("")) {
|
||||
for (auto& i4 : i3.second.get_child("")) {
|
||||
std::string varName = i4.first;
|
||||
std::string varValue = i4.second.get_value<std::string>();
|
||||
Variable * var = n->findStateVariableByName(varName);
|
||||
if (var == NULL)
|
||||
var = n->findFlowVariableByName(varName);
|
||||
if (var == NULL) {
|
||||
if (verbose) std::cout << "cannot find variable " << varName << std::endl;
|
||||
break;
|
||||
}
|
||||
Value * v = getValue(var, varValue);
|
||||
goalValues[var] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (auto& ii : pt.get_child("events")) {
|
||||
hasEvents_ = true;
|
||||
std::vector<Event*> * newMEV = new std::vector<Event*>();
|
||||
for (auto& i3: ii.second.get_child("")) {
|
||||
std::string evName = i3.second.data();
|
||||
MemberAccess * tempMA = new MemberAccess(evName);
|
||||
tempMA->setGlobal(true);
|
||||
Event * ev = amodel->getMainNode()->findEventByName(tempMA);
|
||||
if (ev == NULL) {
|
||||
std::cerr << "cannot find event " << evName << std::endl;
|
||||
break;
|
||||
}
|
||||
newMEV->push_back(ev);
|
||||
}
|
||||
testCase.push_back(newMEV);
|
||||
}
|
||||
|
||||
for (auto& ii : pt.get_child("active")) {
|
||||
hasActive_ = true;
|
||||
std::vector<Event*> * newMEV = new std::vector<Event*>();
|
||||
for (auto& i3: ii.second.get_child("")) {
|
||||
std::string evName = i3.second.data();
|
||||
MemberAccess * tempMA = new MemberAccess(evName);
|
||||
tempMA->setGlobal(true);
|
||||
Event * ev = amodel->getMainNode()->findEventByName(tempMA);
|
||||
if (ev == NULL) {
|
||||
std::cerr << "cannot find event " << evName << std::endl;
|
||||
break;
|
||||
}
|
||||
newMEV->push_back(ev);
|
||||
}
|
||||
activeEvents.push_back(newMEV);
|
||||
}
|
||||
|
||||
for (auto& ii : pt.get_child("inactive")) {
|
||||
hasInactive_ = true;
|
||||
std::vector<Event*> * newMEV = new std::vector<Event*>();
|
||||
for (auto& i3: ii.second.get_child("")) {
|
||||
std::string evName = i3.second.data();
|
||||
MemberAccess * tempMA = new MemberAccess(evName);
|
||||
tempMA->setGlobal(true);
|
||||
Event * ev = amodel->getMainNode()->findEventByName(tempMA);
|
||||
if (ev == NULL) {
|
||||
std::cerr << "cannot find event " << evName << std::endl;
|
||||
break;
|
||||
}
|
||||
newMEV->push_back(ev);
|
||||
}
|
||||
inactiveEvents.push_back(newMEV);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string AltaricaJson::toString() const {
|
||||
std::string s = AltaricaInitInfo::toString();
|
||||
if (hasGoal_) {
|
||||
s+= "GOAL VALUES:\n";
|
||||
// for (std::map<unsigned int, Value*>::const_iterator i = goalValues.begin(); i!= goalValues.end(); ++i) {
|
||||
for (auto &i:goalValues) {
|
||||
s+= i.first->toString() + " = " + i.second->toString()+"\n";
|
||||
}
|
||||
}
|
||||
if (hasEvents_) {
|
||||
s+="EVENTS:\n";
|
||||
for (auto& mev:testCase) {
|
||||
s+=" { ";
|
||||
for (auto &e : *mev) {
|
||||
s+= e->toString();
|
||||
}
|
||||
s+= " }\n";
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<MetaEvent*> * AltaricaJson::matchMEV(std::vector<Event*> *mev, std::vector<MetaEvent*>* allmev) {
|
||||
std::vector<MetaEvent*> * matched = new std::vector<MetaEvent*>();
|
||||
for (auto& mevx:*allmev) {
|
||||
bool ok = true;
|
||||
for (auto& ev:*mev) {
|
||||
if (!mevx->containsE(ev)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
matched->push_back(mevx);
|
||||
}
|
||||
return matched;
|
||||
|
||||
}
|
||||
|
||||
std::vector<MetaEvent*> * AltaricaJson::selectSmaller(std::vector<MetaEvent*> *set) {
|
||||
std::vector<MetaEvent*> * smallestMEVs = new std::vector<MetaEvent*>();
|
||||
unsigned int smaller = std::numeric_limits<unsigned int>::max();
|
||||
for (auto mev: *set) {
|
||||
if (smaller > mev->size())
|
||||
smaller = mev->size();
|
||||
}
|
||||
for (auto mev:*set) {
|
||||
if (mev->size() == smaller)
|
||||
smallestMEVs->push_back(mev);
|
||||
}
|
||||
delete set;
|
||||
return smallestMEVs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AltaricaJson::runTestCase(AltaricaState *cstate, bool printFlow, bool printNULL, bool printDomain) {
|
||||
|
||||
for (auto& mev: testCase) {
|
||||
std::vector<MetaEvent*> * allmev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
std::vector<MetaEvent*> * matched = matchMEV(mev, allmev);
|
||||
matched = selectSmaller(matched);
|
||||
if (matched->size() != 1) {
|
||||
std::cerr << "cannot find corresponding MEV\n";
|
||||
std::cerr << "required: {";
|
||||
for (auto& ev:*mev)
|
||||
std::cerr << ev->toString() << " ";
|
||||
std::cerr << "}\n";
|
||||
std::cerr << "possible: \n";
|
||||
for (auto& mev: *allmev)
|
||||
std::cerr << mev->toString();
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
|
||||
std::cout << "Executing MEV: "<< (*matched)[0]->toString() << std::endl;
|
||||
std::cout << "state reached:" << std::endl;
|
||||
cstate = amodel->getNextState(cstate, (*matched)[0]);
|
||||
if (printFlow)
|
||||
amodel->evaluateFlowVars(cstate);
|
||||
std::cout << cstate->toString(true,printFlow,printNULL,printDomain);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasGoal_) {
|
||||
|
||||
std::cout << "GOAL VALUES:\n";
|
||||
for (auto &i:goalValues) {
|
||||
std::cout << i.first->toString() << " = " << i.second->toString() << std::endl;
|
||||
}
|
||||
std::cout << cstate->toString(true, printFlow, printNULL, printDomain);
|
||||
|
||||
for (auto& gv:goalValues) {
|
||||
Value * reachedValue = cstate->getValue(gv.first);
|
||||
if (!reachedValue->contains(gv.second)) {
|
||||
std::cout << "TESTCASE FAILED for variable " << gv.first->toString();
|
||||
std::cout << "\n required value: " << gv.second->toString();
|
||||
std::cout << "\n reached value : " << reachedValue->toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// return true;
|
||||
}
|
||||
|
||||
if (hasActive_) {
|
||||
std::vector<MetaEvent*> * allmev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
for (auto& mev: activeEvents) {
|
||||
std::vector<MetaEvent*> * matched = matchMEV(mev, allmev);
|
||||
matched = selectSmaller(matched);
|
||||
if (matched->size() == 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasInactive_) {
|
||||
std::vector<MetaEvent*> * allmev = amodel->getEnabledMetaEventsAll(cstate);
|
||||
for (auto& mev: activeEvents) {
|
||||
std::vector<MetaEvent*> * matched = matchMEV(mev, allmev);
|
||||
matched = selectSmaller(matched);
|
||||
if (matched->size() != 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
79
src/grammars/altarica/AltaricaJson.hh
Normal file
79
src/grammars/altarica/AltaricaJson.hh
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_JSON_HH
|
||||
#define ALTARICA_JSON_HH
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "AltaricaInitInfo.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Value;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
class AltaricaState;
|
||||
class MetaEvent;
|
||||
class Event;
|
||||
|
||||
|
||||
class AltaricaJson : public AltaricaInitInfo {
|
||||
private:
|
||||
std::vector<std::vector<Event *>*> testCase;
|
||||
std::vector<std::vector<Event *>*> activeEvents;
|
||||
std::vector<std::vector<Event *>*> inactiveEvents;
|
||||
std::map<Variable*, Value*> goalValues;
|
||||
void parseJsonFile(std::string jsonFile);
|
||||
bool hasInit_;
|
||||
bool hasGoal_;
|
||||
bool hasEvents_;
|
||||
bool hasActive_;
|
||||
bool hasInactive_;
|
||||
|
||||
bool verbose;
|
||||
|
||||
std::vector<MetaEvent*> * matchMEV(std::vector<Event*> *mev, std::vector<MetaEvent*>* allmev);
|
||||
std::vector<MetaEvent*> * selectSmaller(std::vector<MetaEvent*> *set);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
AltaricaJson(std::string jsonFile, AltaricaModel *am);
|
||||
virtual bool hasInit() {return hasInit_;}
|
||||
virtual bool hasGoal() {return hasGoal_;}
|
||||
virtual bool hasEvents() {return hasEvents_;}
|
||||
virtual std::string toString() const;
|
||||
bool runTestCase(AltaricaState *curState, bool printFlow =false, bool printNULL =false, bool printDomain = false);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
1369
src/grammars/altarica/AltaricaModel.cc
Normal file
1369
src/grammars/altarica/AltaricaModel.cc
Normal file
File diff suppressed because it is too large
Load Diff
353
src/grammars/altarica/AltaricaModel.hh
Normal file
353
src/grammars/altarica/AltaricaModel.hh
Normal file
@@ -0,0 +1,353 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_MODEL_HH
|
||||
#define ALTARICA_MODEL_HH
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
#ifndef NDEBUG_SEMANTICS
|
||||
#define DEBUG_SEMANTICS
|
||||
#endif
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class Variable;
|
||||
class Node;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Constant;
|
||||
class Domain;
|
||||
class Event;
|
||||
class Synchronisation;
|
||||
class Value;
|
||||
class AltaricaInitInfo;
|
||||
class AltaricaInitInfoXML;
|
||||
class AltaricaJson;
|
||||
class MetaEvent;
|
||||
class Assertion;
|
||||
|
||||
//! The whole model itself, including functions to simulate it
|
||||
/*! AltaricaModel contains all information needed to simulate an AltaricaModel
|
||||
and functions to generate (meta) events at a given state, then following states
|
||||
*/
|
||||
class AltaricaModel {
|
||||
|
||||
private:
|
||||
bool hasDirac_;
|
||||
bool discrete_;
|
||||
|
||||
void (*probaComputer)(std::vector<MetaEvent*>* mev, bool mayHaveDirac, AltaricaModel *am, AltaricaState *as);
|
||||
std::vector<MetaEvent*> * (*metaEventOrderer)(std::vector<MetaEvent*> *mev);
|
||||
std::vector<MetaEvent*> * (AltaricaModel::*getEnabledMetaEventsMostPrioOnlyFunctor)(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * (AltaricaModel::*getEnabledMetaEventsAllFunctor)(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * (AltaricaModel::*getEnabledMetaEventsDiracFunctor)(AltaricaState *state);
|
||||
|
||||
std::string varStringCache;
|
||||
Variable * varCache;
|
||||
|
||||
AltaricaInitInfo * initInfo;
|
||||
|
||||
//! is the model ready to use?
|
||||
bool finalized_;
|
||||
|
||||
//! constants of the .alt file
|
||||
std::vector<epoch::altarica::Constant*> constants;
|
||||
|
||||
//! declared domains
|
||||
/*! declared domains of the .alt file
|
||||
does not contain anonymous domains !!!!
|
||||
(of the type flow A:[1,10];)
|
||||
*/
|
||||
std::vector<epoch::altarica::Domain*> domains;
|
||||
//! all declared nodes
|
||||
/*! declared nodes. each nodes contains a full living copy of its subnodes;
|
||||
so the model of the system is containdes in "main" node only, other
|
||||
are used for cloning during model building phase
|
||||
*/
|
||||
std::vector<epoch::altarica::Node*> nodes;
|
||||
|
||||
//! all state variables
|
||||
std::vector<epoch::altarica::Variable*> stateVars;
|
||||
|
||||
//! all different flow variables
|
||||
/*! all _different_ flow vars: if flow vars (in the sense of altarica
|
||||
have always the same value, only one flowvar appears in the list
|
||||
*/
|
||||
std::vector<epoch::altarica::Variable*> flowVars;
|
||||
|
||||
//! all atomic events
|
||||
/*! atomic events inside main node and subnodes */
|
||||
std::vector<epoch::altarica::Event*> atomicEvents;
|
||||
|
||||
std::vector<epoch::altarica::Event*> atomicDiracEvents;
|
||||
|
||||
//! all synchronisations
|
||||
/*! synchronisations inside main node and subnodes */
|
||||
std::vector<epoch::altarica::Synchronisation*> syncs;
|
||||
|
||||
//! all metaEvents
|
||||
/*! metaevents, used only if !onTheFly */
|
||||
std::vector<epoch::altarica::MetaEvent*> * metaEvents_;
|
||||
|
||||
//! all metaEvents, sorted by priority
|
||||
/*! all metaevents, sorted, used only if !onTheFly */
|
||||
std::vector<std::vector<epoch::altarica::MetaEvent*> *> *metaEventsByPrio_;
|
||||
|
||||
//! list of all asserts: unused
|
||||
std::list<epoch::altarica::Assertion*> * asserts_;
|
||||
|
||||
//! the main node (default: "main")
|
||||
epoch::altarica::Node * mainNode_;
|
||||
|
||||
//! helper to build global var list
|
||||
void addVars(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global event list
|
||||
void addEvents(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global sync list
|
||||
void addSyncs(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global assert list
|
||||
void addAsserts(epoch::altarica::Node* n);
|
||||
|
||||
//! helper to build global lists
|
||||
void addGlobalDataRec(epoch::altarica::Node *n);
|
||||
|
||||
//! fusion/elimination of simple affectations
|
||||
void compactSimpleAssertsRec(epoch::altarica::Node *n);
|
||||
|
||||
//! compute metaevents
|
||||
/*! compute all metaevents
|
||||
if no state (NULL) no checking of preconditions -> use only with !onTheFly
|
||||
*/
|
||||
std::vector<epoch::altarica::MetaEvent*> * computeMetaEventsNoDirac(epoch::altarica::AltaricaState *s);
|
||||
std::vector<epoch::altarica::MetaEvent*> * computeDiracMetaEvents();
|
||||
|
||||
//! sub function of computeMetaEvents
|
||||
std::vector<epoch::altarica::MetaEvent*> * findAndRemoveMetas(epoch::altarica::Event*e, std::vector<epoch::altarica::MetaEvent*> * metas);
|
||||
|
||||
//! prioritize metaEvents as given by computeMetaEvents
|
||||
std::vector<std::vector<epoch::altarica::MetaEvent*> *> * buildPrioritizedMetaEvents(std::vector<epoch::altarica::MetaEvent*> *);
|
||||
|
||||
//! helper for buildPrioritizedMetaEvents
|
||||
std::vector<std::vector<epoch::altarica::MetaEvent*>*>* splitPrioClass(std::vector<epoch::altarica::MetaEvent*>* prioClass);
|
||||
|
||||
//! helper for buildPrioritizedMetaEvents
|
||||
epoch::altarica::MetaEvent* popMorePrio(std::vector<epoch::altarica::MetaEvent*> * prioClass);
|
||||
|
||||
//! helper for buildPrioritizedMetaEvents
|
||||
epoch::altarica::MetaEvent* popSamePrio(std::vector<epoch::altarica::MetaEvent*> *prioClass, epoch::altarica::MetaEvent* p);
|
||||
|
||||
static void computeDiscreteProbas(std::vector<MetaEvent*>* mev, bool mayHaveDirac, AltaricaModel *am, AltaricaState *as);
|
||||
static void giveContinuousProbas(std::vector<MetaEvent*>* mev, bool mayHaveDirac, AltaricaModel *am, AltaricaState *as);
|
||||
static std::vector<MetaEvent*>* orderMetaEventMostProbableFirst(std::vector<MetaEvent*>* mev);
|
||||
static std::vector<MetaEvent*>* orderMetaEventLessProbableFirst(std::vector<MetaEvent*>* mev);
|
||||
static std::vector<MetaEvent*>* orderMetaEventNOOP(std::vector<MetaEvent*>* mev);
|
||||
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsMostPrioOnlyOnTheFly(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsMostPrioOnlyOffLine(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsAllOnTheFly(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsAllOffLine(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsDiracOnTheFly(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsDiracOffLine(AltaricaState *state);
|
||||
|
||||
static void purgeMetaEvents(std::vector<MetaEvent*>*);
|
||||
|
||||
|
||||
static bool noProba(std::vector<MetaEvent*>* mev);
|
||||
static bool noProba(MetaEvent* mev);
|
||||
static bool hasDirac(std::vector<MetaEvent*> * mev);
|
||||
// static bool dirac(MetaEvent* mev);
|
||||
static bool discrete(std::vector<MetaEvent*>* mev);
|
||||
bool diracEnabled(AltaricaState*s);
|
||||
std::vector<MetaEvent*> * computeDiracMetaEvents(AltaricaState *state);
|
||||
std::vector<MetaEvent*> * getEnabledMetaEventsDirac(AltaricaState *state);
|
||||
AltaricaState * forwardDirac(AltaricaState *s, std::vector<const Variable*>* = NULL);
|
||||
|
||||
|
||||
bool isInAssigned(Variable* v, std::vector<std::vector<const Variable*>* >& assigned);
|
||||
bool isInAlreadyAssignedInDirac(const Variable* v, std::vector<const Variable*>* assigned);
|
||||
bool isInAlreadyAssignedInDirac(std::vector<const Variable*> *vv, std::vector<const Variable*>* assigned);
|
||||
static bool debugSemantics;
|
||||
|
||||
public:
|
||||
|
||||
//! simple constructor
|
||||
AltaricaModel(bool continuous = false);
|
||||
//! complex constructor :)
|
||||
~AltaricaModel();
|
||||
|
||||
void setInitInfo(std::string initFile);
|
||||
|
||||
AltaricaInitInfo * getInitInfo() const {return initInfo;}
|
||||
|
||||
// Functors changes
|
||||
|
||||
void giveMostProbableTransitionFirst() { metaEventOrderer = &AltaricaModel::orderMetaEventMostProbableFirst;}
|
||||
void giveLessProbableTransitionFirst() {metaEventOrderer = &AltaricaModel::orderMetaEventLessProbableFirst;}
|
||||
void setContinuous() {probaComputer = &AltaricaModel::giveContinuousProbas; discrete_ = false;}
|
||||
void setDiscrete() {probaComputer = &AltaricaModel::computeDiscreteProbas; discrete_ = true;}
|
||||
|
||||
bool discrete() {return discrete_;}
|
||||
|
||||
//! setter for the parser
|
||||
void addConstant(epoch::altarica::Constant* c);
|
||||
|
||||
//! setter for the parser
|
||||
void addDomain(epoch::altarica::Domain* d);
|
||||
|
||||
//! setter for the parser
|
||||
void addNode(epoch::altarica::Node* n);
|
||||
|
||||
//! after parsing, finlizing the model is mandatory
|
||||
void finalize(std::string mainNodeName = "main", bool onTheFlyMeta = true);
|
||||
void finalizeRec(epoch::altarica::Node *n);
|
||||
|
||||
static void setDebugSemantics(bool d) { AltaricaModel::debugSemantics = d;}
|
||||
static bool getDebugSemantics() { return AltaricaModel::debugSemantics; }
|
||||
//! find a node in the node list
|
||||
/*! mainly used for parsing */
|
||||
epoch::altarica::Node * findNodeByName(const std::string& s);
|
||||
const epoch::altarica::Node * findNodeByFullName(const std::string& s) const;
|
||||
epoch::altarica::Node* findNodeByFullName(const std::string& s) {
|
||||
return const_cast<Node*>(
|
||||
const_cast<const AltaricaModel*>(this)
|
||||
->findNodeByFullName(s));
|
||||
}
|
||||
std::vector<epoch::altarica::Node*> * findNodesByType(const std::string& s);
|
||||
//! find a constant in the constant list
|
||||
/*! used only by parsing */
|
||||
epoch::altarica::Constant * findConstantByName(const std::string& s) const;
|
||||
//! find a domain in the domain list
|
||||
/*! used only by parsing */
|
||||
epoch::altarica::Domain * findDomainByName(const std::string& s);
|
||||
|
||||
const epoch::altarica::Node * getMainNode() const {return mainNode_;}
|
||||
|
||||
//! build initial state
|
||||
/*! as stated by init declarations of the .alt file*/
|
||||
epoch::altarica::AltaricaState * initialState();
|
||||
|
||||
//! Orders the assertions in dataflow
|
||||
void orders_assertions();
|
||||
|
||||
//! give possible metaEvents for a given state of higher priority (useless for probabilistic MC)
|
||||
std::vector<epoch::altarica::MetaEvent*> * getEnabledMetaEventsMostPrioOnly(epoch::altarica::AltaricaState *s);
|
||||
|
||||
//! give possible metaEvents for a given state
|
||||
std::vector<epoch::altarica::MetaEvent*> * getEnabledMetaEventsAll(epoch::altarica::AltaricaState *s);
|
||||
|
||||
//! generate a new state from a state and a metaevent
|
||||
/*! if metaEvent is not enabled (does not come from getEnabledMetaEvents) -> trouble ahead */
|
||||
// void getNextState(epoch::altarica::AltaricaState *s, epoch::altarica::MetaEvent* me,
|
||||
// epoch::altarica::AltaricaState *ns);
|
||||
//! get next state, + allocation of a new state
|
||||
|
||||
epoch::altarica::AltaricaState * getNextState(epoch::altarica::AltaricaState *s, epoch::altarica::MetaEvent* me);
|
||||
// std::vector<epoch::altarica::AltaricaState*> *getNextStatesFull(epoch::altarica::AltaricaState *s);
|
||||
// std::vector<epoch::altarica::AltaricaState*> *getNextStatesPartial(epoch::altarica::AltaricaState *s);
|
||||
|
||||
//! helper for dealing with labri-style priorities in syncs
|
||||
static bool hasEventDAG(std::vector<epoch::altarica::MetaEvent*>* prioClass);
|
||||
|
||||
//! print all flow variables and values at a given state
|
||||
void evaluateFlowVars(epoch::altarica::AltaricaState *s) const;
|
||||
|
||||
//! evalute a flow var
|
||||
Value * getFlowVarValueAndRelease(AltaricaState *s, std::string n);
|
||||
//! reads a state var
|
||||
Value * getStateVarValue(AltaricaState *s, std::string n);
|
||||
//! gives a var value
|
||||
Value * getVarValueAndRelease(AltaricaState *s, std::string n);
|
||||
|
||||
unsigned int getNFlowVars() const {return flowVars.size();}
|
||||
unsigned int getNStateVars() const {return stateVars.size();}
|
||||
unsigned int getNNodes() const {return nodes.size();}
|
||||
unsigned int getNEvents() const {return atomicEvents.size();}
|
||||
|
||||
Variable* getStateVar(unsigned int i) const;
|
||||
Variable* getFlowVar(unsigned int i) const;
|
||||
|
||||
bool existsVar(std::string n);
|
||||
|
||||
void setInitInfoXML(std::string initFile);
|
||||
AltaricaJson * setInitInfoJSON(std::string initFile);
|
||||
|
||||
|
||||
const std::vector<epoch::altarica::Event*>& getAtomicDiracEvents() const {
|
||||
return atomicDiracEvents;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Event*>& getAtomicEvents() const {
|
||||
return atomicEvents;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Constant*>& getConstants() const {
|
||||
return constants;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::MetaEvent*>& getMetaEvents() const {
|
||||
return *metaEvents_;
|
||||
}
|
||||
|
||||
std::list<epoch::altarica::Assertion*>& getAsserts() const {
|
||||
return *asserts_;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Domain*>& getDomains() const {
|
||||
return domains;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Variable*>& getFlowVars() const {
|
||||
return flowVars;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Node*>& getNodes() const {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Variable*>& getStateVars() const {
|
||||
return stateVars;
|
||||
}
|
||||
|
||||
const std::vector<epoch::altarica::Synchronisation*>& getSyncs() const {
|
||||
return syncs;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
409
src/grammars/altarica/AltaricaState.cc
Normal file
409
src/grammars/altarica/AltaricaState.cc
Normal file
@@ -0,0 +1,409 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "AltaricaState.hh"
|
||||
#include "Assignment.hh"
|
||||
#include <sstream>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include "AltaricaModel.hh"
|
||||
#include <iostream>
|
||||
#include "Values.hh"
|
||||
#include "Variable.hh"
|
||||
#include "AltaricaInitInfo.hh"
|
||||
#include <cassert>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
AltaricaState::AltaricaState(bool initial, const AltaricaModel *amodel, AltaricaInitInfo *initInfo) : amodel_(amodel), cache(NULL) {
|
||||
unsigned int ns = amodel_->getNStateVars();
|
||||
unsigned int nf = amodel_->getNFlowVars();
|
||||
stateVars_.resize(ns,NULL);
|
||||
flowVars_.resize(nf,NULL);
|
||||
|
||||
if (initial) {
|
||||
for (unsigned int i = 0; i<ns; ++i) {
|
||||
Value * v = NULL;
|
||||
// if we have something to init in initFile, take value here
|
||||
Value *iv = NULL;
|
||||
if (initInfo != NULL)
|
||||
iv = initInfo->getInitValue(i);
|
||||
if (iv != NULL) {
|
||||
v = iv;
|
||||
} else {
|
||||
const Assignment * init = amodel_->getStateVar(i)->getInit();
|
||||
if (init != NULL) {
|
||||
v = amodel_->getStateVar(i)->getInit()->evaluate(amodel, this, amodel_->getStateVar(i)->getNode());
|
||||
}
|
||||
}
|
||||
if (v == NULL) {
|
||||
std::string b = "cannot init variable: " + amodel_->getStateVar(i)->toString();
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(b));
|
||||
exit(-1);
|
||||
}
|
||||
if (v->isSymbol()) {
|
||||
EnumDomain * d = (EnumDomain*) amodel_->getStateVar(i)->getDomain();
|
||||
ValueSymbol* vs = (ValueSymbol*) v;
|
||||
if (!d->contains(vs->toSymbol()))
|
||||
{
|
||||
std::string s = "unknown value: ";
|
||||
s+= vs->toSymbol();
|
||||
s+= " for variable " ;
|
||||
s+= amodel_->getStateVar(i)->toString();
|
||||
s+= " should be in ";
|
||||
s+= amodel_->getStateVar(i)->getDomain()->toString();
|
||||
throw AltaricaException(s, "AltaricaState constructor of initial state");
|
||||
}
|
||||
|
||||
vs->setDomain((EnumDomain*)amodel_->getStateVar(i)->getDomain());
|
||||
}
|
||||
stateVars_[i] = v;
|
||||
v->own();
|
||||
}
|
||||
rehash_();
|
||||
}
|
||||
}
|
||||
|
||||
AltaricaState::AltaricaState(const std::vector<Value*> &mstate, const AltaricaModel *amodel) {
|
||||
amodel_ = amodel;
|
||||
cache = NULL;
|
||||
stateVars_.assign(mstate.begin(),mstate.end());
|
||||
for (unsigned int i = 0; i< stateVars_.size(); ++i)
|
||||
if (stateVars_[i] != NULL)
|
||||
stateVars_[i]->own();
|
||||
flowVars_.resize(amodel_->getNFlowVars(),NULL);
|
||||
}
|
||||
|
||||
void AltaricaState::addValue(const Variable* var, Value*v) {
|
||||
if (var->isState())
|
||||
addStateValue(var->getIndex(), v);
|
||||
else
|
||||
addFlowValue(var->getIndex(), v);
|
||||
}
|
||||
|
||||
bool AltaricaState::isEmpty() const {
|
||||
for (unsigned int i=0; i< stateVars_.size(); ++i)
|
||||
if (stateVars_[i] != NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::setValue(const Variable*var, Value *val) {
|
||||
|
||||
if (var->isState()) {
|
||||
if (val->isSymbol()) {
|
||||
ValueSymbol* vs = (ValueSymbol*) val;
|
||||
vs->setDomain((EnumDomain*)var->getDomain());
|
||||
}
|
||||
setStateValue(var->getIndex(),val);
|
||||
} else
|
||||
setFlowValue(var->getIndex(),val);
|
||||
}
|
||||
|
||||
void AltaricaState::addStateValue(unsigned int i, Value*val) {
|
||||
if (val == NULL)
|
||||
return;
|
||||
if (stateVars_[i] == NULL) {
|
||||
stateVars_[i] = val;
|
||||
} else {
|
||||
if (stateVars_[i]->ro())
|
||||
stateVars_[i] = stateVars_[i]->clone();
|
||||
stateVars_[i]->merge(val);
|
||||
}
|
||||
stateVars_[i]->own();
|
||||
Value::deleteIfPossible(val);
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::setStateValue(unsigned int i, Value*val) {
|
||||
if (val == NULL)
|
||||
return;
|
||||
Value::release(stateVars_[i]);
|
||||
val->own();
|
||||
stateVars_[i] = val;
|
||||
}
|
||||
|
||||
void AltaricaState::addFlowValue(unsigned int i, Value*val) {
|
||||
if (val == NULL)
|
||||
return;
|
||||
if (flowVars_[i] == NULL) {
|
||||
flowVars_[i] = val;
|
||||
} else {
|
||||
if (flowVars_[i]->ro())
|
||||
flowVars_[i] = flowVars_[i]->clone();
|
||||
flowVars_[i]->merge(val);
|
||||
}
|
||||
flowVars_[i]->own();
|
||||
Value::deleteIfPossible(val);
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::setFlowValue(unsigned int i, Value*val) {
|
||||
if (val != NULL)
|
||||
val->own();
|
||||
Value::release(flowVars_[i]);
|
||||
flowVars_[i] = val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Value * AltaricaState::getValue(const Variable *v) const{
|
||||
// if (hasValue(v))
|
||||
// return (*vars_)[v];
|
||||
// else
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
|
||||
bool AltaricaState::hasStateValue(unsigned int i ) const {
|
||||
if (stateVars_[i] == NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AltaricaState::hasValue(const Variable * v) const {
|
||||
if (v->isState()) {
|
||||
if (stateVars_[v->getIndex()] == NULL)
|
||||
return false;
|
||||
return true;
|
||||
} else {
|
||||
if (flowVars_[v->getIndex()] == NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Value * AltaricaState::getValue(const Variable *v) const {
|
||||
if (v->isState()) {
|
||||
return stateVars_[v->getIndex()];
|
||||
} else {
|
||||
return flowVars_[v->getIndex()];
|
||||
}
|
||||
}
|
||||
|
||||
Value * AltaricaState::getStateValue(unsigned int i) const {
|
||||
return stateVars_[i];
|
||||
}
|
||||
|
||||
Value * AltaricaState::getFlowValue(unsigned int i) const {
|
||||
return flowVars_[i];
|
||||
}
|
||||
|
||||
void AltaricaState::removeValue(const Variable *v) {
|
||||
if (v->isState()) {
|
||||
Value * vv = stateVars_[v->getIndex()];
|
||||
Value::release(vv);
|
||||
stateVars_[v->getIndex()] = NULL;
|
||||
} else {
|
||||
Value * vv = flowVars_[v->getIndex()];
|
||||
if (vv != NULL)
|
||||
Value::release(vv);
|
||||
flowVars_[v->getIndex()] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaState::releaseFlowVars() const {
|
||||
for (unsigned int i = 0; i<flowVars_.size(); ++i) {
|
||||
Value::release(flowVars_[i]);
|
||||
flowVars_[i]= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AltaricaState::deleteFlowValues() {
|
||||
for (unsigned int i = 0; i<flowVars_.size(); ++i) {
|
||||
Value::release(flowVars_[i]);
|
||||
flowVars_[i]= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AltaricaState::mergeToState(AltaricaState*s) const {
|
||||
unsigned int i = 0;
|
||||
for (std::vector<Value*>::const_iterator vi = stateVars_.begin(); vi!= stateVars_.end(); ++vi)
|
||||
s->addStateValue(i++, *vi);
|
||||
i = 0;
|
||||
for (std::vector<Value*>::const_iterator vi = flowVars_.begin(); vi!= flowVars_.end(); ++vi)
|
||||
s->addFlowValue(i++, *vi);
|
||||
}
|
||||
|
||||
void AltaricaState::intersectState(const AltaricaState *s) {
|
||||
if (s == NULL)
|
||||
return;
|
||||
for (unsigned int i = 0; i< amodel_->getNStateVars(); ++i)
|
||||
removeValue(i, s->getStateValue(i));
|
||||
}
|
||||
|
||||
void AltaricaState::mergeIntersectState (const AltaricaState *s) {
|
||||
if (s == NULL)
|
||||
return;
|
||||
for (unsigned int i = 0; i< amodel_->getNStateVars(); ++i) {
|
||||
if (hasStateValue(i)) {
|
||||
if (s->hasStateValue(i))
|
||||
getStateValue(i)->intersectValue(s->getStateValue(i));
|
||||
} else {
|
||||
setStateValue(i, s->getStateValue(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AltaricaState::removeValue(const Variable *v, const Value*vv) {
|
||||
removeValue(v->getIndex(), vv);
|
||||
}
|
||||
|
||||
void AltaricaState::removeValue(unsigned int i, const Value*vv) {
|
||||
Value *v = stateVars_[i];
|
||||
if (v != NULL) {
|
||||
if (v->ro())
|
||||
v = v->clone();
|
||||
v->removeValue(vv);
|
||||
if (v->card() == 0) {
|
||||
Value::deleteIfPossible(v);
|
||||
v = NULL;
|
||||
} else
|
||||
v->own();
|
||||
stateVars_[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AltaricaState::~AltaricaState() {
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
Value::release(*i);
|
||||
}
|
||||
releaseFlowVars();
|
||||
Value::release(cache);
|
||||
}
|
||||
|
||||
AltaricaState * AltaricaState::clone() const {
|
||||
AltaricaState * n = new AltaricaState(stateVars_,amodel_);
|
||||
n->setHash(hash_);
|
||||
return n;
|
||||
|
||||
}
|
||||
|
||||
// AltaricaState * AltaricaState::getMacroState() const {
|
||||
// AltaricaState *n = new AltaricaState((*stateVars_),amodel_,true);
|
||||
// n->rehash_();
|
||||
// return n;
|
||||
// }
|
||||
|
||||
// unsigned int AltaricaState::size() {
|
||||
// return vars_->size();
|
||||
// }
|
||||
|
||||
void AltaricaState::setHash(size_t h) {
|
||||
hash_ = h;
|
||||
}
|
||||
|
||||
bool AltaricaState::equals(AltaricaState *s) {
|
||||
// if (this == s)
|
||||
// return true;
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
if ( ((*i) != s->getStateValue(j)) && !(*i)->equals(s->getStateValue(j)) )
|
||||
return false;
|
||||
++j;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string AltaricaState::toString(bool state, bool flow, bool printNULL, bool printDomain) {
|
||||
std::stringstream ss;
|
||||
// std::string s;
|
||||
if (state) {
|
||||
if (flow)
|
||||
ss << "STATE VARS:"<<std::endl;
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
if (printNULL ||(*i) != NULL ) {
|
||||
Variable * v = amodel_->getStateVar(j);
|
||||
ss << v->toString();
|
||||
if ((*i) != NULL) {
|
||||
ss << " : " << (*i)->toString();// << "(" << *i << ")" ;
|
||||
if (printDomain)
|
||||
ss << " in " << v->getDomain()->toString();
|
||||
ss <<";" ;
|
||||
} else
|
||||
ss<< " : NULL;";
|
||||
ss<< std::endl;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (flow) {
|
||||
if (state)
|
||||
ss<< "FLOW VARS:\n";
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::iterator i = flowVars_.begin(); i!= flowVars_.end(); ++i) {
|
||||
Variable *v = amodel_->getFlowVar(j++);
|
||||
ss << v->toString();
|
||||
if ((*i) != NULL)
|
||||
ss<< " : " << (*i)->toString() << " in " << v->getDomain()->toString() <<";" ;
|
||||
ss<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
void AltaricaState::rehash_() {
|
||||
hash_ = 0;
|
||||
boost::hash<int> int_hash;
|
||||
for (std::vector<Value*>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
int h = (*i)->toHash();
|
||||
boost::hash_combine(hash_, int_hash(h));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::size_t AltaricaState::hash() {
|
||||
return hash_;
|
||||
}
|
||||
|
||||
bool AltaricaState::operator<(const AltaricaState&o) const {
|
||||
unsigned int j = 0;
|
||||
for (std::vector<Value*>::const_iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
Value* ov = o.getStateValue(j++);
|
||||
|
||||
if ((*i)->less(ov))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
109
src/grammars/altarica/AltaricaState.hh
Normal file
109
src/grammars/altarica/AltaricaState.hh
Normal file
@@ -0,0 +1,109 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_STATE_HH
|
||||
#define ALTARICA_STATE_HH
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class Variable;
|
||||
class Value;
|
||||
class AltaricaInitInfo;
|
||||
|
||||
class AltaricaState {
|
||||
|
||||
private:
|
||||
std::vector<Value*> stateVars_;
|
||||
mutable std::vector<Value*> flowVars_;
|
||||
const AltaricaModel * amodel_;
|
||||
std::size_t hash_;
|
||||
// bool macro_;
|
||||
|
||||
Value *cache;
|
||||
public:
|
||||
// AltaricaState(const AltaricaModel* amodel);
|
||||
AltaricaState(bool initial, const AltaricaModel* amodel, AltaricaInitInfo *initInfo);
|
||||
AltaricaState(const std::vector<Value*> &mstate, const AltaricaModel* amodel);
|
||||
|
||||
// bool isMacro() {return macro_;}
|
||||
|
||||
void setValue(const Variable* var, Value*v);
|
||||
void setStateValue(unsigned int i, Value*val);
|
||||
void setFlowValue(unsigned int i, Value*val);
|
||||
|
||||
// macro state specifics
|
||||
void addValue(const Variable* var, Value*v);
|
||||
void addStateValue(unsigned int i, Value*val);
|
||||
void addFlowValue(unsigned int i, Value*val);
|
||||
|
||||
Value * getValue(const Variable *v) const;
|
||||
Value * getStateValue(unsigned int i) const;
|
||||
Value * getFlowValue(unsigned int i) const;
|
||||
|
||||
void mergeToState(AltaricaState *s) const;
|
||||
void intersectState(const AltaricaState *s);
|
||||
void mergeIntersectState(const AltaricaState *s);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
~AltaricaState();
|
||||
AltaricaState *clone()const;
|
||||
// AltaricaState * getMacroState() const;
|
||||
|
||||
bool equals(AltaricaState*s);
|
||||
// unsigned int size();
|
||||
bool hasValue( const Variable * v) const;
|
||||
bool hasStateValue(unsigned int i) const;
|
||||
std::string toString(bool printStateVar, bool printFlowVar, bool printNULL = true, bool printDomain = true);
|
||||
void removeValue(const Variable *v);
|
||||
void removeValue(const Variable *v, const Value*vv);
|
||||
void removeValue(unsigned int i, const Value*vv);
|
||||
|
||||
std::size_t hash();
|
||||
bool operator<(const AltaricaState&o) const;
|
||||
|
||||
void rehash_();
|
||||
void setHash(size_t h);
|
||||
|
||||
inline const AltaricaModel * getAModel() const {return amodel_;}
|
||||
void releaseFlowVars() const;
|
||||
void deleteFlowValues() ;
|
||||
|
||||
Value * getCachedValue() {return cache;}
|
||||
void setCachedValue(Value *vv) {cache = vv;}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
77
src/grammars/altarica/Assertion.cc
Normal file
77
src/grammars/altarica/Assertion.cc
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Assertion.hh"
|
||||
#include "Node.hh"
|
||||
#include <limits.h>
|
||||
#include "expressions/ExpressionLOG.hh"
|
||||
#include "Values.hh"
|
||||
#include "Variable.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
std::vector<Variable*> * Assertion::infoVars(const AltaricaModel* am, bool flow, bool computed) const {
|
||||
return assert_->infoVars(am, n_, flow, computed);
|
||||
}
|
||||
|
||||
void Assertion::evaluate(const AltaricaModel* am, AltaricaState *s) const {
|
||||
Value * v = assert_->evaluate(am, s, n_,true);
|
||||
Value::deleteIfPossible(v);
|
||||
}
|
||||
|
||||
void Assertion::evaluateLM(const AltaricaModel*am, LandmarkState *lms) const {
|
||||
assert_->evaluateLM(am, lms, n_,true);
|
||||
}
|
||||
|
||||
void Assertion::addVariable(Variable* v) {
|
||||
if (variables_ == NULL)
|
||||
variables_ = new std::vector<Variable*>();
|
||||
// std::cerr << "Adding to assertion variable " << v->getFullName() << std::endl;
|
||||
variables_->push_back(v);
|
||||
}
|
||||
|
||||
const std::vector<Variable*> * Assertion::getVars() const {
|
||||
return variables_;
|
||||
}
|
||||
|
||||
Assertion::~Assertion() {
|
||||
delete variables_;
|
||||
}
|
||||
|
||||
|
||||
std::pair<Variable*,Variable*> * Assertion::isSimpleAffect(const AltaricaModel *am) {
|
||||
ExpressionLOG * el = dynamic_cast<ExpressionLOG*>(assert_);
|
||||
if (el == NULL)
|
||||
return NULL;
|
||||
return el->isSimpleAffect(am, n_);
|
||||
}
|
||||
|
||||
Assertion * Assertion::clone() const {
|
||||
return new Assertion(assert_);
|
||||
}
|
||||
77
src/grammars/altarica/Assertion.hh
Normal file
77
src/grammars/altarica/Assertion.hh
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ASSERT_H_
|
||||
#define ALTA_ASSERT_H_
|
||||
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "expressions/Expression.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Variable;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class LandmarkState;
|
||||
|
||||
class Assertion {
|
||||
protected:
|
||||
Expression * assert_;
|
||||
Node * n_;
|
||||
std::vector<Variable*>* variables_;
|
||||
public:
|
||||
Assertion(Expression * a): assert_(a), n_(NULL) {
|
||||
variables_ = NULL;
|
||||
}
|
||||
~Assertion();
|
||||
|
||||
std::vector<Variable*> * infoVars(const AltaricaModel *am, bool flow, bool computed) const;
|
||||
|
||||
void setNode(Node *n) {n_ = n;}
|
||||
const Node * getNode() {return n_;}
|
||||
const Expression * getExpr() const {return assert_;}
|
||||
void addVariable(Variable* a);
|
||||
const std::vector<Variable*> * getVars() const;
|
||||
|
||||
void evaluate(const AltaricaModel *am, AltaricaState *s) const;
|
||||
void evaluateLM(const AltaricaModel *am, LandmarkState *lms) const;
|
||||
|
||||
std::pair<Variable*,Variable*> * isSimpleAffect(const AltaricaModel*am);
|
||||
|
||||
Assertion * clone() const;
|
||||
|
||||
void deleteExpr() {delete assert_;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
80
src/grammars/altarica/Assignment.cc
Normal file
80
src/grammars/altarica/Assignment.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Assignment.hh"
|
||||
#include "Node.hh"
|
||||
#include <iostream>
|
||||
#include "expressions/Expression.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
// void Assignment::matchVariable(bool init) {
|
||||
// std::cerr << "matching variable " << *(ma_->toString());
|
||||
// std::cerr << " of node " << *(n_->getMA()->toString());
|
||||
// Variable *v = n_->findVariableByName(ma_);
|
||||
// if (init)
|
||||
// n_->findVariableByName(ma_)->setInit(this);
|
||||
// }
|
||||
|
||||
|
||||
Value * Assignment::evaluate(const AltaricaModel *am, AltaricaState * m, const Node *n) const {
|
||||
return e_->evaluate(am,m,n);
|
||||
}
|
||||
|
||||
Value * Assignment::evaluate(const AltaricaModel *am, AltaricaState * m) const {
|
||||
return e_->evaluate(am, m,n_);
|
||||
}
|
||||
|
||||
|
||||
void Assignment::setNode(Node*n) {
|
||||
n_ = n;
|
||||
// if (n_ != NULL)
|
||||
// matchVariable(false);
|
||||
if (n_ != NULL) {
|
||||
v_ = n_->findVariableByName(ma_);
|
||||
if (v_ == NULL) {
|
||||
std::cerr << "COULD NOT MATCH VARIABLE " << ma_->toString() << " in node " << n_->toString() <<
|
||||
" in assignment " << ma_->toString() << " := " << e_->toString() << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Assignment::deleteExprs() {
|
||||
delete e_;
|
||||
// delete oe_;
|
||||
}
|
||||
|
||||
Assignment::~Assignment() {
|
||||
delete ma_;
|
||||
}
|
||||
82
src/grammars/altarica/Assignment.hh
Normal file
82
src/grammars/altarica/Assignment.hh
Normal file
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ASSIGNMENT_H_
|
||||
#define ALTA_ASSIGNMENT_H_
|
||||
|
||||
#include "MemberAccess.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Variable;
|
||||
class Expression;
|
||||
class Value;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
|
||||
class Assignment {
|
||||
protected :
|
||||
//! liste des membres a affecter
|
||||
MemberAccess* ma_;
|
||||
|
||||
//! affectation à donner au membre correspondant
|
||||
Expression* e_;
|
||||
// Expression* oe_;
|
||||
|
||||
Node * n_;
|
||||
|
||||
Variable * v_;
|
||||
|
||||
public :
|
||||
Assignment(MemberAccess* m, Expression*e):ma_(m),e_(e),n_(NULL),v_(NULL) {
|
||||
// oe_ = e_->toOpenExpr();
|
||||
}
|
||||
~Assignment();
|
||||
|
||||
Assignment * clone() const {return new Assignment(ma_->clone(), e_);}
|
||||
|
||||
void setNode(Node*n);
|
||||
Node * getNode() {return n_;}
|
||||
|
||||
// void matchVariable(bool init);
|
||||
|
||||
const Variable* getVar() const {return v_;}
|
||||
const Expression * getExpr() const {return e_;}
|
||||
|
||||
Value * evaluate(const AltaricaModel *am, AltaricaState *m, const Node *n) const;
|
||||
Value * evaluate(const AltaricaModel *am, AltaricaState *m) const;
|
||||
|
||||
|
||||
void deleteExprs();
|
||||
|
||||
const MemberAccess * getMA() {return ma_;}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
99
src/grammars/altarica/CMakeLists.txt
Normal file
99
src/grammars/altarica/CMakeLists.txt
Normal file
@@ -0,0 +1,99 @@
|
||||
# This file is part of EPOCH.
|
||||
# File: CMakeLists.txt
|
||||
# Author: Florent Teichteil-Königsbuch
|
||||
# Contact: florent.teichteil@onera.fr
|
||||
#
|
||||
# EPOCH is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# EPOCH is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#FIND_PACKAGE(LibXML++ REQUIRED)
|
||||
#set(LIBS ${LIBS} ${LibXML++_LIBRARIES})
|
||||
|
||||
|
||||
BISON_TARGET (AltaricaParser altarica.yy ${CMAKE_CURRENT_BINARY_DIR}/altarica_parser.cc)
|
||||
FLEX_TARGET (AltaricaScanner altarica.l ${CMAKE_CURRENT_BINARY_DIR}/altarica_lexer.cc COMPILE_FLAGS --header-file=${CMAKE_CURRENT_BINARY_DIR}/altarica_lexer.h)
|
||||
ADD_FLEX_BISON_DEPENDENCY (AltaricaScanner AltaricaParser)
|
||||
|
||||
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
# ${LibXML++_INCLUDE_DIRS}
|
||||
)
|
||||
ADD_LIBRARY (epoch-altarica SHARED
|
||||
${BISON_AltaricaParser_OUTPUTS}
|
||||
${FLEX_AltaricaScanner_OUTPUTS}
|
||||
AltaricaGenerator.cc
|
||||
AltaricaState.cc
|
||||
AltaricaModel.cc
|
||||
AltaricaInitInfo.cc
|
||||
AltaricaException.cc
|
||||
# AltaricaInitInfoXML.cc
|
||||
AltaricaInitInfoXML2.cc
|
||||
AltaricaJson.cc
|
||||
AltaricaInteractive.cc
|
||||
MetaEvent.cc
|
||||
domains/RangeDomain.cc
|
||||
domains/Domain.cc
|
||||
domains/EnumDomain.cc
|
||||
domains/PredefinedDomain.cc
|
||||
domains/StructuredDomain.cc
|
||||
domains/ArrayDomain.cc
|
||||
domains/RealDomain.cc
|
||||
Parameter.cc
|
||||
Variable.cc
|
||||
Event.cc
|
||||
Assignment.cc
|
||||
EventLaw.cc
|
||||
Constant.cc
|
||||
MemberAccess.cc
|
||||
Transition.cc
|
||||
Synchronisation.cc
|
||||
Assertion.cc
|
||||
Node.cc
|
||||
values/Value.cc
|
||||
values/ValueBool.cc
|
||||
values/ValueInt.cc
|
||||
values/ValueSymbol.cc
|
||||
values/ValueReal.cc
|
||||
LandmarkState.cc
|
||||
LandmarkMetaEvent.cc
|
||||
LandmarkDriver.cc
|
||||
expressions/Expression.cc
|
||||
expressions/ExpressionADD.cc
|
||||
expressions/ExpressionAND.cc
|
||||
expressions/ExpressionARITH.cc
|
||||
expressions/ExpressionBOOLCONSTANT.cc
|
||||
expressions/ExpressionCONSTARRAY.cc
|
||||
expressions/ExpressionCONSTSTRUCT.cc
|
||||
expressions/ExpressionFUNCTIONCALL.cc
|
||||
expressions/ExpressionLOG.cc
|
||||
expressions/ExpressionMINMAX.cc
|
||||
expressions/ExpressionMUL.cc
|
||||
expressions/ExpressionOR.cc
|
||||
expressions/ExpressionQUANTIFIED.cc
|
||||
expressions/ExpressionUNARY.cc
|
||||
expressions/ExpressionUNSIGNEDINT.cc
|
||||
expressions/ExpressionREAL.cc
|
||||
expressions/ExpressionCARD.cc
|
||||
expressions/ExpressionCASE.cc
|
||||
expressions/ExpressionPAREN.cc
|
||||
expressions/ExpressionMEMBER.cc
|
||||
expressions/ExpressionINTERVAL.cc
|
||||
expressions/ExpressionIfThenElse.cc
|
||||
expressions/ExpressionEvaluator.cc
|
||||
expressions/ExpressionEvaluatorLandmark.cc
|
||||
expressions/ExpressionInfoVar.cc
|
||||
altarica_driver.cc
|
||||
parser_helper.cc
|
||||
FiacreTranslator.cc
|
||||
)
|
||||
|
||||
#TARGET_LINK_LIBRARIES (epoch-altarica ${LibXML++_LIBRARIES})
|
||||
80
src/grammars/altarica/Constant.cc
Normal file
80
src/grammars/altarica/Constant.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Constant.hh"
|
||||
#include "./expressions/Expression.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
Constant::Constant(std::string name) : expr_(NULL), domain_(NULL) {
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
Constant::Constant(std::string name, Domain* d) : expr_(NULL) {
|
||||
name_ = name;
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
Constant::Constant(std::string name, Domain* d, Expression *expr) {
|
||||
name_ = name;
|
||||
domain_ = d;
|
||||
expr_ = expr;
|
||||
}
|
||||
|
||||
const Domain* Constant::getDomain() const {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
const Expression* Constant::getExpression() const {
|
||||
return expr_;
|
||||
}
|
||||
|
||||
void Constant::setExpression(Expression *expr) {
|
||||
delete expr_;
|
||||
expr_=expr;
|
||||
}
|
||||
|
||||
Value * Constant::getValue(const AltaricaModel *am, AltaricaState *s, const Node* n) const {
|
||||
return expr_->evaluate(am, s, n);
|
||||
}
|
||||
|
||||
|
||||
// Constant* Constant::findConstantInVector(std::vector<Constant*> v,
|
||||
// std::string *constName) {
|
||||
// for (std::vector<Constant*>::iterator constIt = v.begin();
|
||||
// constIt != v.end(); ++constIt)
|
||||
// if ((*constIt)->getName() == constName)
|
||||
// return *constIt;
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
Constant::~Constant() {
|
||||
delete(expr_);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
79
src/grammars/altarica/Constant.hh
Normal file
79
src/grammars/altarica/Constant.hh
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_CONSTANT_H_
|
||||
#define ALTA_CONSTANT_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Domain;
|
||||
class Expression;
|
||||
class Value;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Node;
|
||||
|
||||
class Constant {
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
std::string name_;
|
||||
Domain * domain_;
|
||||
Expression * expr_;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
Constant(std::string name);
|
||||
|
||||
Constant(std::string name, Domain* d);
|
||||
|
||||
Constant(std::string name, Domain* d, Expression *expr);
|
||||
~Constant();
|
||||
|
||||
const Domain* getDomain() const;
|
||||
const Expression* getExpression() const;
|
||||
void setExpression(Expression *expr);
|
||||
|
||||
Value * getValue(const AltaricaModel *am,
|
||||
AltaricaState *s,
|
||||
const Node* n) const;
|
||||
|
||||
static Constant* findConstantInVector(std::vector<Constant*>v,
|
||||
std::string *constName);
|
||||
|
||||
std::string getName() {return name_;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
262
src/grammars/altarica/Event.cc
Normal file
262
src/grammars/altarica/Event.cc
Normal file
@@ -0,0 +1,262 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Event.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Node.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "MemberAccess.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
// Event::Event(std::string * name) {
|
||||
// name_ = new std::string(*name);
|
||||
// this->path_ = NULL;
|
||||
// this->path_indexes_ = NULL;
|
||||
// }
|
||||
|
||||
|
||||
Event::Event(MemberAccess *ma) {
|
||||
ma_ = ma;
|
||||
law_ = NULL;
|
||||
}
|
||||
|
||||
|
||||
void Event::addUppers(std::set<Event*>* b) {
|
||||
for (std::set<Event*>::iterator it = b->begin();
|
||||
it != b->end(); ++it)
|
||||
addUpper(*it);
|
||||
}
|
||||
|
||||
void Event::addUpper(Event *b) {
|
||||
|
||||
uppers_.insert(b);
|
||||
for (std::set<Event*>::iterator li = lowers_.begin(); li!=lowers_.end(); ++li)
|
||||
(*li)->addUpper(b);
|
||||
}
|
||||
|
||||
|
||||
void Event::addLowers(std::set<Event*>* b) {
|
||||
for (std::set<Event*>::iterator it = b->begin();
|
||||
it != b->end(); ++it)
|
||||
addLower(*it);
|
||||
}
|
||||
|
||||
void Event::addLower(Event *b) {
|
||||
lowers_.insert(b);
|
||||
for (std::set<Event*>::iterator ui = uppers_.begin(); ui!=uppers_.end(); ++ui)
|
||||
(*ui)->addLower(b);
|
||||
}
|
||||
|
||||
|
||||
void Event::addAttribute(const std::string a) {
|
||||
attributes_.push_back(std::string(a));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Event::addAttributes(const std::vector<std::string> *va) {
|
||||
for (std::vector<std::string>::const_iterator si = va->begin(); si != va->end(); ++si) {
|
||||
addAttribute(*si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Event::setLaw(EventLaw* el) {
|
||||
if (law_ != NULL)
|
||||
delete law_;
|
||||
law_ = el;
|
||||
if (law_ != NULL)
|
||||
law_->setNode(node_);
|
||||
}
|
||||
|
||||
const EventLaw * Event::getLaw() const {
|
||||
return law_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Event * Event::clone() {
|
||||
Event *n = new Event(ma_->clone());
|
||||
n->addAttributes(&attributes_);
|
||||
n->addUppers(&uppers_);
|
||||
n->addLowers(&lowers_);
|
||||
if (law_ != NULL)
|
||||
n->setLaw(law_->clone());
|
||||
|
||||
return n;
|
||||
}
|
||||
const MemberAccess* Event::getMA() const {
|
||||
return ma_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void Event::addPath(std::string *p) {
|
||||
// if (path_ == NULL) {
|
||||
// path_ = new std::vector<std::string*>();
|
||||
// path_indexes_ = new std::vector<int>();
|
||||
// }
|
||||
|
||||
// path_->push_back(new std::string(*p));
|
||||
// path_indexes_->push_back(-1);
|
||||
// }
|
||||
|
||||
// void Event::addPathIndexed(std::string *p, int i) {
|
||||
// if (path_ == NULL) {
|
||||
// path_ = new std::vector<std::string*>();
|
||||
// path_indexes_ = new std::vector<int>();
|
||||
// }
|
||||
// path_->push_back(new std::string(*p));
|
||||
// path_indexes_->push_back(i);
|
||||
|
||||
// }
|
||||
|
||||
std::set<Event*> const * Event::getUppers() {
|
||||
return &uppers_;
|
||||
}
|
||||
|
||||
void Event::setNode(Node*n) {
|
||||
node_ = n;
|
||||
if (law_ != NULL)
|
||||
law_->setNode(n);
|
||||
}
|
||||
|
||||
void Event::addTrans(Transition* t) {
|
||||
trans_.push_back(t);
|
||||
}
|
||||
|
||||
void Event::addSync(Synchronisation* s) {
|
||||
bool found = false;
|
||||
for (std::vector<Synchronisation*>::iterator i = syncs_.begin(); i!= syncs_.end(); ++i)
|
||||
if (*i == s) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
syncs_.push_back(s);
|
||||
}
|
||||
|
||||
int Event::nSynchros() {
|
||||
return (syncs_.size());
|
||||
}
|
||||
|
||||
const Node * Event::getNode() {
|
||||
return node_;
|
||||
}
|
||||
|
||||
std::vector<const Node*>* Event::getPath() const {
|
||||
std::vector<const Node*>* path = node_->getPath();
|
||||
path->push_back(node_);
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string Event::getFullName() const {
|
||||
std::stringstream ss;
|
||||
for(auto &n: *getPath())
|
||||
ss << n->getMA()->toString() << ".";
|
||||
ss << getMA()->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool Event::isMorePriorThan(Event*e) {
|
||||
if (e->getNode() != node_)
|
||||
return false;
|
||||
for (std::set<Event*>::iterator i = lowers_.begin(); i!= lowers_.end(); ++i) {
|
||||
if (e == *i)
|
||||
return true;
|
||||
}
|
||||
for (std::set<Event*>::iterator i = lowers_.begin(); i!= lowers_.end(); ++i) {
|
||||
return (*i)->isMorePriorThan(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Event::isLessPriorThan(Event*e) {
|
||||
if (e->getNode() != node_)
|
||||
return false;
|
||||
for (std::set<Event*>::iterator i = uppers_.begin(); i!= uppers_.end(); ++i) {
|
||||
if (e == *i)
|
||||
return true;
|
||||
}
|
||||
for (std::set<Event*>::iterator i = uppers_.begin(); i!= uppers_.end(); ++i) {
|
||||
return (*i)->isLessPriorThan(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Event::isEnabled(const AltaricaModel *am, AltaricaState *s) {
|
||||
if (law_ != NULL && law_->isDisabled())
|
||||
return false;
|
||||
if (s == NULL)
|
||||
return true;
|
||||
if (trans_.size() == 0)
|
||||
return true;
|
||||
for (std::vector<Transition*>::iterator ti = trans_.begin(); ti != trans_.end(); ++ti) {
|
||||
if ( (*ti)->precondOK(am, s))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Event::isDirac() const {
|
||||
if (law_ == NULL)
|
||||
return false;
|
||||
return (law_->isDirac());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Event::doEvent(const AltaricaModel *am, AltaricaState *s, AltaricaState *ns) {
|
||||
for (std::vector<Transition*>::iterator ti = trans_.begin();
|
||||
ti != trans_.end(); ++ti) {
|
||||
if ((*ti)->precondOK(am, s))
|
||||
(*ti)->doTransition(am, s,ns);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Event::toString() {
|
||||
std::string s;
|
||||
s+= " "+ node_->toString() + "." + ma_->toString() + " ";
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
void Event::deleteExprs() {
|
||||
if(law_ != NULL)
|
||||
law_->deleteExpr();
|
||||
}
|
||||
|
||||
Event::~Event() {
|
||||
delete ma_;
|
||||
delete law_;
|
||||
}
|
||||
}
|
||||
}
|
||||
121
src/grammars/altarica/Event.hh
Normal file
121
src/grammars/altarica/Event.hh
Normal file
@@ -0,0 +1,121 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EVENT_H_
|
||||
#define ALTA_EVENT_H_
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Transition;
|
||||
class Synchronisation;
|
||||
class MetaEvent;
|
||||
class AltaricaState;
|
||||
class MemberAccess;
|
||||
class EventLaw;
|
||||
class AltaricaModel;
|
||||
|
||||
//! EVENT
|
||||
/*!
|
||||
Stucture pour stocker les event et leur priorite
|
||||
*/
|
||||
class Event {
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
// std::string *name_;
|
||||
//! full qualified name
|
||||
MemberAccess *ma_;
|
||||
std::set<Event*> uppers_;
|
||||
std::set<Event*> lowers_;
|
||||
std::vector<std::string> attributes_;
|
||||
EventLaw * law_;
|
||||
|
||||
Node * node_;
|
||||
std::vector<Transition *> trans_;
|
||||
std::vector<Synchronisation*> syncs_;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
// Event(std::string *name);
|
||||
Event(MemberAccess *ma);
|
||||
|
||||
void addUppers(std::set<Event*>* b);
|
||||
void addUpper(Event *b);
|
||||
void addLowers(std::set<Event*>* b);
|
||||
void addLower(Event* b);
|
||||
void addAttribute(const std::string a);
|
||||
void addAttributes(const std::vector<std::string> *va);
|
||||
void setLaw(EventLaw* el);
|
||||
const EventLaw * getLaw() const;
|
||||
|
||||
void setNode(Node* n);
|
||||
const Node* getNode();
|
||||
|
||||
std::vector<const Node *>* getPath() const;
|
||||
std::string getFullName() const;
|
||||
|
||||
const MemberAccess* getMA() const;
|
||||
|
||||
void addTrans(Transition* t);
|
||||
const std::vector<Transition *> * getTrans() const {return &trans_;}
|
||||
void addSync(Synchronisation* s);
|
||||
|
||||
int nSynchros();
|
||||
|
||||
// void addPath(std::string* p);
|
||||
// void addPathIndexed(std::string* p, int i);
|
||||
|
||||
std::set<Event*> const * getUppers();
|
||||
Event * clone();
|
||||
|
||||
bool isMorePriorThan(Event*e);
|
||||
bool isLessPriorThan(Event*e);
|
||||
|
||||
bool isEnabled(const AltaricaModel *am, AltaricaState *s);
|
||||
bool isDirac() const;
|
||||
|
||||
void doEvent(const AltaricaModel *am, AltaricaState *s, AltaricaState *ns);
|
||||
|
||||
std::string toString();
|
||||
~Event();
|
||||
|
||||
void deleteExprs() ;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
119
src/grammars/altarica/EventLaw.cc
Normal file
119
src/grammars/altarica/EventLaw.cc
Normal file
@@ -0,0 +1,119 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "EventLaw.hh"
|
||||
#include <stdlib.h>
|
||||
#include "MemberAccess.hh"
|
||||
#include <sstream>
|
||||
#include "values/Value.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#include "expressions/Expression.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EventLaw * EventLaw::clone() const {
|
||||
EventLaw * el;
|
||||
if (ma_ != NULL)
|
||||
el = new EventLaw(ma_->clone(), type_, param1_, param2_);
|
||||
else
|
||||
el = new EventLaw(NULL, type_, param1_, param2_);
|
||||
return el;
|
||||
}
|
||||
|
||||
EventLaw::~EventLaw() {
|
||||
delete ma_;
|
||||
// delete param_;
|
||||
}
|
||||
|
||||
void EventLaw::deleteExpr()
|
||||
{
|
||||
delete param1_;
|
||||
}
|
||||
|
||||
|
||||
bool EventLaw::isDisabled() const {
|
||||
return (type_ == ALTARICA_DISCRETE && param1_ == 0);
|
||||
}
|
||||
|
||||
bool EventLaw::isDirac() const {
|
||||
return type_ == ALTARICA_DIRAC_0;
|
||||
}
|
||||
|
||||
bool EventLaw::isDiscrete() const {
|
||||
return type_ == ALTARICA_DISCRETE;
|
||||
}
|
||||
|
||||
bool EventLaw::isCont() const {
|
||||
return type_ == ALTARICA_EXP;
|
||||
}
|
||||
|
||||
bool EventLaw::isTimed() const {
|
||||
return type_ == ALTARICA_TIMED;
|
||||
}
|
||||
|
||||
double EventLaw::evalParam(const AltaricaModel *am, AltaricaState *s) const {
|
||||
Value *v = param1_->evaluate(am, s, n_, true);
|
||||
double ret;
|
||||
if (v->isInt())
|
||||
ret = ((ValueInt*)v)->toInt();
|
||||
else
|
||||
ret = ((ValueReal*)v)->toDouble();
|
||||
Value::deleteIfPossible(v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string EventLaw::toString() const {
|
||||
std::stringstream ss;
|
||||
switch(type_) {
|
||||
case ALTARICA_TIMED:
|
||||
ss<<"timed(" << param1_->toString() <<", " << param2_->toString() << ")";
|
||||
break;
|
||||
case ALTARICA_DISCRETE:
|
||||
ss << "discrete(" << param1_->toString() <<")";
|
||||
break;
|
||||
case ALTARICA_EXP:
|
||||
ss << "exp(" << param1_->toString() <<")";
|
||||
break;
|
||||
case ALTARICA_DIRAC_0:
|
||||
ss<<"dirac(0)";
|
||||
break;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
111
src/grammars/altarica/EventLaw.hh
Normal file
111
src/grammars/altarica/EventLaw.hh
Normal file
@@ -0,0 +1,111 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EVENTLAW_H_
|
||||
#define ALTA_EVENTLAW_H_
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class MemberAccess;
|
||||
class Expression;
|
||||
class Node;
|
||||
class AltaricaModel;
|
||||
class AltaricaState;
|
||||
|
||||
//! EVENT
|
||||
/*!
|
||||
Stucture pour stocker les event et leur priorite
|
||||
*/
|
||||
typedef enum LawType {
|
||||
ALTARICA_DISCRETE,
|
||||
ALTARICA_DIRAC_0,
|
||||
ALTARICA_EXP,
|
||||
ALTARICA_TIMED
|
||||
} LawType;
|
||||
|
||||
class EventLaw {
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
// std::string *eventName_;
|
||||
//! full qualified name
|
||||
MemberAccess *ma_;
|
||||
LawType type_;
|
||||
//double param_;
|
||||
Expression * param1_;
|
||||
Expression * param2_;
|
||||
Node *n_;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
// EventLaw(std::string *name);
|
||||
// EventLaw(std::string *name, LawType t, double p);
|
||||
~EventLaw();
|
||||
EventLaw(MemberAccess *ma) : ma_(ma), n_(NULL), param1_(NULL), param2_(NULL) {}
|
||||
EventLaw(MemberAccess *ma, LawType t, Expression * p) : ma_(ma), type_(t), param1_(p), param2_(NULL), n_(NULL) {}
|
||||
EventLaw(MemberAccess *ma, LawType t, Expression * p, Expression * q) : ma_(ma), type_(t), param1_(p), param2_(q), n_(NULL) {}
|
||||
EventLaw(LawType t, Expression * p = NULL, Expression * q = NULL) : ma_(NULL), type_(t), param1_(p), param2_(q), n_(NULL) {}
|
||||
|
||||
// void setName(std::string *name);
|
||||
void setMA(MemberAccess *ma) {ma_ = ma;}
|
||||
void setType(LawType t) {type_=t;}
|
||||
void setParam(Expression *e) {param1_ = e;}
|
||||
Expression * getParam() const {return param1_;}
|
||||
Expression * getStartParam() const {return param1_;}
|
||||
Expression * getEndParam() const {return param2_;}
|
||||
|
||||
double evalParam(const AltaricaModel *am, AltaricaState *s) const;
|
||||
bool isDisabled() const;
|
||||
bool isDirac() const;
|
||||
bool isDiscrete() const;
|
||||
bool isCont() const;
|
||||
bool isTimed() const;
|
||||
void setNode(Node *n) {n_ = n;}
|
||||
|
||||
const MemberAccess* getMA() const {return ma_;}
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
EventLaw * clone() const;
|
||||
|
||||
void deleteExpr();
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
709
src/grammars/altarica/FiacreTranslator.cc
Normal file
709
src/grammars/altarica/FiacreTranslator.cc
Normal file
@@ -0,0 +1,709 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* FiacreTranslator.cc
|
||||
*
|
||||
* Created on: 27 oct. 2016
|
||||
* Author: alexandre.albore
|
||||
* This file is part of the IRT MOISE project
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include "FiacreTranslator.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Constant.hh"
|
||||
#include "expressions/Expressions.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "AltaricaGenerator.hh"
|
||||
#include "Event.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "Synchronisation.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Node.hh"
|
||||
#include "Assertion.hh"
|
||||
#include "EventLaw.hh"
|
||||
|
||||
//#define USEUNDEF true // Used to extend the types with an undef value
|
||||
// 2016031810012552 to fr
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
const std::string xx = std::string("x");
|
||||
const std::string yy = std::string("y");
|
||||
const std::pair<std::string,std::string> prefixes(xx,yy);
|
||||
|
||||
FiacreTranslator::FiacreTranslator(const AltaricaModel *amodel): amodel_(amodel) {
|
||||
|
||||
}
|
||||
|
||||
FiacreTranslator::~FiacreTranslator() {
|
||||
os_.clear();
|
||||
}
|
||||
|
||||
|
||||
std::string FiacreTranslator::getType(Value* dom) {
|
||||
if (dom->isBool())
|
||||
return std::string("bool");
|
||||
else if (dom->isInt())
|
||||
return std::string("int");
|
||||
else if (dom->isSymbol())
|
||||
return std::string("union");
|
||||
}
|
||||
|
||||
/* @return a string with the union
|
||||
* Could return a list for ex.
|
||||
*/
|
||||
std::string FiacreTranslator::makesUnion(const std::vector<std::string>* sym) {
|
||||
std::string currentType;
|
||||
|
||||
for (std::vector<std::string>::const_iterator i = sym->begin(); i!= sym->end(); ++i) {
|
||||
if (i+1 == sym->end())
|
||||
currentType += *i ;
|
||||
else
|
||||
currentType += *i + "|";
|
||||
}
|
||||
return currentType;
|
||||
}
|
||||
|
||||
std::string FiacreTranslator::removeAmp(std::string &r) {
|
||||
size_t index = 0;
|
||||
while (true) {
|
||||
index = r.find("&", index);
|
||||
if (index == std::string::npos) break;
|
||||
r.replace(index, 1, ".");
|
||||
index += 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/// Does the product of MetaEvents
|
||||
/// NB: A·B= AB (but not A, B)
|
||||
std::string FiacreTranslator::print_MandatoryEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n,
|
||||
std::ostringstream * spre, std::ostringstream * spost) {
|
||||
|
||||
std::ostringstream sret;
|
||||
std::string s ;
|
||||
|
||||
// if ( spre->rdbuf()->in_avail() == 0 )
|
||||
// *spre << "on (";
|
||||
// else *spre << "\t[] on (";
|
||||
|
||||
|
||||
if (n < 0) {
|
||||
sret << spre->str() + ");\n" + spost->str() + "\t\tx := assertions(y";
|
||||
|
||||
// listing the state vars
|
||||
/* for(auto &s : model().getStateVars()) {
|
||||
sret << s->toFiacre();
|
||||
if (&s != &model().getStateVars().back())
|
||||
sret << ", " ;
|
||||
} */
|
||||
sret << ");" << std::endl << "\t\tto s0"<< std::endl;
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
// unsigned j = 0;
|
||||
if (ev->at(n)->getTrans()->size() != 0)
|
||||
for (auto &ti : *(ev->at(n)->getTrans()) ) {
|
||||
std::ostringstream s1, s2;
|
||||
std::string ti_str = ti->getPrecond()->toString( ti->getNode(), &prefixes, model());
|
||||
s1 << spre->str() << removeAmp(ti_str);
|
||||
if ( n != 0 )
|
||||
s1 << " and ";
|
||||
//s1 << sout->str() << "\tE" << n << "T" << j++;
|
||||
|
||||
const std::vector<epoch::altarica::Assignment*>* effects = ti->getAssigns();
|
||||
if(effects->size() > 0) {
|
||||
s2 << spost->str();
|
||||
|
||||
for(auto &a : *effects) {
|
||||
std::string eff_str = "\t\t"
|
||||
+ a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model() )
|
||||
+ ";\n";
|
||||
s2 << removeAmp(eff_str);
|
||||
}
|
||||
}
|
||||
sret << print_MandatoryEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
else { // null transition
|
||||
std::ostringstream s1, s2;
|
||||
s1 << spre->str();
|
||||
s2 << spost->str();
|
||||
sret << print_MandatoryEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
|
||||
/// Does the optional syncs
|
||||
/// NB: A: a -> a' ; B: b -> b'
|
||||
/// A·B: a|b -> (if a then a') & (if b then b')
|
||||
std::string FiacreTranslator::print_OptionalEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n,
|
||||
std::ostringstream * spre, std::ostringstream * spost) {
|
||||
|
||||
std::ostringstream sret;
|
||||
std::string s ;
|
||||
|
||||
if (n < 0) {
|
||||
sret << spre->str() + ");\n" + spost->str() + "\t\tx := assertions(y";
|
||||
// for(auto &s : model().getStateVars()) {
|
||||
// sret << s->toFiacre();
|
||||
// if (&s != &model().getStateVars().back())
|
||||
// sret << ", " ;
|
||||
// }
|
||||
sret << ");" << std::endl << "\t\tto s0"<< std::endl;
|
||||
return sret.str();
|
||||
}
|
||||
///
|
||||
// const std::string ff = std::string("f");
|
||||
// const std::string gg = std::string("g");
|
||||
// const std::pair<std::string,std::string> prefixes(ff,gg);
|
||||
// std::string assertion = " " + ai->getExpr()->toString((ai->getNode()), &prefixes, model()) + ";\n";//
|
||||
// size_t index = 0;
|
||||
// while (true) {
|
||||
// index = assertion.find(".", index);
|
||||
// if (index == std::string::npos) break;
|
||||
// assertion.replace(index, 1, "_");
|
||||
// index += 1;
|
||||
// }
|
||||
// index = 0;
|
||||
// while (true) { // NB: Transitions already use ':='
|
||||
// index = assertion.find("=", index);
|
||||
// size_t indexif = assertion.find("if", 0);
|
||||
// if (index == std::string::npos) break;
|
||||
// if (indexif == std::string::npos) // does not replace for if conditions (the rest of expr is taken care by the Expressions)
|
||||
// assertion.replace(index, 1, ":=");
|
||||
// break;
|
||||
// }
|
||||
///
|
||||
|
||||
if (ev->at(n)->getTrans()->size() != 0)
|
||||
for (auto &ti : *(ev->at(n)->getTrans()) ) { // HERE: do it in reverse order (?)
|
||||
std::ostringstream s1, s2;
|
||||
std::string ti_str = ti->getPrecond()->toString( ti->getNode(), &prefixes, model());
|
||||
s1 << spre->str() << removeAmp(ti_str);
|
||||
if ( n != 0 )
|
||||
s1 << " or ";
|
||||
|
||||
const std::vector<epoch::altarica::Assignment*>* effects = ti->getAssigns();
|
||||
if(effects->size() > 0) {
|
||||
s2 << spost->str();
|
||||
for(auto &a : *effects) {
|
||||
std::string eff_str = "\t\tif ("
|
||||
+ ti->getPrecond()->toString( ti->getNode(), &prefixes, model() )
|
||||
+ ") then "
|
||||
+ a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model() )
|
||||
+ "\n\t\tend;\n";
|
||||
s2 << removeAmp(eff_str);
|
||||
}
|
||||
}
|
||||
sret << print_OptionalEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
else { // null transition
|
||||
std::ostringstream s1, s2;
|
||||
s1 << spre->str();
|
||||
s2 << spost->str();
|
||||
sret << print_OptionalEvents_sync( ev, n-1, &s1, &s2);
|
||||
}
|
||||
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
|
||||
std::string FiacreTranslator::print_assertions_function (std::vector<std::string> &vecStateVars, std::vector<std::string> &vecFlowVars) {
|
||||
|
||||
std::ostringstream ss;
|
||||
|
||||
const std::string ff = std::string("f");
|
||||
const std::string gg = std::string("g");
|
||||
const std::pair<std::string,std::string> prefixes(ff,gg);
|
||||
|
||||
// Updates the assertions
|
||||
ss << std::endl << "function assertions (";
|
||||
ss << "g : StateVars) : FlowVars is" << std::endl << " var f : FlowVars";
|
||||
|
||||
//Produces the list of state variables
|
||||
// for (int t=0;t<vecStateVars.size();++t) {
|
||||
// ss << vecStateVars.at(t);
|
||||
//
|
||||
// if (t+1 == vecStateVars.size()) {
|
||||
// ss << ") : FlowVars is" << std::endl << " var f : FlowVars";
|
||||
|
||||
//
|
||||
//
|
||||
// #ifdef USEUNDEF
|
||||
// ss << ":= {" << std::endl;
|
||||
//
|
||||
// for(auto &v : model().getFlowVars()) {
|
||||
// os_<< "\t" << v->toFiacre();
|
||||
//
|
||||
// ss << "=" << UNDEF;
|
||||
//
|
||||
// if (&v != &model().getFlowVars().back())
|
||||
// ss<< "," << std::endl;
|
||||
// else
|
||||
// os_ << "\n }";
|
||||
// }
|
||||
// #endif
|
||||
//
|
||||
ss << std::endl << " begin"<< std::endl;
|
||||
// } else
|
||||
// ss << ", ";
|
||||
// }
|
||||
|
||||
for(auto &ai : model().getAsserts()) {
|
||||
std::string assertion = " " + ai->getExpr()->toString((ai->getNode()), &prefixes, model()) + ";\n";//
|
||||
size_t index = 0;
|
||||
while (true) {
|
||||
index = assertion.find(".", index);
|
||||
if (index == std::string::npos) break;
|
||||
assertion.replace(index, 1, "_");
|
||||
index += 1;
|
||||
}
|
||||
index = 0;
|
||||
while (true) { // NB: Transitions already use ':='
|
||||
index = assertion.find("=", index);
|
||||
size_t indexif = assertion.find("if", 0);
|
||||
if (index == std::string::npos) break;
|
||||
if (indexif == std::string::npos) // does not replace for if conditions (the rest of expr is taken care by the Expressions)
|
||||
assertion.replace(index, 1, ":=");
|
||||
break;
|
||||
}
|
||||
index = 0;
|
||||
ss << removeAmp(assertion);
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
ss << " return f"<< std::endl<< std::endl;
|
||||
ss << " end"<< std::endl;
|
||||
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string FiacreTranslator::print_metaEvents(const epoch::altarica::MetaEvent& e) {
|
||||
std::ostringstream sret;
|
||||
size_t index = 0;
|
||||
|
||||
if (e.getEvents()->size() != 0) {
|
||||
std::ostringstream s1;
|
||||
std::ostringstream s2;
|
||||
std::string label;
|
||||
|
||||
label = ((e.getEvents()->size() == 1)? "" : "meta_event_");
|
||||
|
||||
double minTime, maxTime = -100000.0;
|
||||
bool has_Tlaw = false;
|
||||
|
||||
s1 << "on (";
|
||||
for (std::vector<epoch::altarica::Event*>::iterator i = e.getEvents()->begin();
|
||||
i!=e.getEvents()->end(); ++i) {
|
||||
for (auto &t : *(*i)->getTrans()) {
|
||||
|
||||
/* Prints preconditions = guards */
|
||||
std::string r(t->getPrecond()->toString( t->getNode(), &prefixes, model() ));
|
||||
s1 << removeAmp(r);
|
||||
if ((i+1) != e.getEvents()->end()) s1 << " and ";
|
||||
else if (*(&t+1) != *(*i)->getTrans()->end()) s1 << " and ";
|
||||
|
||||
/* Gets the transition law */
|
||||
const EventLaw *law = (*i)->getLaw();
|
||||
const Node * ne = (*i)->getNode();
|
||||
if ( law && law->isTimed()) {
|
||||
has_Tlaw = true;
|
||||
double minT = std::atof(law->getStartParam()->toString( ne , model() ).c_str()) ;
|
||||
double maxT = std::atof(law->getEndParam()->toString(ne, model() ).c_str());
|
||||
|
||||
// Note to self: faire une metaEvent law.
|
||||
minTime = std::min( minTime, minT );
|
||||
maxTime = maxT < 0 ? maxTime : std::max(maxT, maxTime);
|
||||
}
|
||||
|
||||
/* Prints effects */
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
for(auto &a : *(t->getAssigns())) {
|
||||
std::string rr = "\t\t" + a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model())
|
||||
+ ";\n";
|
||||
s2 << removeAmp(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
label += (*i)->getFullName() ;
|
||||
}
|
||||
|
||||
sret << s1.str() << ");" << std::endl;
|
||||
|
||||
if (has_Tlaw) {
|
||||
sret << "\t\twait";
|
||||
if (minTime < 0)
|
||||
sret << "]w,";
|
||||
else sret << "[" << minTime << ",";
|
||||
if (maxTime < 0)
|
||||
sret << "w[;";
|
||||
else sret << maxTime << "];" ;
|
||||
sret << std::endl;
|
||||
}
|
||||
|
||||
sret << s2.str();
|
||||
|
||||
sret << "\t\t/* flow resolution */"<< std::endl;
|
||||
sret << "\t\tx := assertions(y);" << std::endl;
|
||||
/* Prints transition label */
|
||||
{
|
||||
size_t index = 0;
|
||||
|
||||
while (true) {
|
||||
index = label.find(".", index);
|
||||
if (index == std::string::npos) break;
|
||||
label.replace(index, 1, "_");
|
||||
index += 1;
|
||||
}
|
||||
sret << "\t\t#" << label << ";" << std::endl;
|
||||
}
|
||||
|
||||
sret << "\t\tto s0"<< std::endl;
|
||||
}
|
||||
else
|
||||
std::cerr << " NO EVENT";
|
||||
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
std::string FiacreTranslator::print_transitions (Event &e,std::string &sconnect) {
|
||||
std::ostringstream sret;
|
||||
size_t index = 0;
|
||||
|
||||
if(e.getTrans()->size() > 0) {
|
||||
|
||||
if (sconnect.empty())
|
||||
sret <<"\t select"<< std::endl << "\t\t";
|
||||
|
||||
for(auto &t : *e.getTrans()) {
|
||||
std::string r = "on (" + t->getPrecond()->toString( t->getNode(), &prefixes, model() ) + ");\n";
|
||||
|
||||
sret << sconnect << removeAmp(r);
|
||||
|
||||
const EventLaw * law = e.getLaw();
|
||||
const Node * ne = e.getNode();
|
||||
if ( law && law->isTimed())
|
||||
sret << "\t\twait" << (std::atof(law->getStartParam()->toString( ne , model() ).c_str()) < 0 ? "]w"
|
||||
: "[" + law->getStartParam()->toString( ne, model() )) << ","
|
||||
<< (std::atof(law->getEndParam()->toString(ne, model() ).c_str()) < 0 ? "w[;"
|
||||
: law->getEndParam()->toString(ne, model() ) + "];") << std::endl;
|
||||
|
||||
if(t->getAssigns()->size() > 0) {
|
||||
for(auto &a : *t->getAssigns()) {
|
||||
std::string rr = "\t\t" // NB: tail is always a state variable
|
||||
+ a->getVar()->toFiacre()
|
||||
+ " := "
|
||||
+ a->getExpr()->toString( a->getNode(), &prefixes, model() )
|
||||
+ ";\n";
|
||||
sret << removeAmp(rr);
|
||||
}
|
||||
}
|
||||
sret << "\t\t/* flow resolution */"<< std::endl;
|
||||
sret << "\t\tx := assertions(y);" << std::endl;
|
||||
|
||||
/* Prints transition label */
|
||||
{
|
||||
std::string s = e.getFullName();
|
||||
size_t index = 0;
|
||||
|
||||
while (true) {
|
||||
index = s.find(".", index);
|
||||
if (index == std::string::npos) break;
|
||||
s.replace(index, 1, "_");
|
||||
index += 1;
|
||||
}
|
||||
sret << "\t\t#" << s << ";" << std::endl;
|
||||
}
|
||||
|
||||
sret << "\t\tto s0"<< std::endl;
|
||||
if (sconnect.empty())
|
||||
sconnect += "\t\t[] ";
|
||||
}
|
||||
}
|
||||
return sret.str();
|
||||
}
|
||||
|
||||
void FiacreTranslator::printFiacre() {
|
||||
|
||||
// Gets types and state variables
|
||||
std::ostringstream osStateVars, osStateVars2, osTransitions, liftedTypes;
|
||||
std::vector<std::string> vecFlowVars, vecStateVars;
|
||||
|
||||
os_ << "/* Types */"<<std::endl<<std::endl;
|
||||
liftedTypes << "type flowtype is union" << std::endl << "\t";
|
||||
|
||||
|
||||
if (model().getNStateVars()) osStateVars <<"\tvar ";
|
||||
for (unsigned int j = 0; j != model().getNStateVars(); ) {
|
||||
|
||||
// State Vars
|
||||
|
||||
Variable * v = model().getStateVar(j++);
|
||||
Value* dom = v->getDomain()->toValue();
|
||||
|
||||
// gets the type
|
||||
// NB: works only if they are always present in the same order in the Altarica file, otherwise use a list (more costly)
|
||||
|
||||
if (dom->isSymbol()) {
|
||||
const std::vector<std::string>* sym = ((ValueSymbol*)dom)->toSymbols();
|
||||
std::string currentType = makesUnion(sym);
|
||||
std::string typeName = ( v->getDomain()->get_name() == "" ?
|
||||
std::string("type").append( std::to_string(types_.size())) :
|
||||
v->getDomain()->get_name() );
|
||||
// Hashes the type
|
||||
if (types_.emplace(currentType, typeName).second ) {
|
||||
// prints the type
|
||||
os_ << "type " << types_[currentType];// state var v->toFiacre();
|
||||
os_ << " is union " << currentType << " end" << std::endl;// getType(dom);
|
||||
}
|
||||
|
||||
vecStateVars.push_back( v->toFiacre(false) + " : " + types_[currentType] );
|
||||
osStateVars <<"\t" << v->toFiacre(false) << " : " << types_[currentType];
|
||||
|
||||
} // is symbol
|
||||
else { // is basic type
|
||||
vecStateVars.push_back( v->toFiacre(false) + " : " + getType(dom) );
|
||||
osStateVars <<"\t" << v->toFiacre(false) << " : " << getType(dom);
|
||||
}
|
||||
osStateVars << " := " << v->getInit()->getExpr()->toString() << "," << std::endl;
|
||||
if (j == 1)
|
||||
osStateVars2 << "\t" << v->toFiacre(false) << " = " << v->getInit()->getExpr()->toString() ;
|
||||
else
|
||||
osStateVars2 << "," << std::endl <<"\t" << v->toFiacre(false) << " = " << v->getInit()->getExpr()->toString() ;
|
||||
}
|
||||
os_ << std::endl;
|
||||
|
||||
// Flow Vars
|
||||
for(auto &v : model().getFlowVars()) {
|
||||
|
||||
std::string theType;
|
||||
Value* dom = v->getDomain()->toValue();
|
||||
|
||||
// gets the type
|
||||
|
||||
if (dom->isSymbol()) { // is symbol
|
||||
const std::vector<std::string>* sym = ((ValueSymbol*)dom)->toSymbols();
|
||||
std::string currentType = makesUnion(sym);
|
||||
std::string typeName = ( v->getDomain()->get_name() == "" ?
|
||||
std::string("type").append( std::to_string(types_.size())) :
|
||||
v->getDomain()->get_name() );
|
||||
|
||||
// Hashes the type
|
||||
#ifdef USEUNDEF
|
||||
if (std::find(flowtypes_.begin(), flowtypes_.end(), typeName) == flowtypes_.end())
|
||||
{
|
||||
std::string tn= typeName;
|
||||
flowtypes_.push_back(tn);
|
||||
transform(tn.begin(), tn.end(), tn.begin(), toupper);
|
||||
liftedTypes << tn << " of " << typeName << "|\n\t";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (types_.emplace(currentType, typeName).second ) {
|
||||
// prints the type
|
||||
os_ << "type " << types_[currentType];// state var v->toFiacre();
|
||||
os_ << " is union " << currentType << " end" << std::endl;// getType(dom);
|
||||
}
|
||||
|
||||
theType = types_[currentType];
|
||||
} // end is symbol
|
||||
else {
|
||||
#ifdef USEUNDEF
|
||||
if (std::find(flowtypes_.begin(), flowtypes_.end(), getType(dom)) == flowtypes_.end()) { // is basic type
|
||||
|
||||
std::string tn = getType(dom);
|
||||
|
||||
flowtypes_.push_back(tn);
|
||||
transform(tn.begin(), tn.end(), tn.begin(), toupper);
|
||||
liftedTypes << tn << " of " << getType(dom) << "|\n\t";
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
theType = getType(dom);
|
||||
}// end is basic type
|
||||
|
||||
|
||||
#ifdef USEUNDEF
|
||||
vecFlowVars.push_back(v->toFiacre(false) + " : flowtype"); // + types_[currentType]);
|
||||
|
||||
} // end for
|
||||
|
||||
liftedTypes << UNDEF << " end" << std::endl;
|
||||
os_ << liftedTypes.str();
|
||||
#else
|
||||
|
||||
vecFlowVars.push_back(v->toFiacre(false) + " : " + theType);
|
||||
// Gets the aliases
|
||||
// for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator i = (v->getAliases())->begin(); i!= v->getAliases()->end(); ++i) {
|
||||
//
|
||||
//
|
||||
// {
|
||||
// // Get the variable
|
||||
// std::ostringstream oss;
|
||||
//
|
||||
// oss.str("");
|
||||
// std::string nodename = (*i)->first->getFullName();
|
||||
// if (nodename != "main")
|
||||
// oss << nodename.substr(5, std::string::npos) << ".";
|
||||
// oss << (*i)->second->toString();
|
||||
// std::string aliasname = oss.str();
|
||||
// std::cout << "looking for " << v->getFullName() << std::endl;
|
||||
// //epoch::altarica::Variable* av = v->getNode()->findVariableByName(aliasname);
|
||||
// //if (av == NULL)
|
||||
// // throw new std::out_of_range("Cannot find Variable: " + nodename +
|
||||
// // " in node " + nodename + "\n");
|
||||
// //vecFlowVars.push_back( av->toFiacre() + " : " + theType );
|
||||
//
|
||||
//
|
||||
// MemberAccess *ma = new MemberAccess(aliasname);
|
||||
// // ma->setGlobal(true);
|
||||
// Variable * av = model().getMainNode()->findVariableByName(ma);
|
||||
// std::cout << " - " << av->getFullName() << std::endl;
|
||||
// // model().existsVar();
|
||||
//
|
||||
// }
|
||||
|
||||
// vecFlowVars.push_back( (*i)->first->toFiacre() + "_" + (*i)->second->toString() + " : " + theType );
|
||||
// }
|
||||
} // end for
|
||||
#endif
|
||||
|
||||
os_ << "type FlowVars is record\n";
|
||||
for (int t=0;t<vecFlowVars.size();++t) {
|
||||
os_ << "\t" << vecFlowVars.at(t);
|
||||
if (t+1 < vecFlowVars.size())
|
||||
os_<< ",\n";
|
||||
else
|
||||
os_ << " end" << std::endl;
|
||||
}
|
||||
|
||||
os_ << "type StateVars is record\n";
|
||||
for (int t=0;t<vecStateVars.size();++t) {
|
||||
os_ << "\t" << vecStateVars.at(t);
|
||||
if (t+1 < vecStateVars.size())
|
||||
os_<< ",\n";
|
||||
else
|
||||
os_ << " end" << std::endl;
|
||||
}
|
||||
|
||||
os_ <<std::endl<< "/* Constants */"<<std::endl;
|
||||
|
||||
std::vector<epoch::altarica::Constant*> constants = model().getConstants();
|
||||
for (std::vector<epoch::altarica::Constant*>::const_iterator c = constants.begin(); c!= constants.end(); ++c) {
|
||||
std::string t = std::string("type");
|
||||
const Expression* expr = (*c)->getExpression();
|
||||
|
||||
if (const ExpressionUNSIGNEDINT* vu = dynamic_cast<const ExpressionUNSIGNEDINT*>(expr))
|
||||
t = std::string("nat");
|
||||
else if (const ExpressionBOOLCONSTANT* vu = dynamic_cast<const ExpressionBOOLCONSTANT*>(expr))
|
||||
t = std::string("bool");
|
||||
// for (auto &n : model().getNodes())
|
||||
// if (n->getMA()->isGlobal() || n->getParent() != NULL) // << n->getMA()->toString() << "_"
|
||||
os_ << "const " << (*c)->getName() << " : "
|
||||
<< t << " is " << (*c)->getExpression()->toString()<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
os_ << print_assertions_function(vecStateVars, vecFlowVars);
|
||||
|
||||
|
||||
os_<<std::endl << "process mainprocess (&x : FlowVars, &y: StateVars) is\n\tstates s0"<<std::endl;
|
||||
|
||||
|
||||
// for (int t=0;t<vecFlowVars.size();++t)
|
||||
// os_ << "," << std::endl <<"\t" << vecFlowVars.at(t); /* NB: FLOW VARS have no Init value << " := " << v->getInit()->getExpr()->toString() */
|
||||
// os_ << std::endl;
|
||||
|
||||
/*********** Transitions ********/
|
||||
|
||||
osTransitions << std::endl <<"\tfrom s0"<<std::endl;
|
||||
|
||||
std::string sconnect("");
|
||||
for(auto &e : model().getAtomicEvents()) {
|
||||
// osTransitions << print_transitions(*e, sconnect);
|
||||
}
|
||||
|
||||
// osTransitions << "\t\t/* Syncs */"<<std::endl;
|
||||
// for(auto &sy : model().getSyncs()) {
|
||||
// if (sy->getMandatoryEvents()->size() || sy->getOptionalEvents()->size()) {
|
||||
// std::ostringstream s1("\t\t[] on (");
|
||||
// std::ostringstream s2;
|
||||
// int num = sy->getMandatoryEvents()->size()-1;
|
||||
//
|
||||
// if (sy->getMandatoryEvents()->size() > 1)
|
||||
// osTransitions << print_MandatoryEvents_sync(sy->getMandatoryEvents(), num, &s1, &s2);
|
||||
//
|
||||
// num = sy->getOptionalEvents()->size()-1;
|
||||
// if (sy->getOptionalEvents()->size() > 1)
|
||||
// osTransitions << print_OptionalEvents_sync(sy->getOptionalEvents(), num, &s1, &s2);
|
||||
// }
|
||||
// }
|
||||
|
||||
osTransitions << "/* Syncs */" << std::endl;
|
||||
osTransitions <<"\t select"<< std::endl << "\t\t";
|
||||
bool firstME = true;
|
||||
|
||||
for(auto &sy :model().getMetaEvents()) {
|
||||
if (firstME)
|
||||
firstME=false;
|
||||
else osTransitions << "\t\t[]";
|
||||
|
||||
osTransitions << print_metaEvents(*sy);
|
||||
}
|
||||
|
||||
os_ << osTransitions.str();
|
||||
os_ << "\t end" << std::endl;
|
||||
|
||||
std::cout << os_.str();
|
||||
|
||||
|
||||
std::cout << "component Main is" << std::endl;
|
||||
|
||||
// Removing the last comma
|
||||
osStateVars.seekp(osStateVars.str().length()-1);
|
||||
std::cout << "\t/* State Variables */\n\tvar y : StateVars := {"<< std::endl;
|
||||
std::cout << osStateVars2.str() << " }," << std::endl;
|
||||
std::cout << "\tx : FlowVars"<< std::endl << std::endl;
|
||||
|
||||
std::cout << "\tpar * in\n\t\tmainprocess (&x, &y)\n\tend" << std::endl << std::endl << "Main"<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
}
|
||||
110
src/grammars/altarica/FiacreTranslator.hh
Normal file
110
src/grammars/altarica/FiacreTranslator.hh
Normal file
@@ -0,0 +1,110 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* \class FiacreTranslator
|
||||
*
|
||||
* \ingroup PackageName
|
||||
* (Note, this needs exactly one \defgroup somewhere)
|
||||
*
|
||||
* \brief Provide an example
|
||||
*
|
||||
* This class contains all the printouts of the Altarica data structure
|
||||
* to a fiacre file.
|
||||
* Called in the main console.
|
||||
*
|
||||
* \note This file is part of the IRT MOISE project
|
||||
*
|
||||
* \author alexandre.albore $Author: bv $
|
||||
*
|
||||
* \version $Revision: 1.0 $
|
||||
*
|
||||
* \date $Date: 2016/10/27 09:16:20 $
|
||||
*
|
||||
* Contact: alexandre.albore@irt-saintexupery.com
|
||||
*
|
||||
* Created on: Wed Oct 27 09:16:20 2016
|
||||
*
|
||||
* $Id: doxygen-howto.html,v 1.0 2016/10/27 14:16:20 bv Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FIACRETRANSLATOR_HH_
|
||||
#define FIACRETRANSLATOR_HH_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include "Values.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
|
||||
class FiacreTranslator {
|
||||
|
||||
private:
|
||||
std::vector<Value*> stateVars_;
|
||||
mutable std::vector<Value*> flowVars_;
|
||||
const AltaricaModel * amodel_;
|
||||
// std::vector<Assertion*> * asserts_;
|
||||
|
||||
protected:
|
||||
std::ostringstream os_;
|
||||
std::unordered_map<std::string,std::string> types_;
|
||||
std::vector<std::string> flowtypes_;
|
||||
const std::string UNDEF = std::string("UNDEF");
|
||||
std::string print_MandatoryEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n, std::ostringstream * s1, std::ostringstream * s2);
|
||||
std::string print_OptionalEvents_sync (const std::vector<epoch::altarica::Event*> *ev, int n, std::ostringstream * s1, std::ostringstream * s2);
|
||||
std::string print_assertions_function (std::vector<std::string> &vs, std::vector<std::string> &vf);
|
||||
std::string print_transitions (epoch::altarica::Event &e, std::string &sconnect);
|
||||
std::string print_metaEvents(const epoch::altarica::MetaEvent& e) ; //,std::string &sconnect
|
||||
|
||||
public:
|
||||
//!
|
||||
FiacreTranslator(const AltaricaModel* amodel);
|
||||
|
||||
~FiacreTranslator();
|
||||
|
||||
std::string getType(Value* dom);
|
||||
|
||||
std::ostringstream *fiacre() {return &os_;}
|
||||
void printFiacre();
|
||||
const AltaricaModel &model() {return *amodel_;}
|
||||
std::string makesUnion(const std::vector<std::string>* sym);
|
||||
std::string removeAmp(std::string &r);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FIACRETRANSLATOR_HH_ */
|
||||
110
src/grammars/altarica/LandmarkDriver.cc
Normal file
110
src/grammars/altarica/LandmarkDriver.cc
Normal file
@@ -0,0 +1,110 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "LandmarkDriver.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "LandmarkState.hh"
|
||||
#include "LandmarkMetaEvent.hh"
|
||||
#include "Values.hh"
|
||||
#include "iostream"
|
||||
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
LandmarkDriver::LandmarkDriver(AltaricaModel * amodel) {
|
||||
amodel_ = amodel;
|
||||
finalState_ = NULL;
|
||||
}
|
||||
|
||||
|
||||
void LandmarkDriver::computeLandmarks() {
|
||||
AltaricaState *init = amodel_->initialState();
|
||||
// AltaricaState *initialMacroState = init->getMacroState();
|
||||
std::cerr << "INIT STATE:" << init->toString(true,true,false,false);
|
||||
|
||||
LandmarkState * is = new LandmarkState(init);
|
||||
is->addSelfAsLabel();
|
||||
// std::cerr<<is->toString();
|
||||
|
||||
LandmarkState * currentState = is;
|
||||
LandmarkState * previousState = NULL;
|
||||
|
||||
int i = 0;
|
||||
while (!stablePlanningGraph(previousState,currentState)) {
|
||||
std::cout << "LEVEL IN PLANNINGGRAPH: " << i++ << "\n";
|
||||
previousState = currentState;
|
||||
currentState = new LandmarkState(previousState->getState()->clone());
|
||||
std::cout << "CURRENT STATE: " << currentState->getState()->toString(true,true,false,false) << "\n";
|
||||
|
||||
std::vector<MetaEvent*> * mevs = amodel_->getEnabledMetaEventsAll(previousState->getState());
|
||||
int j=0;
|
||||
for (std::vector<MetaEvent*>::iterator mevi = mevs->begin(); mevi!= mevs->end(); ++mevi) {
|
||||
std::cout << "EVALUATING MEV: " << j++ << "\n";
|
||||
LandmarkMetaEvent * lmev = new LandmarkMetaEvent(*mevi, amodel_);
|
||||
lmev->computeLabels((const AltaricaModel*)amodel_, previousState);
|
||||
std::cout << "LANDMARK MEV\n" << lmev->toString();
|
||||
AltaricaState * cs = amodel_->getNextState(previousState->getState(), *mevi);
|
||||
//amodel_->evaluateFlowVars(cs);
|
||||
LandmarkState * tempState = new LandmarkState(cs);
|
||||
tempState->computeLabels((const AltaricaModel*) amodel_, previousState->getState(), lmev);
|
||||
//tempState->computeFlowLabels(amodel_);
|
||||
// std::cout << "TEMPSTATE\n" << tempState->toString();
|
||||
currentState->mergeIntersectLabels(tempState);
|
||||
cs->mergeToState(currentState->getState());
|
||||
// std::cout << "CURRENTSTATE INC\n" << currentState->toString();
|
||||
}
|
||||
if (currentState == NULL)
|
||||
currentState = previousState;
|
||||
else {
|
||||
currentState->addNoopLabels(previousState);
|
||||
// std::cout << "CURRENTSTATE AFTER NOOP\n" << currentState->toString();
|
||||
currentState->addSelfAsLabel();
|
||||
// std::cout << "CURRENTSTATE AFTER SELF\n" << currentState->toString();
|
||||
}
|
||||
std::cout << "CURRENTSTATE AT END\n" << currentState->toString();
|
||||
|
||||
|
||||
}
|
||||
finalState_ = currentState;
|
||||
// std::cout << "CURRENTSTATE AT END BEFORE REMOVESELF\n" << currentState->toString();
|
||||
// finalState_->removeSelfAsLabel();
|
||||
// std::cout << "CURRENTSTATE AT END AFTER REMOVESELF\n" << currentState->toString();
|
||||
finalState_->computeFlowLabels(amodel_);
|
||||
}
|
||||
|
||||
bool LandmarkDriver::stablePlanningGraph(LandmarkState *ps, LandmarkState*cs) {
|
||||
if (ps == NULL)
|
||||
return false;
|
||||
for (unsigned int i = 0; i<amodel_->getNStateVars(); ++i)
|
||||
if (!ps->getState()->getStateValue(i)->equals(cs->getState()->getStateValue(i)))
|
||||
return false;
|
||||
for (unsigned int i = 0; i<amodel_->getNFlowVars(); ++i)
|
||||
if (ps->getState()->getFlowValue(i) != NULL && cs->getState()->getFlowValue(i) != NULL)
|
||||
if (!ps->getState()->getFlowValue(i)->equals(cs->getState()->getFlowValue(i)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
54
src/grammars/altarica/LandmarkDriver.hh
Normal file
54
src/grammars/altarica/LandmarkDriver.hh
Normal file
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef LANDMARK_DRIVER_HH
|
||||
#define LANDMARK_DRIVER_HH
|
||||
|
||||
#include "LandmarkState.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Variable;
|
||||
class FixedValue;
|
||||
class LandmarkState;
|
||||
class AltaricaModel;
|
||||
class AltaricaState;
|
||||
|
||||
class LandmarkDriver {
|
||||
private:
|
||||
AltaricaModel* amodel_;
|
||||
bool stablePlanningGraph(LandmarkState *ps, LandmarkState*cs);
|
||||
LandmarkState * finalState_;
|
||||
|
||||
public:
|
||||
LandmarkDriver(AltaricaModel *amodel);
|
||||
void computeLandmarks();
|
||||
const LandmarkState* getAllLM() {return finalState_;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
104
src/grammars/altarica/LandmarkMetaEvent.cc
Normal file
104
src/grammars/altarica/LandmarkMetaEvent.cc
Normal file
@@ -0,0 +1,104 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "LandmarkMetaEvent.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "LandmarkState.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "expressions/Expression.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Values.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
LandmarkMetaEvent::LandmarkMetaEvent(MetaEvent *me, AltaricaModel *am) {
|
||||
me_ = me;
|
||||
am_ = am;
|
||||
label_ = new AltaricaState(false,am_,am_->getInitInfo());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LandmarkMetaEvent::addLabel(const AltaricaState * l) {
|
||||
l->mergeToState(label_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string LandmarkMetaEvent::toString() const {
|
||||
std::string s;
|
||||
s += me_->toString();
|
||||
s += "LABELS :\n";
|
||||
s += label_->toString(true,false,false,false);
|
||||
return s;
|
||||
}
|
||||
|
||||
void LandmarkMetaEvent::computeLabels(const AltaricaModel*am, const LandmarkState *als) {
|
||||
|
||||
std::vector<bool> varInPreconds(am_->getNStateVars(), false);
|
||||
|
||||
const std::vector<Event*> * evs = me_->getEvents();
|
||||
for (std::vector<Event*>::const_iterator evi = evs->begin(); evi != evs->end(); ++evi) {
|
||||
const std::vector<Transition*> * trans = (*evi)->getTrans();
|
||||
for (std::vector<Transition*>::const_iterator ti = trans->begin(); ti != trans->end(); ++ti) {
|
||||
const Expression * precond = (*ti)->getPrecond();
|
||||
std::vector<Variable*> * newvars = precond->infoVars(am, (*ti)->getNode(), false, false);
|
||||
for (std::vector<Variable*>::iterator nvi = newvars->begin(); nvi != newvars->end(); ++nvi) {
|
||||
varInPreconds[(*nvi)->getIndex()] = true;
|
||||
}
|
||||
delete newvars;
|
||||
}
|
||||
}
|
||||
|
||||
// pour chaque var à true, on prend une seule valeur, et le reste change pas,
|
||||
// si mev valide, on ajoute les labels de cette valeur (addLabel)
|
||||
// vrai car on fait l'union des labels: si une valeur d'une var d'une précond est ok, alors son
|
||||
// label sera dans le label final
|
||||
|
||||
AltaricaState *as = als->getState()->clone();
|
||||
|
||||
for (int i =0; i<am_->getNStateVars(); ++i) {
|
||||
if (varInPreconds[i]) {
|
||||
Value *v = as->getStateValue(i);
|
||||
std::vector<Value*> *afv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator fvi = afv->begin(); fvi!= afv->end(); ++fvi) {
|
||||
// on teste une des valeurs possibles pour la variable
|
||||
as->setStateValue(i,*fvi);
|
||||
if (me_->isEnabled(am, as)) {
|
||||
addLabel(als->getLabel(i, *fvi));
|
||||
}
|
||||
}
|
||||
as->setStateValue(i,v);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
65
src/grammars/altarica/LandmarkMetaEvent.hh
Normal file
65
src/grammars/altarica/LandmarkMetaEvent.hh
Normal file
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef LANDMARK_METAEVENT_HH
|
||||
#define LANDMARK_METAEVENT_HH
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class MetaEvent;
|
||||
class LandmarkState;
|
||||
class AltaricaState;
|
||||
|
||||
class LandmarkMetaEvent {
|
||||
|
||||
private:
|
||||
MetaEvent *me_;
|
||||
AltaricaModel *am_;
|
||||
AltaricaState *label_;
|
||||
|
||||
public:
|
||||
LandmarkMetaEvent(MetaEvent *me, AltaricaModel *m);
|
||||
const MetaEvent * getMetaEvent() const {return me_;}
|
||||
|
||||
void addLabel(const AltaricaState * l);
|
||||
|
||||
const AltaricaState* getLabel() const {return label_;}
|
||||
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
void computeLabels(const AltaricaModel*am, const LandmarkState *als);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
269
src/grammars/altarica/LandmarkState.cc
Normal file
269
src/grammars/altarica/LandmarkState.cc
Normal file
@@ -0,0 +1,269 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "LandmarkState.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "AltaricaModel.hh"
|
||||
#include "LandmarkMetaEvent.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "Values.hh"
|
||||
#include "iostream"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
LandmarkState::LandmarkState(AltaricaState *as) {
|
||||
as_ = as;
|
||||
labels_ = new labelsType(as->getAModel()->getNStateVars(), NULL);
|
||||
flowLabels_ = new labelsType(as->getAModel()->getNFlowVars(), NULL);
|
||||
}
|
||||
|
||||
void LandmarkState::addSelfAsLabel() {
|
||||
for (unsigned int i = 0; i<labels_->size(); ++i) {
|
||||
if ((*labels_)[i] == NULL) {
|
||||
(*labels_)[i] = new std::map<Value*, AltaricaState*, ValueComparator>();
|
||||
}
|
||||
Value *v = as_->getStateValue(i);
|
||||
if (v != NULL) {
|
||||
std::vector<Value*> * vfv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator j = vfv->begin(); j!= vfv->end(); ++j) {
|
||||
if ((*labels_)[i]->find(*j) == (*labels_)[i]->end())
|
||||
(*(*labels_)[i])[*j] = new AltaricaState(false, as_->getAModel(),as_->getAModel()->getInitInfo());
|
||||
(*(*labels_)[i])[*j]->addStateValue(i, *j);
|
||||
(*j)->own();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LandmarkState::removeSelfAsLabel() {
|
||||
for (unsigned int i = 0; i<labels_->size(); ++i) {
|
||||
Value *v = as_->getStateValue(i);
|
||||
if (v != NULL) {
|
||||
std::vector<Value*> * vfv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator j = vfv->begin(); j!= vfv->end(); ++j) {
|
||||
if ((*labels_)[i]->find(*j) != (*labels_)[i]->end()) {
|
||||
AltaricaState * lm = (*(*labels_)[i])[*j];
|
||||
lm->removeValue(i, *j);
|
||||
if (lm->isEmpty()) {
|
||||
delete lm;
|
||||
((*labels_)[i])->erase(*j);
|
||||
// (*(*labels_)[i])[*j] = NULL;
|
||||
}
|
||||
}
|
||||
// (*j)->own();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LandmarkState::addLabel(unsigned int i, Value* v, const AltaricaState* label) {
|
||||
if ((*labels_)[i] == NULL) {
|
||||
(*labels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>();
|
||||
(*((*labels_)[i]))[v] = label->clone();
|
||||
} else {
|
||||
std::map<labelsKeyType, AltaricaState*, ValueComparator>::iterator j = (*labels_)[i]->find(v);
|
||||
if (j == (*labels_)[i]->end())
|
||||
(*((*labels_)[i]))[v] = label->clone();
|
||||
else
|
||||
label->mergeToState(j->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LandmarkState::addNoopLabels(LandmarkState *ps) {
|
||||
for (unsigned int i =0; i<labels_->size(); ++i) {
|
||||
Value *v = as_->getStateValue(i);
|
||||
Value *vps = ps->getState()->getStateValue(i);
|
||||
if (v != NULL && vps != NULL) {
|
||||
std::vector<Value*> *vfv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator j = vfv->begin(); j!= vfv->end(); ++j) {
|
||||
if ((*labels_)[i] != NULL)
|
||||
if ((*labels_)[i]->find(*j) != (*labels_)[i]->end())
|
||||
(*(*labels_)[i])[*j]->mergeIntersectState(ps->getLabel(i,*j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AltaricaState* LandmarkState::getLabel(Variable* v, Value *fv) const {
|
||||
if (v->isFlow())
|
||||
return getFlowLabel(v->getIndex(), fv);
|
||||
return getLabel(v->getIndex(), fv);
|
||||
|
||||
}
|
||||
|
||||
AltaricaState* LandmarkState::getLabel(unsigned int i, Value *fv) const {
|
||||
if ((*labels_)[i] == NULL)
|
||||
return NULL;
|
||||
if ((*labels_)[i]->find(fv) == (*labels_)[i]->end())
|
||||
return NULL;
|
||||
return (*(*labels_)[i])[fv];
|
||||
}
|
||||
|
||||
|
||||
AltaricaState* LandmarkState::getFlowLabel(unsigned int i, Value *fv) const {
|
||||
if ((*flowLabels_)[i] == NULL)
|
||||
return NULL;
|
||||
if ((*flowLabels_)[i]->find(fv) == (*flowLabels_)[i]->end())
|
||||
return NULL;
|
||||
return (*(*flowLabels_)[i])[fv];
|
||||
}
|
||||
|
||||
|
||||
std::string LandmarkState::toString() const {
|
||||
std::string s;
|
||||
s += as_->toString(true,true,false,false);
|
||||
s += "LABELS :\n";
|
||||
for (unsigned int i = 0; i<labels_->size(); ++i) {
|
||||
if (as_->getStateValue(i) != NULL) {
|
||||
if ((*labels_)[i] != NULL)
|
||||
for (std::map<labelsKeyType, AltaricaState*>::const_iterator j = (*labels_)[i]->begin(); j!= (*labels_)[i]->end(); ++j) {
|
||||
s += "STATE VAR:" + as_->getAModel()->getStateVar(i)->toString() + "/" + j->first->toString() + " : \n" ;
|
||||
s += j->second->toString(true,false,false,false) ;
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned int i = 0; i<flowLabels_->size(); ++i) {
|
||||
if (as_->getFlowValue(i) != NULL) {
|
||||
if ((*flowLabels_)[i] != NULL)
|
||||
for (std::map<labelsKeyType, AltaricaState*>::const_iterator j = (*flowLabels_)[i]->begin(); j!= (*flowLabels_)[i]->end(); ++j) {
|
||||
s += "FLOW VAR:" + as_->getAModel()->getFlowVar(i)->toString() + "/" + j->first->toString() + " : \n" ;
|
||||
if (j->second != NULL)
|
||||
s += j->second->toString(true,false,false,false) ;
|
||||
s+= "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void LandmarkState::computeLabels(const AltaricaModel *am, const AltaricaState *ps, LandmarkMetaEvent *la) {
|
||||
|
||||
// as_ is current macro state
|
||||
|
||||
std::vector<std::vector<Value*> *> assigned(ps->getAModel()->getNStateVars(), NULL);
|
||||
AltaricaState * ts = ps->clone();
|
||||
|
||||
// we replay the transition to see what values are created by it
|
||||
|
||||
const std::vector<Event*> *evs = la->getMetaEvent()->getEvents();
|
||||
|
||||
for (std::vector<Event*>::const_iterator evi = evs->begin(); evi!= evs->end(); ++evi) {
|
||||
const std::vector<Transition*> * trans = (*evi)->getTrans();
|
||||
for (std::vector<Transition*>::const_iterator transi = trans->begin(); transi!=trans->end(); ++transi) {
|
||||
const std::vector<Assignment*> * assigns = (*transi)->getAssigns();
|
||||
for (std::vector<Assignment*>::const_iterator assi = assigns->begin(); assi!= assigns->end(); ++assi) {
|
||||
//assigned[(*k)->getVar()->getIndex()] = true;
|
||||
Value * v = (*assi)->evaluate(am, ts);
|
||||
std::vector<Value*> *afv = v->getSingletons();
|
||||
for (std::vector<Value*>::iterator i = afv->begin(); i!= afv->end(); ++i) {
|
||||
if (assigned[(*assi)->getVar()->getIndex()] == NULL)
|
||||
assigned[(*assi)->getVar()->getIndex()] = new std::vector<Value*>();
|
||||
assigned[(*assi)->getVar()->getIndex()]->push_back(*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for each of values created by the transition, we add transition label
|
||||
|
||||
for (unsigned int i = 0; i<ps->getAModel()->getNStateVars(); ++i) {
|
||||
if (assigned[i]!=NULL) {
|
||||
for (std::vector<Value*>::iterator j = assigned[i]->begin(); j!= assigned[i]->end(); ++j)
|
||||
addLabel(i,(Value*)*j, la->getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LandmarkState::mergeIntersectLabels(const LandmarkState * os) {
|
||||
const labelsType * l = os->getLabels();
|
||||
for (unsigned int i =0; i<labels_->size(); ++i) {
|
||||
if ((*labels_)[i] == NULL) {
|
||||
if (((*l)[i])!=NULL)
|
||||
(*labels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>(*((*l)[i]));
|
||||
else
|
||||
(*labels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>();
|
||||
} else {
|
||||
if ((*l)[i]!=NULL)
|
||||
for (std::map<Value*, AltaricaState*,ValueComparator>::iterator
|
||||
j = (*l)[i]->begin(); j!= (*l)[i]->end(); ++j) {
|
||||
if ((*labels_)[i]->find(j->first) == (*labels_)[i]->end())
|
||||
(*(*labels_)[i])[j->first] = j->second->clone();
|
||||
else
|
||||
(*(*labels_)[i])[j->first]->intersectState(j->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
l = os->getFlowLabels();
|
||||
for (unsigned int i =0; i<flowLabels_->size(); ++i) {
|
||||
if ((*flowLabels_)[i] == NULL) {
|
||||
if (((*l)[i])!=NULL)
|
||||
(*flowLabels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>(*((*l)[i]));
|
||||
else
|
||||
(*flowLabels_)[i] = new std::map<labelsKeyType, AltaricaState*, ValueComparator>();
|
||||
} else {
|
||||
if ((*l)[i]!=NULL)
|
||||
for (std::map<Value*, AltaricaState*,ValueComparator>::iterator
|
||||
j = (*l)[i]->begin(); j!= (*l)[i]->end(); ++j) {
|
||||
if ((*flowLabels_)[i]->find(j->first) == (*flowLabels_)[i]->end())
|
||||
(*(*flowLabels_)[i])[j->first] = j->second->clone();
|
||||
else
|
||||
(*(*flowLabels_)[i])[j->first]->intersectState(j->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LandmarkState::computeFlowLabels(const AltaricaModel *am) {
|
||||
unsigned int nfv = am->getNFlowVars();
|
||||
as_->deleteFlowValues();
|
||||
for (unsigned int i = 0; i<nfv; ++i) {
|
||||
Variable *v = am->getFlowVar(i);
|
||||
v->evaluateLM(am, this);
|
||||
std::cout << this->toString();
|
||||
}
|
||||
|
||||
}
|
||||
95
src/grammars/altarica/LandmarkState.hh
Normal file
95
src/grammars/altarica/LandmarkState.hh
Normal file
@@ -0,0 +1,95 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef LANDMARK_STATE_HH
|
||||
#define LANDMARK_STATE_HH
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Values.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaModel;
|
||||
class AltaricaState;
|
||||
class Variable;
|
||||
class LandmarkMetaEvent;
|
||||
class Value;
|
||||
|
||||
typedef Value* labelsKeyType;
|
||||
|
||||
|
||||
class ValueComparator {
|
||||
public:
|
||||
bool operator() (const labelsKeyType& a, const labelsKeyType& b) const {
|
||||
return a->less(b);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<Value*, AltaricaState*, ValueComparator> landmarkType;
|
||||
|
||||
typedef std::vector<landmarkType*> labelsType;
|
||||
|
||||
|
||||
// for each variable (vector) a map between a value and corresponding labels
|
||||
|
||||
class LandmarkState {
|
||||
|
||||
|
||||
private:
|
||||
AltaricaState *as_;
|
||||
labelsType *labels_;
|
||||
labelsType *flowLabels_;
|
||||
|
||||
public:
|
||||
LandmarkState(AltaricaState *as);
|
||||
AltaricaState * getState() const {return as_;}
|
||||
void addSelfAsLabel();
|
||||
void removeSelfAsLabel();
|
||||
// void addLabel(labelsType *l);
|
||||
void addLabel(unsigned int i, Value* v, const AltaricaState* label);
|
||||
void addNoopLabels(LandmarkState *ps);
|
||||
|
||||
// return NULL if no label
|
||||
AltaricaState* getLabel(Variable* v, Value *fv) const ;
|
||||
AltaricaState* getLabel(unsigned int i, Value *fv) const ;
|
||||
AltaricaState* getFlowLabel(unsigned int i, Value *fv) const ;
|
||||
labelsType * getLabels() const {return labels_;}
|
||||
labelsType * getFlowLabels() const {return flowLabels_;}
|
||||
|
||||
void computeLabels(const AltaricaModel*am, const AltaricaState *ps, LandmarkMetaEvent *la);
|
||||
void computeFlowLabels(const AltaricaModel*am);
|
||||
void mergeIntersectLabels(const LandmarkState *os);
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
458
src/grammars/altarica/MemberAccess.cc
Normal file
458
src/grammars/altarica/MemberAccess.cc
Normal file
@@ -0,0 +1,458 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MemberAccess.hh"
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Ident::~Ident() {
|
||||
}
|
||||
|
||||
MemberAccess::MemberAccess(){
|
||||
isGlobal_ = false;
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MemberAccess::MemberAccess(std::string id, std::vector<int> *v) {
|
||||
isGlobal_ = false;
|
||||
Ident* i = new Ident();
|
||||
i->id = id;
|
||||
for (std::vector<int>::iterator j = v->begin(); j != v->end(); ++j)
|
||||
i->indexes.push_back(*j);
|
||||
// i->indexes = v;
|
||||
path_.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
MemberAccess::MemberAccess(std::string id) {
|
||||
isGlobal_ = false;
|
||||
std::istringstream iss(id);
|
||||
std::string slice;
|
||||
bool first = true;
|
||||
|
||||
while (std::getline(iss,slice,'.')) {
|
||||
Ident* i = new Ident();
|
||||
boost::char_separator<char> sep("[]");
|
||||
boost::tokenizer<boost::char_separator<char> > tok(slice, sep);
|
||||
i->id = *(tok.begin());
|
||||
if (first && i->id.compare("main") == 0)
|
||||
isGlobal_ = true;
|
||||
first = false;
|
||||
|
||||
// i->indexes = new std::vector<int>();
|
||||
for (boost::tokenizer<boost::char_separator<char> >::const_iterator j = ++tok.begin();
|
||||
j != tok.end(); ++j)
|
||||
i->indexes.push_back(atoi((*j).c_str()));
|
||||
path_.push_back(i);
|
||||
}
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::addIdBack(std::string id) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
path_.push_back(nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
void MemberAccess::addIdBack(std::string id, std::vector<int> &iv) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
for (std::vector<int>::iterator i = iv.begin(); i!=iv.end(); ++i)
|
||||
nap->indexes.push_back(*i);
|
||||
path_.push_back(nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdBackNoString(std::string id, std::vector<int> &iv) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
for (std::vector<int>::iterator i = iv.begin(); i!=iv.end(); ++i)
|
||||
nap->indexes.push_back(*i);
|
||||
// nap->indexes = iv;
|
||||
path_.push_back(nap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::addIdBack(std::string id, int i) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
nap->indexes.push_back(i);
|
||||
path_.push_back(nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdFront(std::string id) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
path_.insert(path_.begin(),nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdFront(std::string id, std::vector<int> &iv) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
for (std::vector<int>::iterator i = iv.begin(); i!=iv.end(); ++i)
|
||||
nap->indexes.push_back(*i);
|
||||
// nap->indexes = iv;
|
||||
path_.insert(path_.begin(),nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdFront(std::string id, int i) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = id;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
nap->indexes.push_back(i);
|
||||
path_.insert(path_.begin(),nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::removeIdFront() {
|
||||
Ident * a= path_[0];
|
||||
path_.erase(path_.begin());
|
||||
delete a;
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::removeIdFrontNoString() {
|
||||
Ident * a= path_[0];
|
||||
path_.erase(path_.begin());
|
||||
delete a;
|
||||
}
|
||||
|
||||
|
||||
bool MemberAccess::removeIdFront(std::string id) {
|
||||
if (id.compare(path_[0]->id)!= 0)
|
||||
return false;
|
||||
removeIdFront();
|
||||
return true;
|
||||
doString();
|
||||
}
|
||||
|
||||
bool MemberAccess::removeIdFront(std::string id, std::vector<int> *iv) {
|
||||
Ident * a = path_[0];
|
||||
if ((!sameIndexes(iv, &a->indexes)) || (id.compare(a->id)!= 0))
|
||||
return false;
|
||||
removeIdFront();
|
||||
doString();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemberAccess::removeIdFrontNoString(std::string id, std::vector<int> *iv) {
|
||||
Ident * a = path_[0];
|
||||
if ((!sameIndexes(iv, &a->indexes)) || (id.compare(a->id)!= 0))
|
||||
return false;
|
||||
removeIdFrontNoString();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::addIndexBack(int i) {
|
||||
path_[path_.size()-1]->indexes.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexesBack(std::vector<int> *iv){
|
||||
for (std::vector<int>::iterator i = iv->begin();
|
||||
i != iv->end(); ++i)
|
||||
addIndexBack(*i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexFront(int i) {
|
||||
path_[0]->indexes.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexesFront(std::vector<int> *iv) {
|
||||
for (std::vector<int>::iterator i = iv->begin();
|
||||
i != iv->end(); ++i)
|
||||
addIndexFront(*i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndex(std::string id, int i) {
|
||||
for (std::vector<Ident*>::iterator pi = path_.begin();
|
||||
pi != path_.end(); ++pi) {
|
||||
if ((*pi)->id.compare(id)==0) {
|
||||
(*pi)->indexes.push_back(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexes(std::string id, std::vector<int> *v) {
|
||||
for (std::vector<Ident*>::iterator pi = path_.begin();
|
||||
pi != path_.end(); ++pi) {
|
||||
if ((*pi)->id.compare(id)==0) {
|
||||
for (std::vector<int>::iterator vi = v->begin(); vi != v->end(); ++vi)
|
||||
(*pi)->indexes.push_back(*vi);
|
||||
return;
|
||||
}
|
||||
}
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIndexSecond(int i) {
|
||||
if (path_[0]->indexes.size() != 0)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("wrong logic in member access name while flattening array domain")));
|
||||
path_[0]->indexes.push_back(i);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addIdSecond(std::string s) {
|
||||
Ident * nap = new Ident();
|
||||
nap->id = s;
|
||||
// nap->indexes = new std::vector<int>();
|
||||
path_.insert(++path_.begin(), nap);
|
||||
doString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MemberAccess::setGlobal(bool b) {
|
||||
isGlobal_ = b;
|
||||
}
|
||||
|
||||
bool MemberAccess::isGlobal() const {
|
||||
return isGlobal_;
|
||||
}
|
||||
|
||||
MemberAccess* MemberAccess::clone() const{
|
||||
MemberAccess * n = new MemberAccess();
|
||||
for (std::vector<Ident*>::const_iterator i = path_.begin(); i!= path_.end(); ++i)
|
||||
n->addIdBackNoString(std::string((*i)->id), (*i)->indexes);
|
||||
n->setGlobal(isGlobal_);
|
||||
n->doString();
|
||||
return n;
|
||||
}
|
||||
|
||||
const std::vector<Ident*> * MemberAccess::getAccesses() const {
|
||||
return &path_;
|
||||
}
|
||||
|
||||
void MemberAccess::addMemberAccessBack(MemberAccess *ma) {
|
||||
for (std::vector<Ident*>::const_iterator i = ma->getAccesses()->begin();
|
||||
i!= ma->getAccesses()->end(); ++i)
|
||||
addIdBack((*i)->id, (*i)->indexes);
|
||||
doString();
|
||||
}
|
||||
|
||||
void MemberAccess::addMemberAccessFront(MemberAccess *ma) {
|
||||
for (std::vector<Ident*>::const_iterator i = ma->getAccesses()->begin();
|
||||
i!= ma->getAccesses()->end(); ++i)
|
||||
addIdFront((*i)->id, (*i)->indexes);
|
||||
doString();
|
||||
}
|
||||
|
||||
bool MemberAccess::sameIndexes(const std::vector<int> * ind1, const std::vector<int> * ind2) {
|
||||
if (ind1 == NULL)
|
||||
return ind2 == NULL;
|
||||
else if (ind2 == NULL)
|
||||
return false;
|
||||
// if (ind1->size() == 0)
|
||||
// return (ind2->size() == 0);
|
||||
if (ind1->size() != ind2->size())
|
||||
return false;
|
||||
std::vector<int>::const_iterator i2 = ind2->begin();
|
||||
for (std::vector<int>::const_iterator i1 = ind1->begin(); i1 != ind1->end(); ++i1) {
|
||||
if (*i1 != *i2)
|
||||
return false;
|
||||
++i2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemberAccess::equals(const MemberAccess* ma) const {
|
||||
return (s_.compare(ma->toString()) == 0);
|
||||
// const std::vector<Ident*> * otherPath = ma->getAccesses();
|
||||
// if (otherPath->size() != path_.size())
|
||||
// return false;
|
||||
// std::vector<Ident*>::iterator i2 = path_.begin();
|
||||
// for (std::vector<Ident*>::const_iterator i1 = otherPath->begin(); i1 != otherPath->end(); ++i1, ++i2) {
|
||||
// if ((*i1)->id.compare((*i2)->id) != 0)
|
||||
// return false;
|
||||
// if (!sameIndexes((*i1)->indexes, (*i2)->indexes))
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MemberAccess * MemberAccess::buildSuffix(const MemberAccess *ma) const {
|
||||
// MemberAccess * nma = clone();
|
||||
// nma->setGlobal(false);
|
||||
// const std::vector<Ident*> * frontPath = ma->getAccesses();
|
||||
// for (std::vector<Ident*>::const_iterator i = frontPath->begin();
|
||||
// i != frontPath->end(); ++i)
|
||||
// if (!nma->removeIdFrontNoString((*i)->id, (*i)->indexes)) {
|
||||
// delete(nma);
|
||||
// return NULL;
|
||||
// }
|
||||
// nma->doString();
|
||||
// return nma;
|
||||
|
||||
const std::vector<Ident*> * frontPath = ma->getAccesses();
|
||||
int j = 0;
|
||||
for (std::vector<Ident*>::const_iterator i = frontPath->begin(); i != frontPath->end(); ++i) {
|
||||
Ident *ij = path_[j];
|
||||
if ((!sameIndexes(&ij->indexes, &(*i)->indexes)) || (ij->id.compare((*i)->id)!= 0))
|
||||
return NULL;
|
||||
++j;
|
||||
}
|
||||
MemberAccess *nma = new MemberAccess();
|
||||
for (; j<path_.size(); ++j) {
|
||||
nma->addIdBackNoString(std::string(path_[j]->id),path_[j]->indexes);
|
||||
}
|
||||
nma->doString();
|
||||
return nma;
|
||||
}
|
||||
|
||||
|
||||
void MemberAccess::addSimpleCombinationsRec(std::vector<int>* idx, std::vector<int>* maxidxs,
|
||||
std::vector<std::vector<int>*>* iidx) {
|
||||
if (maxidxs->size() == 0) {
|
||||
iidx->push_back(new std::vector<int>(*idx));
|
||||
} else {
|
||||
int m = maxidxs->front();
|
||||
maxidxs->erase(maxidxs->begin());
|
||||
for (int i = 0; i<m; ++i) {
|
||||
idx->push_back(i);
|
||||
addSimpleCombinationsRec(idx, maxidxs, iidx);
|
||||
idx->pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<int>*>* MemberAccess::buildSimpleCombinations(std::vector<int>* idxs) {
|
||||
std::vector<int> * idx = new std::vector<int>();
|
||||
std::vector<std::vector<int>*>* iidx = new std::vector<std::vector<int>*>();
|
||||
addSimpleCombinationsRec(idx, idxs, iidx);
|
||||
delete(idx);
|
||||
return iidx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<MemberAccess*> * MemberAccess::buildCombinations() {
|
||||
std::vector<MemberAccess*> * ret = new std::vector<MemberAccess*>();
|
||||
ret->push_back(new MemberAccess());
|
||||
|
||||
for (std::vector<Ident*>::iterator api = path_.begin(); api!= path_.end(); ++api) {
|
||||
Ident* ap = (*api);
|
||||
std::vector<std::vector<int>* > * comb = buildSimpleCombinations ( &ap->indexes );
|
||||
int ncomb = comb->size();
|
||||
int nma = ret->size();
|
||||
|
||||
|
||||
for (int i = 1; i<ncomb; ++i) {
|
||||
for (int j = 0; j<nma; ++j) {
|
||||
ret->push_back( ((*ret)[j])->clone());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i< ncomb; ++i) {
|
||||
for (int j= 0; j<nma; ++j) {
|
||||
(*ret)[i*nma+j]->addIdBack(ap->id, *((*comb)[i]));
|
||||
}
|
||||
delete (*comb)[i];
|
||||
}
|
||||
delete comb;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const std::string MemberAccess::getSymbol() const {
|
||||
return path_[0]->id;
|
||||
}
|
||||
|
||||
|
||||
void MemberAccess::toString_() {
|
||||
s_.clear();
|
||||
|
||||
for (std::vector<Ident*>::iterator ii = path_.begin(); ii != path_.end();) {
|
||||
s_+= (*ii)->id ;
|
||||
if ((*ii)->indexes.size() != 0)
|
||||
for (std::vector<int>::iterator iii = (*ii)->indexes.begin();
|
||||
iii != (*ii)->indexes.end(); ++iii) {
|
||||
s_+= "[";
|
||||
s_+= (*iii);
|
||||
s_+= "]";
|
||||
}
|
||||
if (++ii != path_.end())
|
||||
s_+= ".";
|
||||
}
|
||||
}
|
||||
|
||||
void MemberAccess::headToString_() {
|
||||
h_.clear();
|
||||
if (path_.size() == 0)
|
||||
return;
|
||||
h_+= path_[0]->id ;
|
||||
if (path_[0]->indexes.size() != 0)
|
||||
for (std::vector<int>::iterator iii = path_[0]->indexes.begin();
|
||||
iii != path_[0]->indexes.end(); ++iii) {
|
||||
h_+= "[";
|
||||
h_+= (*iii);
|
||||
h_+= "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MemberAccess::~MemberAccess() {
|
||||
for (std::vector<Ident*>::iterator i = path_.begin();
|
||||
i!= path_.end(); ++i)
|
||||
delete(*i);
|
||||
h_.clear();
|
||||
s_.clear();
|
||||
}
|
||||
|
||||
void MemberAccess::doString() {
|
||||
toString_();
|
||||
headToString_();
|
||||
}
|
||||
}
|
||||
}
|
||||
135
src/grammars/altarica/MemberAccess.hh
Normal file
135
src/grammars/altarica/MemberAccess.hh
Normal file
@@ -0,0 +1,135 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_MEMBER_ACCESS_H_
|
||||
#define ALTA_MEMBER_ACCESS_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Ident {
|
||||
public :
|
||||
std::string id;
|
||||
std::vector<int> indexes;
|
||||
~Ident();
|
||||
} ;
|
||||
|
||||
class MemberAccess {
|
||||
protected:
|
||||
std::vector<Ident*> path_;
|
||||
bool isGlobal_ ;
|
||||
std::string s_;
|
||||
std::string h_;
|
||||
const std::vector<Ident*> * getAccesses() const;
|
||||
|
||||
|
||||
void addSimpleCombinationsRec(std::vector<int>* idx, std::vector<int>* maxidxs,
|
||||
std::vector<std::vector<int>*>* iidx);
|
||||
std::vector<std::vector<int>*>* buildSimpleCombinations(std::vector<int>* idxs);
|
||||
void toString_();
|
||||
void headToString_();
|
||||
|
||||
|
||||
private:
|
||||
void addIdBackNoString(std::string id, std::vector<int> &iv);
|
||||
void removeIdFrontNoString();
|
||||
bool removeIdFrontNoString(std::string id, std::vector<int> *iv);
|
||||
public:
|
||||
|
||||
|
||||
//! empty constructor
|
||||
MemberAccess();
|
||||
~MemberAccess();
|
||||
|
||||
//! empty constructor with reservation
|
||||
MemberAccess(int n);
|
||||
|
||||
MemberAccess(std::string id, std::vector<int> *v);
|
||||
MemberAccess(std::string id);
|
||||
|
||||
|
||||
void addIdBack(std::string id);
|
||||
// void addIdBack(std::string id, std::vector<int> *iv);
|
||||
void addIdBack(std::string id, std::vector<int> &iv);
|
||||
|
||||
void addIdBack(std::string id, int i);
|
||||
|
||||
void addIdFront(std::string id);
|
||||
void addIdFront(std::string id, std::vector<int> &iv);
|
||||
void addIdFront(std::string id, int i);
|
||||
void removeIdFront();
|
||||
|
||||
bool removeIdFront(std::string id);
|
||||
bool removeIdFront(std::string id, std::vector<int> *iv);
|
||||
|
||||
|
||||
|
||||
|
||||
void addIndexBack(int i);
|
||||
void addIndexesBack(std::vector<int> *iv);
|
||||
|
||||
void addIndexFront(int i);
|
||||
void addIndexesFront(std::vector<int> *iv);
|
||||
|
||||
void addIndexSecond(int i);
|
||||
void addIdSecond(std::string s);
|
||||
|
||||
void addIndex(std::string id, int i);
|
||||
void addIndexes(std::string id, std::vector<int> *iv);
|
||||
|
||||
void setGlobal(bool b);
|
||||
bool isGlobal() const;
|
||||
|
||||
//! join two memberAcesses
|
||||
void addMemberAccessBack(MemberAccess *ma);
|
||||
void addMemberAccessFront(MemberAccess *ma);
|
||||
|
||||
MemberAccess * buildSuffix(const MemberAccess *ma) const;
|
||||
|
||||
bool equals(const MemberAccess* ma) const;
|
||||
|
||||
MemberAccess* clone() const;
|
||||
|
||||
static bool sameIndexes(const std::vector<int> * ind1, const std::vector<int> * ind2);
|
||||
|
||||
std::vector<MemberAccess*> * buildCombinations();
|
||||
|
||||
inline std::string toString() const {return s_;}
|
||||
|
||||
inline std::string headToString() const {return h_;}
|
||||
const std::string getSymbol() const;
|
||||
|
||||
void doString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
292
src/grammars/altarica/MetaEvent.cc
Normal file
292
src/grammars/altarica/MetaEvent.cc
Normal file
@@ -0,0 +1,292 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "MetaEvent.hh"
|
||||
#include "Event.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include <sstream>
|
||||
#include <cfloat>
|
||||
#include <iostream>
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
double MetaEvent::complementOthersProba(std::vector<const Event*> * allEvents, AltaricaModel *am, AltaricaState *as) {
|
||||
double proba = 1.0;
|
||||
for (std::vector<const Event*>::iterator i = allEvents->begin(); i!= allEvents->end(); ++i) {
|
||||
if (!containsE(*i))
|
||||
proba *= 1.0-(*i)->getLaw()->evalParam(am,as);
|
||||
}
|
||||
return proba;
|
||||
}
|
||||
|
||||
|
||||
void MetaEvent::push_back(Event *e) {
|
||||
events_->push_back(e);
|
||||
}
|
||||
|
||||
bool MetaEvent::containsE(const Event *e) const{
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i)
|
||||
if (e == *i)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
MetaEvent* MetaEvent::unionMetaEvents(std::vector<MetaEvent*> * metavec) {
|
||||
MetaEvent * unions = new MetaEvent();
|
||||
for (std::vector<MetaEvent*>::iterator si = metavec->begin(); si!=metavec->end(); ++si) {
|
||||
unions->add(*si);
|
||||
}
|
||||
return unions;
|
||||
}
|
||||
|
||||
bool MetaEvent::contains(const MetaEvent* mev) const
|
||||
{
|
||||
for (auto i:*mev->getEvents())
|
||||
if (!containsE(i))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MetaEvent::equals(const MetaEvent* mev) const
|
||||
{
|
||||
if (!contains(mev))
|
||||
return false;
|
||||
if (!mev->contains(this))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MetaEvent::addMEV(std::vector<MetaEvent*> * list, MetaEvent* mev)
|
||||
{
|
||||
for (auto i:*list)
|
||||
if (i->equals(mev))
|
||||
return false;
|
||||
list->push_back(mev);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<MetaEvent*>* MetaEvent::combineMetaEvents(std::vector<MetaEvent*> * metavec) {
|
||||
std::vector<MetaEvent*> * combined = new std::vector<MetaEvent*>();
|
||||
|
||||
while (!metavec->empty()) {
|
||||
MetaEvent * mev = metavec->back();
|
||||
metavec->pop_back();
|
||||
|
||||
if (combined->empty())
|
||||
combined->push_back(mev);
|
||||
else {
|
||||
std::vector<MetaEvent*> newMEVs;
|
||||
for (auto i:*combined) {
|
||||
if (!i->contains(mev)) {
|
||||
MetaEvent * nmev = i->clone();
|
||||
nmev->add(mev);
|
||||
newMEVs.push_back(nmev);
|
||||
}
|
||||
}
|
||||
for (auto i:newMEVs)
|
||||
if (!addMEV(combined, i))
|
||||
delete i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return combined;
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned int MetaEvent::size() {
|
||||
return events_->size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MetaEvent::eventIn(Event *e) {
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i)
|
||||
if (e == *i)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MetaEvent::add(MetaEvent* m) {
|
||||
bool changed = false;
|
||||
const std::vector<Event*> * otherE = m->getEvents();
|
||||
for (std::vector<Event*>::const_iterator i = otherE->begin(); i!= otherE->end(); ++i) {
|
||||
if (!eventIn(*i)) {
|
||||
events_->push_back(*i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<MetaEvent*>* MetaEvent::buildVec(std::vector<std::vector<Event*>*>* v) {
|
||||
std::vector<MetaEvent*>* ret = new std::vector<MetaEvent*>();
|
||||
for (std::vector<std::vector<Event*>*>::iterator i = v->begin(); i!= v->end(); ++i) {
|
||||
ret->push_back(new MetaEvent(*i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
MetaEvent::MetaEvent() {
|
||||
events_ = new std::vector<Event*>();
|
||||
}
|
||||
|
||||
MetaEvent::MetaEvent(std::vector<Event*> *v) {
|
||||
events_ = v;
|
||||
}
|
||||
|
||||
MetaEvent * MetaEvent::clone() const {
|
||||
MetaEvent * r = new MetaEvent();
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i)
|
||||
r->push_back(*i);
|
||||
r->setProba(proba_);
|
||||
r->setReward(reward_);
|
||||
return r;
|
||||
}
|
||||
|
||||
MetaEvent::~MetaEvent() {
|
||||
delete events_;
|
||||
}
|
||||
|
||||
int MetaEvent::comparePrioTo(MetaEvent* other) {
|
||||
bool meMorePrior = false;
|
||||
bool meLessPrior = false;
|
||||
const std::vector<Event*> * otherE= other->getEvents();
|
||||
|
||||
// first check if I have one event comparable
|
||||
for (std::vector<Event*>::const_iterator i = otherE->begin();
|
||||
meMorePrior == false && meLessPrior == false && i!= otherE->end(); ++i) {
|
||||
for (std::vector<Event*>::iterator j = events_->begin();
|
||||
meMorePrior == false && meLessPrior == false && j!= events_->end(); ++j) {
|
||||
if ((*j)->isMorePriorThan(*i))
|
||||
meMorePrior = true;
|
||||
if ((*j)->isLessPriorThan(*i))
|
||||
meLessPrior = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if incomparable, same prio
|
||||
if (!meLessPrior && !meMorePrior)
|
||||
return 0;
|
||||
|
||||
// if comparable,
|
||||
// now check that I do not have and opposite prio event
|
||||
// if so -> same prio
|
||||
if (meLessPrior || meMorePrior)
|
||||
for (std::vector<Event*>::const_iterator i = otherE->begin(); i!= otherE->end(); ++i) {
|
||||
for (std::vector<Event*>::iterator j = events_->begin(); j!= events_->end(); ++j) {
|
||||
if (meMorePrior && (*i)->isMorePriorThan(*j))
|
||||
return 0;
|
||||
if (meLessPrior && (*i)->isLessPriorThan(*j))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (meMorePrior)
|
||||
return 1;
|
||||
if (meLessPrior)
|
||||
return -1;
|
||||
|
||||
// never reached
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool MetaEvent::isEnabled(const AltaricaModel *am, AltaricaState *s) const {
|
||||
for (std::vector<Event*>::iterator ei = events_->begin(); ei != events_->end(); ++ei) {
|
||||
if (!(*ei)->isEnabled(am, s))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MetaEvent::isDirac() const {
|
||||
for (std::vector<Event*>::const_iterator i = events_->begin(); i!= events_->end(); ++i) {
|
||||
if ((*i)->getLaw() != NULL && (*i)->getLaw()->isDirac())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string MetaEvent::toString() {
|
||||
// std::string s;
|
||||
std::stringstream s;
|
||||
s << "MetaEvent: < p = ";
|
||||
s << proba_;
|
||||
s << " r = ";
|
||||
s << reward_;
|
||||
s << " ";
|
||||
if (events_->size() != 0)
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!=events_->end(); ++i)
|
||||
s << (*i)->toString();
|
||||
else
|
||||
s << " NO EVENT";
|
||||
s<< ">\n";
|
||||
return s.str();
|
||||
}
|
||||
|
||||
double MetaEvent::timesDiscreteProba(AltaricaModel *am, AltaricaState *as) {
|
||||
proba_ = 1.0;
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i) {
|
||||
if ((*i)->getLaw() != NULL)
|
||||
proba_ *= (*i)->getLaw()->evalParam(am,as);
|
||||
}
|
||||
return proba_;
|
||||
}
|
||||
double MetaEvent::timesDiscreteProba(double p) {
|
||||
proba_ *= p;
|
||||
return proba_;
|
||||
}
|
||||
|
||||
|
||||
void MetaEvent::setMaxContProba(AltaricaModel *am, AltaricaState *as) {
|
||||
proba_ = DBL_MIN;
|
||||
bool printed = true;
|
||||
for (std::vector<Event*>::iterator i = events_->begin(); i!= events_->end(); ++i) {
|
||||
if ((*i)->getLaw() != NULL) {
|
||||
if (proba_ != DBL_MIN) {
|
||||
if (!printed) {
|
||||
std::cerr<< "BIG FAT WARNING: >1 synchronised events have a continuous law: theoretical proba is 0........." << std::endl;
|
||||
std::cerr<< toString() << std::endl;
|
||||
printed = true;
|
||||
}
|
||||
}
|
||||
if ((*i)->getLaw()->evalParam(am,as) > proba_)
|
||||
proba_ = (*i)->getLaw()->evalParam(am,as);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/grammars/altarica/MetaEvent.hh
Normal file
89
src/grammars/altarica/MetaEvent.hh
Normal file
@@ -0,0 +1,89 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_MEV_HH
|
||||
#define ALTARICA_MEV_HH
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Event;
|
||||
|
||||
|
||||
//! meta event class : synchronised atomic events
|
||||
class MetaEvent {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Event*> *events_;
|
||||
double proba_;
|
||||
double reward_;
|
||||
|
||||
public:
|
||||
|
||||
MetaEvent();
|
||||
~MetaEvent();
|
||||
MetaEvent(std::vector<Event*> *v);
|
||||
void push_back(Event* e);
|
||||
bool containsE(const Event* e) const;
|
||||
unsigned int size();
|
||||
bool add(MetaEvent* m);
|
||||
std::vector<Event*> * getEvents() const {return events_;}
|
||||
int comparePrioTo(MetaEvent* other);
|
||||
bool eventIn(Event *e);
|
||||
double getProba() const {return proba_;}
|
||||
void setProba(double p) {proba_ = p;}
|
||||
double getReward() const {return reward_;}
|
||||
void setReward(double r) {reward_ = r;}
|
||||
double timesDiscreteProba(AltaricaModel *am, AltaricaState *as);
|
||||
double timesDiscreteProba(double p);
|
||||
double complementOthersProba(std::vector<const Event*> * allEvents, AltaricaModel *am, AltaricaState *as);
|
||||
void setMaxContProba(AltaricaModel *am, AltaricaState *as);
|
||||
MetaEvent * clone() const;
|
||||
inline bool isEmpty() {return events_->size() == 0;}
|
||||
|
||||
bool isEnabled(const AltaricaModel *am, AltaricaState *s) const;
|
||||
bool equals(const MetaEvent * mev) const;
|
||||
bool contains(const MetaEvent* mev) const ;
|
||||
|
||||
|
||||
bool isDirac() const;
|
||||
static MetaEvent* unionMetaEvents(std::vector<MetaEvent*> *metavec);
|
||||
static std::vector<MetaEvent*>* combineMetaEvents(std::vector<MetaEvent*> *metavec);
|
||||
static bool addMEV(std::vector<MetaEvent*> *list, MetaEvent *mev);
|
||||
static std::vector<MetaEvent*>* buildVec(std::vector<std::vector<Event*>*>* v);
|
||||
std::string toString();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
836
src/grammars/altarica/Node.cc
Normal file
836
src/grammars/altarica/Node.cc
Normal file
@@ -0,0 +1,836 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Node.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "Parameter.hh"
|
||||
#include "Variable.hh"
|
||||
#include "Event.hh"
|
||||
#include "Transition.hh"
|
||||
#include "Assertion.hh"
|
||||
#include "Synchronisation.hh"
|
||||
#include "EventLaw.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "domains/EnumDomain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Node::Node() {
|
||||
// name_ = NULL;
|
||||
ma_ = NULL;
|
||||
typeName_ =NULL;
|
||||
events_by_prio_ = NULL;
|
||||
parent_ = NULL;
|
||||
}
|
||||
|
||||
Node * Node::clone() const {
|
||||
Node * n = new Node();
|
||||
n->setMA(ma_->clone());
|
||||
n->setTypeName(typeName_->clone());
|
||||
n->setParent(parent_);
|
||||
for(std::vector<std::string>::const_iterator it = attributes_.begin();
|
||||
it != attributes_.end(); ++it)
|
||||
n->addAttribute(*it);
|
||||
for(std::vector<Parameter*>::const_iterator it = params_.begin();
|
||||
it != params_.end(); ++it)
|
||||
n->addParam((*it)->clone());
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator it = stateVars_.begin();
|
||||
it != stateVars_.end(); ++it) {
|
||||
Variable * v = it->second->clone();
|
||||
n->addVariable(v);
|
||||
}
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator it = flowVars_.begin();
|
||||
it != flowVars_.end(); ++it) {
|
||||
Variable * v = it->second->clone();
|
||||
n->addVariable(v);
|
||||
}
|
||||
for(std::map<std::string,Event*,ltstr>::const_iterator it = events_.begin();
|
||||
it != events_.end(); ++it) {
|
||||
n->addEvent(it->second->clone());
|
||||
}
|
||||
for(std::vector<Transition*>::const_iterator it = trans_.begin();
|
||||
it != trans_.end(); ++it) {
|
||||
n->addTransition((*it)->clone());
|
||||
}
|
||||
for(std::vector<Assertion*>::const_iterator it = asserts_.begin();
|
||||
it != asserts_.end(); ++it)
|
||||
n->addAssertion((*it)->clone());
|
||||
for(std::map<std::string, Node*, ltstr>::const_iterator it = subNodes_.begin();
|
||||
it != subNodes_.end(); ++it)
|
||||
n->addSubNode(it->second->clone());
|
||||
for(std::vector<Synchronisation*>::const_iterator it = syncs_.begin();
|
||||
it != syncs_.end(); ++it)
|
||||
n->addSync((*it)->clone());
|
||||
for(std::vector<Assignment*>::const_iterator it = inits_.begin();
|
||||
it != inits_.end(); ++it)
|
||||
n->addInit((*it)->clone());
|
||||
for(std::vector<Assignment*>::const_iterator it = paramSets_.begin();
|
||||
it != paramSets_.end(); ++it)
|
||||
n->addParamsSet((*it)->clone());
|
||||
for(std::vector<std::string>::const_iterator it = externals_.begin();
|
||||
it != externals_.end(); ++it)
|
||||
n->addExternal(*it);
|
||||
// n->finalize(am);
|
||||
return n;
|
||||
}
|
||||
|
||||
void Node::setMA(std::string name, std::vector<int> * idxs) {
|
||||
if (ma_ != NULL)
|
||||
delete ma_;
|
||||
ma_ = new MemberAccess();
|
||||
ma_->addIdBack(name,*idxs);
|
||||
}
|
||||
|
||||
void Node::setMA(std::string name) {
|
||||
if (ma_ != NULL)
|
||||
delete ma_;
|
||||
ma_ = new MemberAccess(name);
|
||||
// ma_->addIdBack(name);
|
||||
}
|
||||
|
||||
void Node::setMA(MemberAccess* ma) {
|
||||
if (ma_ != NULL)
|
||||
delete ma_;
|
||||
ma_ = ma;
|
||||
}
|
||||
|
||||
|
||||
void Node::setParent(Node *n) {
|
||||
parent_ = n;
|
||||
}
|
||||
|
||||
const Node * Node::getParent() const{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
std::vector<const Node*>* Node::getPath() const {
|
||||
if(parent_ == NULL)
|
||||
return new std::vector<const Node*>();
|
||||
auto ret = parent_->getPath();
|
||||
ret->push_back(parent_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Node::getFullName() const {
|
||||
if(parent_ == NULL)
|
||||
return this->getMA()->toString();
|
||||
std::ostringstream oss;
|
||||
oss << parent_->getFullName()
|
||||
<< "."
|
||||
<< this->getMA()->toString();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void Node::addAttribute(const std::string a) {
|
||||
attributes_.push_back(std::string(a));
|
||||
}
|
||||
|
||||
void Node::addAttributes(const std::vector<std::string>* va) {
|
||||
for (std::vector<std::string>::const_iterator si = va->begin(); si != va->end(); ++si) {
|
||||
addAttribute(*si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Node::addParam(Parameter* p) {
|
||||
params_.push_back(p);
|
||||
}
|
||||
|
||||
void Node::addParams(std::vector<Parameter*>* p) {
|
||||
for (std::vector<Parameter*>::iterator pit = p->begin();
|
||||
pit != p->end(); ++pit)
|
||||
addParam(*pit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addVariable(Variable* v) {
|
||||
v->setNode(this);
|
||||
EnumDomain * ed = dynamic_cast<EnumDomain*>(v->getDomain());
|
||||
if (ed != NULL) {
|
||||
const std::vector<std::string> * sed = ed->getSymbols();
|
||||
for (std::vector<std::string>::const_iterator i = sed->begin(); i!= sed->end(); ++i)
|
||||
symbolCache_.insert(*i);
|
||||
}
|
||||
|
||||
std::vector<Variable*> *vars = v->flattenDomain();
|
||||
for (std::vector<Variable*>::iterator vi = vars->begin(); vi != vars->end(); ++vi)
|
||||
// vars_.push_back(*vi);
|
||||
if (v->isState())
|
||||
stateVars_[(*vi)->getMA()->toString()] = *vi;
|
||||
else
|
||||
flowVars_[(*vi)->getMA()->toString()] = *vi;
|
||||
delete(vars);
|
||||
}
|
||||
|
||||
void Node::addVariables(std::vector<Variable*>* v) {
|
||||
for (std::vector<Variable*>::iterator vit = v->begin();
|
||||
vit != v->end(); ++vit)
|
||||
addVariable(*vit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addEvent(Event* e) {
|
||||
e->setNode(this);
|
||||
// events_.push_back(e);
|
||||
events_[e->getMA()->toString()] = e;
|
||||
}
|
||||
|
||||
void Node::addEvents(std::vector<Event*>* e) {
|
||||
for (std::vector<Event*>::iterator eit = e->begin();
|
||||
eit != e->end(); ++eit)
|
||||
addEvent(*eit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addTransition(Transition* t) {
|
||||
t->setNode(this);
|
||||
trans_.push_back(t);
|
||||
}
|
||||
|
||||
void Node::addTransitions(std::vector<Transition*>* t) {
|
||||
for (std::vector<Transition*>::iterator tit = t->begin();
|
||||
tit != t->end(); ++tit)
|
||||
addTransition(*tit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addAssertion(Assertion *a) {
|
||||
a->setNode(this);
|
||||
asserts_.push_back(a);
|
||||
}
|
||||
|
||||
void Node::addAssertions(std::vector<Assertion*> *a) {
|
||||
for (std::vector<Assertion*>::iterator ait = a->begin();
|
||||
ait != a->end(); ++ait)
|
||||
addAssertion(*ait);
|
||||
}
|
||||
|
||||
|
||||
void Node::addSubNode(Node* n) {
|
||||
n->setParent(this);
|
||||
subNodes_[n->getMA()->toString()] = n;
|
||||
//subNodes_.push_back(n);
|
||||
}
|
||||
|
||||
void Node::addSubNodes(std::vector<Node*>* n) {
|
||||
for (std::vector<Node*>::iterator nit = n->begin();
|
||||
nit != n->end(); ++nit)
|
||||
addSubNode(*nit);
|
||||
}
|
||||
|
||||
|
||||
// void Node::addSubNode(Node* n, std::vector<int> *tab) {
|
||||
// if (tab == NULL)
|
||||
// subNodes_[n] = new std::vector<int>();
|
||||
// else
|
||||
// subNodes_[n] = new std::vector<int>(*tab);
|
||||
// }
|
||||
|
||||
// void Node::addSubNodes(std::vector<Node*>* n, std::vector<std::vector<int>*> *tab) {
|
||||
// std::vector<std::vector<int> * >::iterator tabit = tab->begin();
|
||||
// for (std::vector<Node*>::iterator nit = n->begin() ;
|
||||
// nit != n->end(); ++nit, ++tabit)
|
||||
// addSubNode(*nit, *tabit);
|
||||
// }
|
||||
|
||||
|
||||
void Node::addInit(Assignment* i) {
|
||||
Variable* var = findStateVariableByName(i->getMA());
|
||||
if(var == NULL) {
|
||||
std::cerr << "\nInit failed, variable not found : "
|
||||
<< i->getMA()->toString()
|
||||
<< std::endl;
|
||||
} else {
|
||||
var->setInit(i);
|
||||
i->setNode(this);
|
||||
inits_.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Node::addInits(std::vector<Assignment*>* i) {
|
||||
for (std::vector<Assignment*>::iterator iit = i->begin();
|
||||
iit != i->end(); ++iit)
|
||||
addInit(*iit);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Node::addParamsSet(Assignment* p) {
|
||||
paramSets_.push_back(p);
|
||||
}
|
||||
|
||||
void Node::addParamsSets(std::vector<Assignment*>* p) {
|
||||
for (std::vector<Assignment*>::iterator pit = p->begin();
|
||||
pit != p->end(); ++pit)
|
||||
addParamsSet(*pit);
|
||||
}
|
||||
|
||||
|
||||
void Node::addExternal(std::string e) {
|
||||
externals_.push_back(e);
|
||||
}
|
||||
|
||||
void Node::addExternals(std::vector<std::string>* e) {
|
||||
for (std::vector<std::string>::iterator eit = e->begin();
|
||||
eit != e->end(); ++eit)
|
||||
addExternal(*eit);
|
||||
}
|
||||
|
||||
void Node::addSync(Synchronisation* s) {
|
||||
s->setNode(this);
|
||||
syncs_.push_back(s);
|
||||
}
|
||||
|
||||
void Node::addSyncs(std::vector<Synchronisation*> *s) {
|
||||
for (std::vector<Synchronisation*>::iterator sit = s->begin();
|
||||
sit != s->end(); ++sit)
|
||||
addSync(*sit);
|
||||
}
|
||||
|
||||
void Node::addEventLaw(EventLaw* el) {
|
||||
Event * ev = findEventByName(el->getMA());
|
||||
el->setNode(this);
|
||||
if (ev != NULL)
|
||||
ev->setLaw(el);
|
||||
}
|
||||
|
||||
void Node::addEventLaws(std::vector<EventLaw*>* e) {
|
||||
for (std::vector<EventLaw*>::iterator eli = e->begin();
|
||||
eli != e->end(); ++eli)
|
||||
addEventLaw(*eli);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Node::hasName(std::string n) {
|
||||
MemberAccess * ma = new MemberAccess(n);
|
||||
|
||||
if (ma_->equals(ma)) {
|
||||
delete(ma);
|
||||
return true;
|
||||
} else {
|
||||
delete(ma);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Event * Node::findEventByName(const MemberAccess * eName) const {
|
||||
const MemberAccess * suffix = NULL;
|
||||
if (eName->isGlobal()) {
|
||||
suffix = eName->buildSuffix(ma_);
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
} else {
|
||||
suffix = eName;
|
||||
}
|
||||
|
||||
std::map<std::string, Event*, ltstr>::const_iterator i = events_.find(suffix->toString());
|
||||
if (i != events_.end())
|
||||
return i->second;
|
||||
|
||||
|
||||
|
||||
std::string head = suffix->headToString();
|
||||
std::map<std::string, Node*, ltstr>::const_iterator j = subNodes_.find(head);
|
||||
if (j == subNodes_.end())
|
||||
return NULL;
|
||||
MemberAccess * ma = suffix->buildSuffix(j->second->getMA());
|
||||
Event * e = j->second->findEventByName(ma);
|
||||
delete ma;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
Variable * Node::findStateVariableByName(const std::string& s) const {
|
||||
MemberAccess ma(s);
|
||||
Variable * v = findStateVariableByName(&ma);
|
||||
return v;
|
||||
}
|
||||
|
||||
Variable * Node::findFlowVariableByName(const std::string& s) const {
|
||||
MemberAccess ma(s);
|
||||
Variable * v = findFlowVariableByName(&ma);
|
||||
return v;
|
||||
}
|
||||
|
||||
Variable * Node::findVariableByName(const std::string& s) const {
|
||||
MemberAccess ma(s);
|
||||
Variable * v = findVariableByName(&ma);
|
||||
return v;
|
||||
}
|
||||
|
||||
bool Node::isSymbol(const MemberAccess *ma) const {
|
||||
std::set<std::string>::iterator si = symbolCache_.find(ma->toString());
|
||||
if (si != symbolCache_.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Node::isSymbol(std::string s) const {
|
||||
std::set<std::string>::iterator si = symbolCache_.find(s);
|
||||
if (si != symbolCache_.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Variable * Node::findStateVariableByName(const MemberAccess * eName) const {
|
||||
|
||||
|
||||
const MemberAccess * suffix = NULL;
|
||||
if (eName->isGlobal()) {
|
||||
suffix = eName->buildSuffix(ma_);
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
} else
|
||||
suffix = eName;
|
||||
|
||||
|
||||
std::map<std::string, Variable*, ltstr>::const_iterator i = stateVars_.find(suffix->toString());
|
||||
if (i != stateVars_.end())
|
||||
return i->second;
|
||||
|
||||
if (stateVarsCache_.size() != 0) {
|
||||
i = stateVarsCache_.find(suffix->toString());
|
||||
if (i != stateVarsCache_.end())
|
||||
return i->second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::map<std::string, Node*, ltstr>::const_iterator j = subNodes_.find(suffix->headToString());
|
||||
if (j == subNodes_.end()) {
|
||||
return NULL;
|
||||
}
|
||||
MemberAccess * ma = suffix->buildSuffix(j->second->getMA());
|
||||
Variable * v = j->second->findStateVariableByName(ma);
|
||||
delete ma;
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Variable * Node::findFlowVariableByName(const MemberAccess * eName) const {
|
||||
|
||||
bool delSuffix = false;
|
||||
|
||||
const MemberAccess * suffix = NULL;
|
||||
if (eName->isGlobal()) {
|
||||
suffix = eName->buildSuffix(ma_);
|
||||
delSuffix = true;
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
} else
|
||||
suffix = eName;
|
||||
|
||||
|
||||
std::map<std::string, Variable*, ltstr>::const_iterator i = flowVars_.find(suffix->toString());
|
||||
if (i != flowVars_.end()) {
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
if (flowVarsCache_.size() != 0) {
|
||||
i = flowVarsCache_.find(suffix->toString());
|
||||
if (i != flowVarsCache_.end()) {
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
return i->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, Node*, ltstr>::const_iterator j = subNodes_.find(suffix->headToString());
|
||||
if (j == subNodes_.end()) {
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
return NULL;
|
||||
}
|
||||
MemberAccess * ma = suffix->buildSuffix(j->second->getMA());
|
||||
Variable * v = j->second->findFlowVariableByName(ma);
|
||||
if (delSuffix)
|
||||
delete suffix;
|
||||
delete ma;
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Variable * Node::findVariableByName(const MemberAccess * eName) const {
|
||||
Variable *v = findFlowVariableByName(eName);
|
||||
if (v == NULL)
|
||||
return findStateVariableByName(eName);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
// const std::vector<Variable*>* Node::getVariables() {
|
||||
const std::map<std::string, Variable*, Node::ltstr> *
|
||||
Node::getStateVariables() const {
|
||||
return &stateVars_;
|
||||
}
|
||||
|
||||
|
||||
const std::map<std::string, Variable*, Node::ltstr> *
|
||||
Node::getFlowVariables() const {
|
||||
return &flowVars_;
|
||||
}
|
||||
|
||||
|
||||
// const std::vector<Event*>* Node::getEvents() {
|
||||
const std::map<std::string, Event*, Node::ltstr> *
|
||||
Node::getEvents() const {
|
||||
return &events_;
|
||||
}
|
||||
|
||||
const std::vector<Synchronisation*>* Node::getSyncs() const {
|
||||
return &syncs_;
|
||||
}
|
||||
const std::vector<Assertion*> *Node::getAsserts() const {
|
||||
return &asserts_;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Transition*>* Node::getTransitions() const {
|
||||
return &trans_;
|
||||
}
|
||||
|
||||
const std::map<std::string,Node*,Node::ltstr>* Node::getSubNodes() const {
|
||||
return &subNodes_;
|
||||
}
|
||||
|
||||
const MemberAccess * Node::getMA() const {
|
||||
return ma_;
|
||||
}
|
||||
|
||||
|
||||
void Node::buildEventsByPrio() {
|
||||
if (events_.size() == 0)
|
||||
return;
|
||||
std::vector<Event*> ev;
|
||||
if (events_by_prio_ == NULL)
|
||||
events_by_prio_ = new std::vector<std::vector<Event*>* >();
|
||||
for (std::map<std::string, Event*,ltstr>::iterator i = events_.begin(); i!=events_.end(); ++i)
|
||||
ev.push_back(i->second);
|
||||
// ev.insert(ev.begin(), events_.begin(), events_.end());
|
||||
|
||||
std::vector<Event*> *p0 = new std::vector<Event*>();
|
||||
std::vector<Event*>::iterator i = ev.begin();
|
||||
|
||||
while (i!= ev.end()) {
|
||||
if ((*i)->getUppers()->size() == 0) {
|
||||
p0->push_back(*i);
|
||||
i = ev.erase(i);
|
||||
} else
|
||||
++i;
|
||||
}
|
||||
events_by_prio_->push_back(p0);
|
||||
|
||||
while (ev.size() > 0) {
|
||||
std::vector<Event*> *pi = new std::vector<Event*>();
|
||||
i = ev.begin();
|
||||
while (i!=ev.end()) {
|
||||
if (notInEv((*i)->getUppers(),&events_)) {
|
||||
pi->push_back(*i);
|
||||
i = ev.erase(i);
|
||||
} else
|
||||
++i;
|
||||
}
|
||||
events_by_prio_->push_back(pi);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// bool Node::notInEv(std::set<Event*>const *up, std::vector<Event*> * ev) {
|
||||
bool Node::notInEv(std::set<Event*>const *up, std::map<std::string, Event*, Node::ltstr> * ev) {
|
||||
for (std::set<Event*>::iterator upi = up->begin(); upi != up->end(); ++upi) {
|
||||
// for (std::vector<Event*>::iterator evi = ev->begin(); evi != ev->end(); evi++)
|
||||
for (std::map<std::string, Event*, Node::ltstr>::iterator evi = ev->begin(); evi != ev->end(); evi++)
|
||||
if (*upi == evi->second)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Node::matchEventsInTransitions() {
|
||||
for (std::vector<Transition*>::iterator i = trans_.begin(); i!= trans_.end(); ++i) {
|
||||
(*i)->matchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Node::matchEventsInSynchros() {
|
||||
for (std::vector<Synchronisation*>::iterator i = syncs_.begin(); i!= syncs_.end(); ++i) {
|
||||
(*i)->matchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
// void Node::matchVariablesInInits() {
|
||||
// for (std::vector<Variable*>::iterator i = vars_.begin(); i!= vars_.end(); ++i) {
|
||||
// std::cerr << "var: " << *((*i)->getMA()->toString()) << std::endl;
|
||||
// }
|
||||
// for (std::vector<Assignment*>::iterator i = inits_.begin(); i!= inits_.end(); ++i) {
|
||||
// (*i)->matchVariable(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// To each variable is added the vector of the asserts that update its value
|
||||
void Node::matchVariablesInAsserts(const AltaricaModel* am) {
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!= asserts_.end(); ++i) {
|
||||
std::vector<Variable*> * fv = (*i)->infoVars(am, true, true);
|
||||
for (std::vector<Variable*>::iterator j = fv->begin(); j!= fv->end(); ++j) {
|
||||
std::cerr << "adding one assertion for node "<< toString() << " var: " << (*j)->getFullName() <<std::endl;
|
||||
(*j)->addAssert(*i);
|
||||
}
|
||||
delete fv;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Node::toString(bool withTypes) const {
|
||||
std::string s;
|
||||
if (parent_ != NULL)
|
||||
s += parent_->toString(withTypes) + ".";
|
||||
if (typeName_ != NULL && withTypes)
|
||||
s+= "(";
|
||||
s+= ma_->toString();
|
||||
if (typeName_!=NULL && withTypes)
|
||||
s+= ":" + typeName_->toString() + ")";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Node::toFiacre() const {
|
||||
std::string s;
|
||||
if (parent_ != NULL)
|
||||
s += parent_->toFiacre() + "_";
|
||||
s+= ma_->toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Node::printTrans() const {
|
||||
std::string s;
|
||||
s += "TRANSITIONS:\n";
|
||||
for (std::vector<Transition*>::const_iterator i = trans_.begin(); i!= trans_.end(); ++i) {
|
||||
s+= (*i)->toString() + "\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void Node::finalize(const AltaricaModel *am) {
|
||||
buildEventsByPrio();
|
||||
matchEventsInTransitions();
|
||||
matchEventsInSynchros();
|
||||
// matchVariablesInInits();
|
||||
matchVariablesInAsserts(am);
|
||||
|
||||
}
|
||||
|
||||
void Node::compactSimpleAsserts(const AltaricaModel *am) {
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!=asserts_.end();++i) {
|
||||
std::pair<Variable*,Variable*> * aff = (*i)->isSimpleAffect(am);
|
||||
if (aff != NULL) {
|
||||
// ++i;
|
||||
// else {
|
||||
// in this case, this assert is aff->first = aff->second
|
||||
// both being flow vars
|
||||
// std::cerr << "REMOVING ASSERTION:::: " <<aff->first->toString() << " = " << aff->second->toString()<< std::endl;
|
||||
aff->first->removeAssert(*i);
|
||||
// i = asserts_.erase(i);
|
||||
// ++i;
|
||||
std::vector<Node *> *n = (std::vector<Node *>*)aff->first->getNodes();
|
||||
aff->second->mergeVariable(aff->first);
|
||||
// Node * n = (Node*)aff->first->getNode();
|
||||
for (std::vector<Node*>::iterator j = n->begin(); j!=n->end(); ++j)
|
||||
(*j)->aliasVar(aff->first,aff->second);
|
||||
delete n;
|
||||
delete(aff->first);
|
||||
delete aff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Node::aliasVar(Variable* toRemove, Variable *mergedVar) {
|
||||
//std::vector<Variable*>::iterator i;
|
||||
std::map<std::string, Variable*, ltstr>::iterator i;
|
||||
|
||||
for (i = flowVars_.begin(); i!=flowVars_.end() && i->second != toRemove; ++i) ;
|
||||
if (i == flowVars_.end())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("unable to find var toremove!!!!!!!")));
|
||||
// *i = mergedVar;
|
||||
flowVars_[i->first] = mergedVar;
|
||||
// std::cerr << "AFTER: node var of node:" << this->toString() << std::endl;
|
||||
// for (std::vector<Variable*>::iterator j = vars_.begin(); j!=vars_.end(); ++j) {
|
||||
// std::cerr<< (*j)->toString() << std::endl;
|
||||
// }
|
||||
}
|
||||
|
||||
void Node::deleteExprs() {
|
||||
for (std::vector<Transition*>::iterator i = trans_.begin(); i!= trans_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!= asserts_.end(); ++i)
|
||||
(*i)->deleteExpr();
|
||||
for (std::vector<Assignment*>::iterator i = inits_.begin(); i!= inits_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
for (std::vector<Assignment*>::iterator i = paramSets_.begin(); i!= paramSets_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
for (std::map<std::string, Event*, ltstr>::iterator i = events_.begin(); i!= events_.end(); ++i)
|
||||
(*i).second->deleteExprs();
|
||||
}
|
||||
|
||||
Node::~Node() {
|
||||
// std::cerr << "\ndeleting node " << ma_->toString() << std::endl;
|
||||
for (std::map<std::string, Node*, ltstr>::iterator i = subNodes_.begin();
|
||||
i!= subNodes_.end(); ++i)
|
||||
delete i->second;
|
||||
delete ma_;
|
||||
delete typeName_;
|
||||
|
||||
|
||||
|
||||
for (std::map<std::string,Variable*,ltstr*>::iterator i = flowVars_.begin(); i!= flowVars_.end(); ++i) {
|
||||
if (i->second->removeOwner(this)) {
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (std::map<std::string,Variable*,ltstr>::iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for (std::vector<Event*>::iterator i = events_.begin(); i!= events_.end(); ++i)
|
||||
// delete *i;
|
||||
for (std::map<std::string,Event*,ltstr>::iterator i = events_.begin(); i!= events_.end(); ++i)
|
||||
delete i->second;
|
||||
for (std::vector<Transition*>::iterator i = trans_.begin(); i!= trans_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assertion*>::iterator i = asserts_.begin(); i!= asserts_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assignment*>::iterator i = inits_.begin();
|
||||
i!= inits_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assignment*>::iterator i = paramSets_.begin();
|
||||
i!= paramSets_.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
for (std::vector<Synchronisation*>::iterator i = syncs_.begin();
|
||||
i!= syncs_.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
attributes_.clear();
|
||||
externals_.clear();
|
||||
for (std::vector<Parameter*>::iterator i = params_.begin();
|
||||
i!= params_.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
if (events_by_prio_ != NULL)
|
||||
for (std::vector<std::vector<Event*>* >::iterator i = events_by_prio_->begin();
|
||||
i!= events_by_prio_->end(); ++i)
|
||||
delete (*i);
|
||||
|
||||
delete(events_by_prio_);
|
||||
}
|
||||
|
||||
void Node::addFlowVarToCache(Variable * v, MemberAccess *subMA, std::string vName) const {
|
||||
std::string s = subMA->toString() + "." + vName;
|
||||
// std::cout << "adding var " << s << " to node " << ma_->toString() << std::endl;
|
||||
flowVarsCache_[s] = v;
|
||||
if (parent_ != NULL) {
|
||||
subMA->addMemberAccessFront(ma_);
|
||||
parent_->addFlowVarToCache(v,subMA,vName);
|
||||
}
|
||||
}
|
||||
|
||||
void Node::addStateVarToCache(Variable * v, MemberAccess *subMA, std::string vName) const {
|
||||
std::string s = subMA->toString() + "." + vName;
|
||||
// std::cout << "adding var " << s << " to node " << ma_->toString() << std::endl;
|
||||
stateVarsCache_[s] = v;
|
||||
if (parent_ != NULL) {
|
||||
subMA->addMemberAccessFront(ma_);
|
||||
parent_->addStateVarToCache(v,subMA,vName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Node::populateVarCache() const {
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator i = stateVars_.begin(); i!= stateVars_.end(); ++i) {
|
||||
if (parent_ != NULL) {
|
||||
MemberAccess *ma = ma_->clone();
|
||||
parent_->addStateVarToCache(i->second, ma, i->first);
|
||||
delete ma;
|
||||
}
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * aliases =
|
||||
i->second->getAliases();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator j = aliases->begin();
|
||||
j!= aliases->end(); ++j) {
|
||||
MemberAccess * ma = (*j)->first->getMA()->clone();
|
||||
const Node * p = (*j)->first->getParent();
|
||||
p->addStateVarToCache(i->second,ma,(*j)->second->toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (std::map<std::string, Variable*, ltstr>::const_iterator i = flowVars_.begin(); i!= flowVars_.end(); ++i) {
|
||||
if (parent_ != NULL) {
|
||||
MemberAccess *ma = ma_->clone();
|
||||
parent_->addFlowVarToCache(i->second, ma, i->first);
|
||||
delete ma;
|
||||
}
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * aliases =
|
||||
i->second->getAliases();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator j = aliases->begin();
|
||||
j!= aliases->end(); ++j) {
|
||||
MemberAccess * ma = (*j)->first->getMA()->clone();
|
||||
const Node * p = (*j)->first->getParent();
|
||||
if (p!=NULL)
|
||||
p->addFlowVarToCache(i->second,ma,(*j)->second->toString());
|
||||
delete ma;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
206
src/grammars/altarica/Node.hh
Normal file
206
src/grammars/altarica/Node.hh
Normal file
@@ -0,0 +1,206 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_NODE_H_
|
||||
#define ALTA_NODE_H_
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Parameter;
|
||||
class Variable;
|
||||
class Event;
|
||||
class EventLaw;
|
||||
class Transition;
|
||||
class Expression;
|
||||
class Assignment;
|
||||
class Synchronisation;
|
||||
class Value;
|
||||
class Assertion;
|
||||
class MemberAccess;
|
||||
class AltaricaModel;
|
||||
|
||||
class Node {
|
||||
|
||||
public :
|
||||
struct ltstr {
|
||||
bool operator() (const std::string s1, const std::string s2) const {
|
||||
return s1.compare(s2) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
// std::string * name_;
|
||||
Node * parent_;
|
||||
MemberAccess* ma_;
|
||||
MemberAccess* typeName_;
|
||||
std::vector<std::string> attributes_;
|
||||
std::vector<Parameter*> params_;
|
||||
|
||||
// std::vector<Variable*> vars_;
|
||||
std::map<std::string,Variable*, ltstr> stateVars_;
|
||||
std::map<std::string,Variable*, ltstr> flowVars_;
|
||||
mutable std::map<std::string,Variable*, ltstr> stateVarsCache_;
|
||||
mutable std::map<std::string,Variable*, ltstr> flowVarsCache_;
|
||||
mutable std::set<std::string> symbolCache_;
|
||||
|
||||
// std::vector<Event*> events_;
|
||||
std::map<std::string, Event*, ltstr> events_;
|
||||
|
||||
std::vector<Transition*> trans_;
|
||||
std::vector<Assertion*> asserts_;
|
||||
//std::vector<Expression<OpenValue>*> asserts_;
|
||||
|
||||
std::map<std::string, Node*, ltstr> subNodes_;
|
||||
// std::vector<Node*> subNodes_;
|
||||
std::vector<Synchronisation*> syncs_;
|
||||
std::vector<Assignment*> inits_;
|
||||
std::vector<Assignment*> paramSets_;
|
||||
std::vector<std::string> externals_;
|
||||
|
||||
std::vector<std::vector<Event*>* > *events_by_prio_;
|
||||
|
||||
// bool notInEv(std::set<Event*>const *up, std::vector<Event*> * ev);
|
||||
bool notInEv(std::set<Event*>const *up, std::map<std::string,Event*,ltstr> * ev);
|
||||
void buildEventsByPrio();
|
||||
void matchEventsInTransitions();
|
||||
void matchEventsInSynchros();
|
||||
// void matchVariablesInInits();
|
||||
void matchVariablesInAsserts(const AltaricaModel *am);
|
||||
|
||||
unsigned int index_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
Node();
|
||||
~Node();
|
||||
|
||||
// void setName(std::string * name);
|
||||
void setMA(std::string name, std::vector<int> * idxs);
|
||||
void setMA(std::string name);
|
||||
void setMA(MemberAccess* ma);
|
||||
|
||||
void setTypeName(MemberAccess *ma) {typeName_ = ma;}
|
||||
const MemberAccess * getTypeName() const {return typeName_;}
|
||||
|
||||
void setParent(Node *n);
|
||||
const Node * getParent() const;
|
||||
std::vector<const Node*>* getPath() const;
|
||||
std::string getFullName() const;
|
||||
|
||||
void addAttribute(const std::string a);
|
||||
void addAttributes(const std::vector<std::string>* va);
|
||||
|
||||
Node* clone() const;
|
||||
|
||||
void addParam(Parameter* p);
|
||||
void addParams(std::vector<Parameter*>* p);
|
||||
void addVariable(Variable* v);
|
||||
void addVariables(std::vector<Variable*>* v);
|
||||
void addEvent(Event* e);
|
||||
void addEvents(std::vector<Event*>* e);
|
||||
void addTransition(Transition* t);
|
||||
void addTransitions(std::vector<Transition*>* t);
|
||||
void addAssertion(Assertion *e);
|
||||
void addAssertions(std::vector<Assertion*> *e);
|
||||
void addSubNode(Node* n);
|
||||
void addSubNodes(std::vector<Node*>* n);
|
||||
// void addSubNode(Node* n, std::vector<int> * v);
|
||||
// void addSubNodes(std::vector<Node*>* n, std::vector<std::vector<int>* > * v);
|
||||
void addSync(Synchronisation* s);
|
||||
void addSyncs(std::vector<Synchronisation*> *s);
|
||||
void addInit(Assignment* i);
|
||||
void addInits(std::vector<Assignment*>* i);
|
||||
void addParamsSet(Assignment* p);
|
||||
void addParamsSets(std::vector<Assignment*>* p);
|
||||
void addExternal(std::string e);
|
||||
void addExternals(std::vector<std::string>* e);
|
||||
void addEventLaw(EventLaw* e);
|
||||
void addEventLaws(std::vector<EventLaw*>* e);
|
||||
|
||||
|
||||
// const std::vector<Variable*> *getVariables();
|
||||
const std::map<std::string, Variable*, ltstr> * getStateVariables() const;
|
||||
const std::map<std::string, Variable*, ltstr> * getFlowVariables() const;
|
||||
const std::vector<Transition*> *getTransitions() const;
|
||||
// const std::vector<Node*> *getSubNodes();
|
||||
const std::map<std::string, Node*, ltstr> *getSubNodes() const;
|
||||
// const std::vector<Event*> *getEvents();
|
||||
const std::map<std::string, Event*, ltstr> *getEvents() const;
|
||||
const std::vector<Synchronisation*> *getSyncs() const;
|
||||
const std::vector<Assertion*> *getAsserts() const;
|
||||
const MemberAccess * getMA() const;
|
||||
|
||||
|
||||
bool hasName(std::string name);
|
||||
|
||||
Event* findEventByName(const MemberAccess* eName) const;
|
||||
Variable * findStateVariableByName(const MemberAccess * eName) const;
|
||||
Variable * findStateVariableByName(const std::string& s) const;
|
||||
Variable * findFlowVariableByName(const MemberAccess * eName) const;
|
||||
Variable * findFlowVariableByName(const std::string& s) const;
|
||||
Variable * findVariableByName(const MemberAccess * eName) const;
|
||||
Variable * findVariableByName(const std::string& s) const;
|
||||
|
||||
std::string toString(bool withTypes=false) const;
|
||||
std::string toFiacre() const ;
|
||||
std::string printTrans() const;
|
||||
|
||||
|
||||
void finalize(const AltaricaModel *am);
|
||||
|
||||
void deleteExprs();
|
||||
|
||||
void aliasVar(Variable* toRemove, Variable *mergedVar) ;
|
||||
void compactSimpleAsserts(const AltaricaModel *am);
|
||||
|
||||
void populateVarCache() const ;
|
||||
void addStateVarToCache(Variable*v, MemberAccess *subMA, std::string vName) const;
|
||||
void addFlowVarToCache(Variable*v, MemberAccess *subMA, std::string vName) const;
|
||||
bool isSymbol(const MemberAccess *ma) const;
|
||||
bool isSymbol(std::string s) const;
|
||||
|
||||
inline void setIndex(unsigned int i) { index_ = i;}
|
||||
inline unsigned int getIndex() const { return index_;}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
62
src/grammars/altarica/Parameter.cc
Normal file
62
src/grammars/altarica/Parameter.cc
Normal file
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Parameter.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Parameter::Parameter(std::string name) {
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
Parameter::Parameter(std::string name, Domain* d) {
|
||||
name_ = name;
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
void Parameter::setDomain(Domain *d) {
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
Domain *Parameter::getDomain() {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
std::string Parameter::getName() {
|
||||
return name_;
|
||||
}
|
||||
|
||||
Parameter * Parameter::clone() {
|
||||
return new Parameter(name_, domain_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
65
src/grammars/altarica/Parameter.hh
Normal file
65
src/grammars/altarica/Parameter.hh
Normal file
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef ALTA_PARAMETER_H_
|
||||
#define ALTA_PARAMETER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Domain;
|
||||
|
||||
class Parameter {
|
||||
|
||||
protected:
|
||||
|
||||
//!
|
||||
std::string name_;
|
||||
Domain * domain_;
|
||||
|
||||
public:
|
||||
|
||||
//!
|
||||
Parameter(std::string name);
|
||||
|
||||
Parameter(std::string name, Domain* d);
|
||||
|
||||
void setDomain(Domain *d);
|
||||
|
||||
Parameter * clone();
|
||||
|
||||
Domain * getDomain();
|
||||
|
||||
std::string getName();
|
||||
~Parameter() {};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
276
src/grammars/altarica/Synchronisation.cc
Normal file
276
src/grammars/altarica/Synchronisation.cc
Normal file
@@ -0,0 +1,276 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Synchronisation.hh"
|
||||
#include "Node.hh"
|
||||
#include <limits.h>
|
||||
#include <iostream>
|
||||
#include "AltaricaModel.hh"
|
||||
#include "MemberAccess.hh"
|
||||
#include "Event.hh"
|
||||
#include "MetaEvent.hh"
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
Synchronisation::Synchronisation() {
|
||||
max_ = 0;
|
||||
ma_ = NULL;
|
||||
numerical_constant_ = -1;
|
||||
};
|
||||
|
||||
|
||||
Synchronisation::Synchronisation(MemberAccess *ma) {
|
||||
max_ = 0;
|
||||
ma_ = ma;
|
||||
numerical_constant_ = -1;
|
||||
};
|
||||
|
||||
void Synchronisation::addEvent(MemberAccess*e, bool optional) {
|
||||
broadcastList_.push_back(e);
|
||||
optionalBcast_.push_back(optional);
|
||||
}
|
||||
|
||||
void Synchronisation::setConstraintType(short ct) {
|
||||
constraint_type_ = ct;
|
||||
}
|
||||
|
||||
void Synchronisation::setNumConstant(int n) {
|
||||
numerical_constant_ = n;
|
||||
}
|
||||
|
||||
void Synchronisation::setMax() {
|
||||
max_ = 1;
|
||||
}
|
||||
|
||||
void Synchronisation::setMin() {
|
||||
max_ = -1;
|
||||
}
|
||||
|
||||
|
||||
Synchronisation * Synchronisation::clone() {
|
||||
Synchronisation * n;
|
||||
if (ma_ != NULL)
|
||||
n = new Synchronisation(ma_->clone());
|
||||
else
|
||||
n = new Synchronisation();
|
||||
n->setConstraintType(constraint_type_);
|
||||
n->setNumConstant(numerical_constant_);
|
||||
if (max_ == 1)
|
||||
n->setMax();
|
||||
else if (max_ == -1)
|
||||
n->setMin();
|
||||
std::vector<MemberAccess*>::iterator itma = broadcastList_.begin();
|
||||
std::vector<bool>::iterator ito = optionalBcast_.begin();
|
||||
for (; itma != broadcastList_.end(); ++itma) {
|
||||
n->addEvent((*itma)->clone(), *ito);
|
||||
++ito;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void Synchronisation::setNode(Node * n) {
|
||||
node_ = n;
|
||||
}
|
||||
|
||||
void Synchronisation::matchEvents() {
|
||||
broadcastListOptionalEvents_.clear();
|
||||
broadcastListMandatoryEvents_.clear();
|
||||
for (unsigned int i = 0; i < broadcastList_.size(); ++i) {
|
||||
Event * e = node_->findEventByName(broadcastList_[i]);
|
||||
if(e == NULL)
|
||||
std::cerr << "\nSync failed, unknown event : "
|
||||
<< broadcastList_[i]->toString()
|
||||
<< std::endl;
|
||||
else {
|
||||
e->addSync(this);
|
||||
if (optionalBcast_[i])
|
||||
broadcastListOptionalEvents_.push_back(e);
|
||||
else
|
||||
broadcastListMandatoryEvents_.push_back(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Event*> * Synchronisation::getOptionalEvents() {
|
||||
if (broadcastListOptionalEvents_.size() == 0 && broadcastListMandatoryEvents_.size() ==0)
|
||||
matchEvents();
|
||||
return &broadcastListOptionalEvents_;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Event*> * Synchronisation::getMandatoryEvents() {
|
||||
if (broadcastListOptionalEvents_.size() == 0 && broadcastListMandatoryEvents_.size() ==0)
|
||||
matchEvents();
|
||||
return &broadcastListMandatoryEvents_;
|
||||
}
|
||||
|
||||
std::string Synchronisation::toString() const {
|
||||
std::stringstream ss;
|
||||
ss << "blist: ";
|
||||
for (std::vector<MemberAccess*>::const_iterator i = broadcastList_.begin(); i!= broadcastList_.end(); ++i) {
|
||||
ss << (*i)->toString() << ",";
|
||||
}
|
||||
ss << "\n mandatoryEv: ";
|
||||
for (std::vector<Event*>::const_iterator i = broadcastListMandatoryEvents_.begin(); i!= broadcastListMandatoryEvents_.end(); ++i) {
|
||||
ss << (*i)->toString() << ",";
|
||||
}
|
||||
ss << "\n optionalEv: ";
|
||||
for (std::vector<Event*>::const_iterator i = broadcastListOptionalEvents_.begin(); i!= broadcastListOptionalEvents_.end(); ++i) {
|
||||
ss << (*i)->toString() << ",";
|
||||
}
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<MetaEvent*> * Synchronisation::buildSynchronisedEvents(const AltaricaModel *am, AltaricaState *s) {
|
||||
// if (ma_ != NULL)
|
||||
// std::cerr << "building sync events for sync "<< *(ma_->toString()) << " of node: " << *(node_->getMA()->toString()) << std::endl;
|
||||
// else
|
||||
// std::cerr << "building sync events for node: " << *(node_->getMA()->toString()) << std::endl;
|
||||
|
||||
std::vector<MetaEvent*> * ret = NULL;
|
||||
|
||||
for (std::vector<Event*>::iterator j = broadcastListMandatoryEvents_.begin();
|
||||
j!=broadcastListMandatoryEvents_.end() ; ++j)
|
||||
if (!(*j)->isEnabled(am, s)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = new std::vector<MetaEvent*>();
|
||||
|
||||
MetaEvent * me = new MetaEvent();
|
||||
for (std::vector<Event*>::iterator j = broadcastListMandatoryEvents_.begin(); j!=broadcastListMandatoryEvents_.end(); ++j)
|
||||
me->push_back(*j);
|
||||
ret->push_back(me);
|
||||
|
||||
for ( std::vector<Event*>::iterator i = broadcastListOptionalEvents_.begin();
|
||||
i!= broadcastListOptionalEvents_.end(); ++i) {
|
||||
if ((*i)->isEnabled(am, s)) {
|
||||
int nvec = ret->size();
|
||||
std::vector<MetaEvent*> *temp = new std::vector<MetaEvent*>();
|
||||
for (std::vector<MetaEvent*>::iterator k = ret->begin(); k!=ret->end(); ++k)
|
||||
temp->push_back((*k)->clone());
|
||||
ret->insert(ret->begin(), temp->begin(), temp->end());
|
||||
delete temp;
|
||||
for (int j = 0; j<nvec; ++j) {
|
||||
(*ret)[j]->push_back(*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now apply constraints
|
||||
|
||||
std::vector<MetaEvent*>::iterator iret;
|
||||
if (numerical_constant_ != -1) {
|
||||
iret = ret->begin();
|
||||
while (iret != ret->end()) {
|
||||
int s = (*iret)->size();
|
||||
bool removed = false;
|
||||
switch (constraint_type_) {
|
||||
case -2: // INF
|
||||
if (s >= numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case -1: // INFEQ
|
||||
if (s > numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case 0: // EQ
|
||||
if (s != numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case 1: // SUPEQ
|
||||
if (s < numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
case 2: // SUP
|
||||
if (s <= numerical_constant_) {
|
||||
iret = ret->erase(iret);
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!removed)
|
||||
++iret;
|
||||
}
|
||||
}
|
||||
|
||||
// if min then select only minimal size among remaining
|
||||
if (max_ == -1) {
|
||||
unsigned int min_size = UINT_MAX;
|
||||
for (iret = ret->begin(); iret != ret->end(); ++iret) {
|
||||
if ((*iret)->size()<min_size)
|
||||
min_size = (*iret)->size();
|
||||
}
|
||||
iret = ret->begin();
|
||||
while (iret != ret->end()) {
|
||||
if ((*iret)->size() != min_size) {
|
||||
iret = ret->erase(iret);
|
||||
} else
|
||||
++iret;
|
||||
}
|
||||
} else if (max_ == 1) { // if max select only max size among remaining
|
||||
unsigned int max_size = std::numeric_limits<unsigned int>::min();
|
||||
for (iret = ret->begin(); iret != ret->end(); ++iret) {
|
||||
if ((*iret)->size()>max_size)
|
||||
max_size = (*iret)->size();
|
||||
}
|
||||
iret = ret->begin();
|
||||
while (iret != ret->end()) {
|
||||
if ((*iret)->size() != max_size) {
|
||||
iret = ret->erase(iret);
|
||||
} else
|
||||
++iret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// finally send stuff
|
||||
return ret;
|
||||
}
|
||||
|
||||
Synchronisation::~Synchronisation() {
|
||||
for (std::vector<MemberAccess*>::iterator i = broadcastList_.begin();
|
||||
i!= broadcastList_.end(); ++i)
|
||||
delete *i;
|
||||
delete ma_;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
src/grammars/altarica/Synchronisation.hh
Normal file
88
src/grammars/altarica/Synchronisation.hh
Normal file
@@ -0,0 +1,88 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_SYNC_H_
|
||||
#define ALTA_SYNC_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class MetaEvent;
|
||||
class Event;
|
||||
class MemberAccess;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
|
||||
class Synchronisation {
|
||||
protected:
|
||||
std::vector<MemberAccess*> broadcastList_;
|
||||
std::vector<Event*> broadcastListMandatoryEvents_;
|
||||
std::vector<Event*> broadcastListOptionalEvents_;
|
||||
std::vector<bool> optionalBcast_;
|
||||
short constraint_type_;
|
||||
int numerical_constant_;
|
||||
short max_;
|
||||
MemberAccess *ma_;
|
||||
Node * node_;
|
||||
public:
|
||||
Synchronisation();
|
||||
~Synchronisation();
|
||||
Synchronisation(MemberAccess *ma);
|
||||
|
||||
void addEvent(MemberAccess* e, bool optional);
|
||||
void setConstraintType(short ct);
|
||||
void setNumConstant(int n);
|
||||
void setMax();
|
||||
void setMin();
|
||||
|
||||
void setNode(Node *n);
|
||||
|
||||
Synchronisation* clone();
|
||||
|
||||
void matchEvents();
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
bool syncEvent(Event* e);
|
||||
|
||||
const std::vector<Event*> * getOptionalEvents();
|
||||
const std::vector<Event*> * getMandatoryEvents();
|
||||
|
||||
std::vector<MetaEvent*> * buildSynchronisedEvents(const AltaricaModel *am,
|
||||
AltaricaState *s);
|
||||
|
||||
const MemberAccess* getMA() const { return ma_; }
|
||||
short getConstraintType() const { return constraint_type_; }
|
||||
int getNumericalConstant() const { return numerical_constant_; }
|
||||
short getMinMaxType() const { return max_; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
194
src/grammars/altarica/Transition.cc
Normal file
194
src/grammars/altarica/Transition.cc
Normal file
@@ -0,0 +1,194 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Transition.hh"
|
||||
#include "Node.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "Values.hh"
|
||||
#include "Event.hh"
|
||||
#include "Assignment.hh"
|
||||
#include "expressions/Expression.hh"
|
||||
#include "AltaricaException.hh"
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Transition::Transition(Expression *precond) {
|
||||
precond_ = precond;
|
||||
node_ = NULL;
|
||||
// stateVarsInPrecond = NULL;
|
||||
}
|
||||
|
||||
Transition::Transition() {
|
||||
node_ = NULL;
|
||||
// stateVarsInPrecond = NULL;
|
||||
}
|
||||
|
||||
void Transition::setPrecond(Expression *precond) {
|
||||
precond_ = precond;
|
||||
}
|
||||
|
||||
void Transition::addEvent(Event* e) {
|
||||
eventList_.push_back(e);
|
||||
e->addTrans(this);
|
||||
}
|
||||
|
||||
void Transition::addEvents(std::vector<Event*>* ve) {
|
||||
for (std::vector<Event*>::iterator i = ve->begin(); i != ve->end(); ++i)
|
||||
eventList_.push_back(*i);
|
||||
}
|
||||
|
||||
void Transition::addAssignment(Assignment *a) {
|
||||
assignmentList_.push_back(a);
|
||||
a->setNode(node_);
|
||||
}
|
||||
|
||||
void Transition::addAssignments(std::vector<Assignment*> *va) {
|
||||
for (std::vector<Assignment*>::iterator i = va->begin();
|
||||
i != va->end(); ++i)
|
||||
assignmentList_.push_back(*i);
|
||||
}
|
||||
|
||||
|
||||
Transition * Transition::clone() {
|
||||
Transition * n = new Transition(precond_);
|
||||
for (std::vector<Event*>::iterator it = eventList_.begin();
|
||||
it != eventList_.end(); ++it)
|
||||
n->addEvent(*it);
|
||||
|
||||
for (std::vector<Assignment*>::iterator it = assignmentList_.begin();
|
||||
it != assignmentList_.end(); ++it)
|
||||
n->addAssignment((*it)->clone());
|
||||
|
||||
for (std::vector<MemberAccess*>::iterator it = eventNames_.begin();
|
||||
it != eventNames_.end(); ++it)
|
||||
n->addEventName((*it)->clone());
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void Transition::addEventName(MemberAccess*ma) {
|
||||
eventNames_.push_back(ma);
|
||||
}
|
||||
|
||||
void Transition::addEventNames(std::vector<MemberAccess *> *mav) {
|
||||
for (std::vector<MemberAccess*>::iterator i = mav->begin(); i!= mav->end(); ++i)
|
||||
eventNames_.push_back(*i);
|
||||
}
|
||||
|
||||
void Transition::setNode(Node*n) {
|
||||
node_ = n;
|
||||
for (std::vector<Assignment*>::iterator i = assignmentList_.begin(); i!=assignmentList_.end(); ++i)
|
||||
(*i)->setNode(n);
|
||||
for (std::vector<Event*>::iterator i = eventList_.begin(); i!=eventList_.end(); ++i)
|
||||
(*i)->setNode(n);
|
||||
|
||||
}
|
||||
|
||||
void Transition::matchEvents() {
|
||||
// if (eventList_.size() != 0)
|
||||
// eventList_.clear();
|
||||
// we have only events names for now, we need to add corresponding events in node
|
||||
for (std::vector<MemberAccess*>::const_iterator i = eventNames_.begin();
|
||||
i!=eventNames_.end(); ++i) {
|
||||
Event *e = node_->findEventByName(*i);
|
||||
if (e == NULL) {
|
||||
std::string s = "cannot find event: ";
|
||||
s+= (*i)->toString();
|
||||
throw AltaricaException(s, "epoch::altarica::Transition::matchEvents()");
|
||||
|
||||
}
|
||||
addEvent(e);
|
||||
// e->addTrans(this);
|
||||
}
|
||||
}
|
||||
|
||||
// void Transition::cachePrecond() {
|
||||
// stateVarsInPrecond = precond_->infoVars(node_,false,false);
|
||||
// }
|
||||
|
||||
bool Transition::precondOK(const AltaricaModel *am, AltaricaState *s) const {
|
||||
ValueBool * fv = (ValueBool*) precond_->evaluate(am, s,node_);
|
||||
bool res = fv->allowedTop();
|
||||
Value::deleteIfPossible(fv);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void Transition::doTransition(const AltaricaModel *am, AltaricaState *ps, AltaricaState *ns) {
|
||||
// if (!ps->isMacro()) {
|
||||
for (std::vector<Assignment*>::iterator ai = assignmentList_.begin();
|
||||
ai != assignmentList_.end(); ++ai)
|
||||
ns->setValue((*ai)->getVar(), (*ai)->evaluate(am, ps));
|
||||
// } else {
|
||||
// for (std::vector<Assignment*>::iterator ai = assignmentList_.begin();
|
||||
// ai != assignmentList_.end(); ++ai)
|
||||
// ns->addValue((*ai)->getVar(), (*ai)->evaluate(ps));
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Transition::deleteExprs() {
|
||||
delete precond_ ;
|
||||
for (std::vector<Assignment*>::iterator i = assignmentList_.begin(); i != assignmentList_.end(); ++i)
|
||||
(*i)->deleteExprs();
|
||||
}
|
||||
|
||||
Transition::~Transition() {
|
||||
for (std::vector<MemberAccess*>::iterator i = eventNames_.begin();
|
||||
i!= eventNames_.end(); ++i)
|
||||
delete *i;
|
||||
for (std::vector<Assignment*>::iterator i = assignmentList_.begin(); i != assignmentList_.end(); ++i) {
|
||||
delete (*i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Transition::toString() const {
|
||||
std::string s;
|
||||
s += "NODE "+ node_->toString() + "\n";
|
||||
for (std::vector<MemberAccess*>::const_iterator i = eventNames_.begin(); i!=eventNames_.end(); ++i) {
|
||||
s+= (*i)->toString() + "; ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Transition::toFiacre() const {
|
||||
std::string s;
|
||||
s += "NODE "+ node_->toString() + "\n";
|
||||
for (std::vector<MemberAccess*>::const_iterator i = eventNames_.begin(); i!=eventNames_.end(); ++i) {
|
||||
s+= (*i)->toString() + "; "; //node_
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
106
src/grammars/altarica/Transition.hh
Normal file
106
src/grammars/altarica/Transition.hh
Normal file
@@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_TRANSITION_H_
|
||||
#define ALTA_TRANSITION_H_
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Assignment;
|
||||
class MemberAccess;
|
||||
class Event;
|
||||
class Expression;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
|
||||
class Transition {
|
||||
|
||||
protected:
|
||||
|
||||
//! precondition associee a la transition
|
||||
Expression *precond_;
|
||||
|
||||
//! liste des evenements concernes
|
||||
std::vector<Event*> eventList_;
|
||||
|
||||
std::vector<Assignment*> assignmentList_;
|
||||
|
||||
std::vector<MemberAccess*> eventNames_;
|
||||
|
||||
|
||||
Node * node_;
|
||||
|
||||
// std::vector<Variable*> * stateVarsInPrecond;
|
||||
// std::map<int, int> indexVarTranslator;
|
||||
public:
|
||||
|
||||
//!
|
||||
Transition(Expression *precond);
|
||||
Transition();
|
||||
~Transition();
|
||||
|
||||
void setPrecond(Expression *precond);
|
||||
const Expression * getPrecond() const {return precond_; }
|
||||
void addEvent(Event* e);
|
||||
void addEvents(std::vector<Event*>* ve);
|
||||
void addAssignment(Assignment* a);
|
||||
void addAssignments(std::vector<Assignment*> * va);
|
||||
const std::vector<Assignment*> * getAssigns() const {return &assignmentList_;}
|
||||
void addEventName(MemberAccess *ma);
|
||||
void addEventNames(std::vector<MemberAccess*> *mav);
|
||||
Transition * clone();
|
||||
|
||||
void setNode(Node*n);
|
||||
const Node* getNode() const {return node_;}
|
||||
|
||||
void matchEvents();
|
||||
|
||||
bool precondOK(const AltaricaModel *am, AltaricaState *s) const;
|
||||
|
||||
void doTransition(const AltaricaModel *am, AltaricaState *s, AltaricaState *ns);
|
||||
|
||||
// void cachePrecond();
|
||||
|
||||
|
||||
void deleteExprs();
|
||||
|
||||
std::string toString() const;
|
||||
std::string toFiacre() const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
33
src/grammars/altarica/Values.hh
Normal file
33
src/grammars/altarica/Values.hh
Normal file
@@ -0,0 +1,33 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef VALUES_HH
|
||||
#define VALUES_HH
|
||||
#include "values/Value.hh"
|
||||
#include "values/ValueBool.hh"
|
||||
#include "values/ValueSymbol.hh"
|
||||
#include "values/ValueInt.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
#endif
|
||||
529
src/grammars/altarica/Variable.cc
Normal file
529
src/grammars/altarica/Variable.cc
Normal file
@@ -0,0 +1,529 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <limits.h>
|
||||
|
||||
#include "MemberAccess.hh"
|
||||
#include "Variable.hh"
|
||||
#include "AltaricaState.hh"
|
||||
#include "Assertion.hh"
|
||||
#include "Node.hh"
|
||||
#include "domains/Domains.hh"
|
||||
#include "Values.hh"
|
||||
#include "LandmarkState.hh"
|
||||
#include "AltaricaException.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
Variable::Variable(std::string name) {
|
||||
ma_= new MemberAccess(name);
|
||||
domain_ = NULL;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
loop_status_ = 0;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma) {
|
||||
ma_= ma;
|
||||
domain_ = NULL;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
loop_status_ = 0;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, Domain* d) {
|
||||
domain_ = d;
|
||||
ma_=new MemberAccess(name);
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
loop_status_ = 0;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma, Domain* d) {
|
||||
domain_ = d;
|
||||
ma_=ma;
|
||||
asserts_ = NULL;
|
||||
loop_status_ = 0;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, Domain* d, bool isState) {
|
||||
domain_ = d;
|
||||
ma_ = new MemberAccess(name);
|
||||
state_ = isState;
|
||||
asserts_ = NULL;
|
||||
loop_status_ = 0;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma, Domain* d, bool isState) {
|
||||
domain_ = d;
|
||||
ma_ = ma;
|
||||
state_ = isState;
|
||||
loop_status_ = 0;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, bool isState) {
|
||||
state_ = isState;
|
||||
ma_ = new MemberAccess(name);
|
||||
asserts_ = NULL;
|
||||
loop_status_ = 0;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Variable::Variable(MemberAccess *ma, bool isState) {
|
||||
state_ = isState;
|
||||
ma_ = ma;
|
||||
asserts_ = NULL;
|
||||
init_ = NULL;
|
||||
aliases_ = new std::vector<std::pair<const Node*, const MemberAccess*>*>();
|
||||
loop_status_ = 0;
|
||||
index_ = UINT_MAX;
|
||||
}
|
||||
|
||||
Domain * Variable::getDomain() const {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
void Variable::setDomain(Domain *d) {
|
||||
domain_ = d;
|
||||
}
|
||||
|
||||
void Variable::setState(bool s) {
|
||||
state_ = s;
|
||||
}
|
||||
|
||||
void Variable::setState() {
|
||||
state_ = true;
|
||||
}
|
||||
|
||||
void Variable::setFlow() {
|
||||
state_ = false;
|
||||
}
|
||||
|
||||
|
||||
void Variable::addAttribute(const std::string a) {
|
||||
attributes_.push_back(std::string(a));
|
||||
}
|
||||
|
||||
void Variable::addAttributes(const std::vector<std::string> *va) {
|
||||
if (va != NULL)
|
||||
for (std::vector<std::string>::const_iterator si = va->begin(); si != va->end(); ++si) {
|
||||
addAttribute(*si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Variable::setMemberAccess(MemberAccess *ma) {
|
||||
ma_ = ma;
|
||||
}
|
||||
|
||||
Variable * Variable::clone() const {
|
||||
Variable * n = new Variable(ma_->clone(), domain_, state_);
|
||||
// if (ma_!=NULL)
|
||||
// n->setMemberAccess(ma_->clone());
|
||||
n->addAttributes(&attributes_);
|
||||
n->setNode(node_);
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i =
|
||||
aliases_->begin(); i!=aliases_->end(); ++i)
|
||||
n->addAlias((*i)->first, (*i)->second->clone());
|
||||
// if (init_ != NULL)
|
||||
n->setInit(init_);
|
||||
return n;
|
||||
}
|
||||
|
||||
// bool Variable::isState() const {
|
||||
// return state_;
|
||||
// }
|
||||
|
||||
|
||||
// bool Variable::isFlow() const {
|
||||
// return !state_;
|
||||
// }
|
||||
|
||||
void Variable::setNode(const Node*n) {
|
||||
node_ = n;
|
||||
}
|
||||
|
||||
const Node * Variable::getNode() const{
|
||||
return node_;
|
||||
}
|
||||
|
||||
const std::vector<Node *> * Variable::getNodes() const {
|
||||
std::vector<Node*>* ret = new std::vector<Node*>();
|
||||
ret->push_back((Node*)node_);
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i =
|
||||
aliases_->begin(); i!=aliases_->end(); ++i) {
|
||||
ret->push_back((Node*)(*i)->first);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<const Node *>* Variable::getPath() const {
|
||||
std::vector<const Node*>* ret = node_->getPath();
|
||||
ret->push_back(node_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Variable::getFullName() const {
|
||||
std::ostringstream ss;
|
||||
ss << node_->getFullName()
|
||||
<< "."
|
||||
<< getMA()->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Variable::setInit(Assignment* n) {
|
||||
init_ = n;
|
||||
}
|
||||
|
||||
const Assignment * Variable::getInit() {
|
||||
return init_;
|
||||
}
|
||||
|
||||
|
||||
const MemberAccess * Variable::getMA() const{
|
||||
return ma_;
|
||||
}
|
||||
|
||||
std::vector<Variable*> * Variable::flattenDomain() {
|
||||
return domain_->flatten(this);
|
||||
}
|
||||
|
||||
void Variable::addToMASecond(int i) {
|
||||
ma_->addIndexSecond(i);
|
||||
}
|
||||
|
||||
|
||||
void Variable::addToMASecond(std::string s) {
|
||||
ma_->addIdSecond(s);
|
||||
}
|
||||
|
||||
void Variable::addAssert(Assertion* a) {
|
||||
if (asserts_ == NULL)
|
||||
asserts_ = new std::vector<Assertion*>();
|
||||
asserts_->push_back(a);
|
||||
}
|
||||
|
||||
void Variable::addAsserts(const std::vector<Assertion*> * a) {
|
||||
if (a == NULL)
|
||||
return;
|
||||
for (std::vector<Assertion*>::const_iterator i = a->begin(); i!= a->end(); ++i)
|
||||
addAssert(*i);
|
||||
}
|
||||
|
||||
const std::vector<Assertion*> * Variable::getAsserts() const {
|
||||
return asserts_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// unsigned int Variable::nbUnComputedOpen(std::vector<Variable*> * vv, AltaricaState *s) {
|
||||
// unsigned int c = 0;
|
||||
// for (std::vector<Variable*>::iterator i = vv->begin(); i!= vv->end(); ++i) {
|
||||
// if (!s->hasValue(*i))
|
||||
// ++c;
|
||||
// }
|
||||
// return c;
|
||||
// }
|
||||
|
||||
void Variable::forceEvaluate(const AltaricaModel *am, AltaricaState *s) const {
|
||||
s->setValue(this, getDomain()->toValue());
|
||||
s->getValue(this)->unConstrain();
|
||||
|
||||
// if (asserts_->size() > 1) {
|
||||
// std::cerr << "more than one assert possible to compute" << std::endl;
|
||||
// }
|
||||
if (asserts_->size() == 0) {
|
||||
std::string s = "cannot compute: " + toString();
|
||||
std::cerr << "\nError " << s << std::endl;
|
||||
throw new AltaricaException(s, "Variable::evaluate");
|
||||
}
|
||||
|
||||
for (std::vector<Assertion*>::iterator ai = asserts_->begin(); ai != asserts_->end(); ++ai) {
|
||||
(*ai)->evaluate(am, s);
|
||||
}
|
||||
s->getValue(this)->constrain();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Variable::evaluate(const AltaricaModel *am, AltaricaState *s) const {
|
||||
// if (index_ == 717 || index_ == 1411 || index_ == 2125 || index_ == 2841) {
|
||||
// std::cout << "blah\n";
|
||||
// std::cout << s->toString(true,true,false,false) << std::endl;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
if (s->getFlowValue(index_) != NULL) {
|
||||
loop_status_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (loop_status_) {
|
||||
case 0: loop_status_ = 1;
|
||||
break;
|
||||
case 1: loop_status_ = 2;
|
||||
std::cerr << ">>>>>>>>>>>>>>>>>>>>>>>>> loop detected, into loop for debug\n";
|
||||
std::cerr << ">>>>>>>>>>>>>>>>>>>>>>>>> evaluating var: " << this->toString() << " \n";
|
||||
break;
|
||||
case 2:
|
||||
std::cerr << "<<<<<<<<<<<<<<<<<<<<<<<< end of loop, assuming all possible values, you should check your model\n";
|
||||
s->setValue(this, getDomain()->toValue());
|
||||
s->getValue(this)->unConstrain();
|
||||
// loop_status_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
s->setValue(this, NULL);
|
||||
|
||||
// s->setValue(this, getDomain()->toValue(), false);
|
||||
// s->getValue(this)->unConstrain();
|
||||
if ((asserts_ == NULL) || (asserts_->size() == 0)) {
|
||||
std::string s = "cannot compute: " + toString();
|
||||
std::cerr << "\nError " << s << std::endl;
|
||||
throw new AltaricaException(s, "Variable::evaluate");
|
||||
}
|
||||
|
||||
for (std::vector<Assertion*>::iterator ai = asserts_->begin(); ai != asserts_->end(); ++ai) {
|
||||
if (loop_status_ == 2)
|
||||
std::cerr << ">>>>>>>>>>>>>>>>>>> using assertion\n" << (*ai)->getExpr()->toString() << "\n";
|
||||
|
||||
(*ai)->evaluate(am, s);
|
||||
}
|
||||
s->getValue(this)->constrain();
|
||||
loop_status_ = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Variable::evaluateLM(const AltaricaModel *am, LandmarkState *lms) const {
|
||||
if (lms->getState()->hasValue(this))
|
||||
return;
|
||||
lms->getState()->setValue(this, getDomain()->toValue());
|
||||
lms->getState()->getValue(this)->unConstrain();
|
||||
|
||||
// int bidon = this->toString().find("MMEL_status^applicable");
|
||||
// if (bidon!=-1) {
|
||||
// std::cerr << "blah";
|
||||
// }
|
||||
|
||||
if (asserts_->size() > 1) {
|
||||
std::cerr << "more than one assert possible to compute" << std::endl;
|
||||
}
|
||||
|
||||
for (std::vector<Assertion*>::iterator ai = asserts_->begin(); ai != asserts_->end(); ++ai) {
|
||||
(*ai)->evaluateLM(am, lms);
|
||||
}
|
||||
lms->getState()->getValue(this)->constrain();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Variable::toString() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << index_ << ": " << node_->toString() << "."+ma_->toString();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i = aliases_->begin();
|
||||
i!= aliases_->end(); ++i)
|
||||
ss << " / " << (*i)->first->toString() << "." << (*i)->second->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Variable::toFiacre(const bool print_head) const {
|
||||
std::ostringstream ss;
|
||||
|
||||
if (print_head) {
|
||||
if (node_->findStateVariableByName(ma_->toString()))
|
||||
ss << "y.";
|
||||
if (node_->findFlowVariableByName(ma_->toString()))
|
||||
ss << "x.";
|
||||
}
|
||||
ss << node_->toFiacre() << "_" << ma_->toString();
|
||||
|
||||
// for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i = aliases_->begin(); i!= aliases_->end(); ++i)
|
||||
// ss << " / " << (*i)->first->toString() << "_" << (*i)->second->toString();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool Variable::equals(std::vector<Variable*> *v1, std::vector<Variable*> *v2) {
|
||||
if (v1->size() != v2->size())
|
||||
return false;
|
||||
for (std::vector<Variable*>::iterator v1it = v1->begin(); v1it != v1->end(); ++v1it) {
|
||||
bool isIn = false;
|
||||
for (std::vector<Variable*>::iterator v2it = v2->begin();
|
||||
v2it != v2->end() && ! isIn; ++v2it) {
|
||||
if (*v2it == *v1it)
|
||||
isIn = true;
|
||||
}
|
||||
if (!isIn)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Variable*> *Variable::removeFromVec(std::vector<Variable*> *toRemove, std::vector<Variable*> *all) {
|
||||
for (std::vector<Variable*>::iterator i = toRemove->begin(); i!=toRemove->end(); ++i) {
|
||||
bool removed = false;
|
||||
for (std::vector<Variable*>::iterator j = all->begin(); j!=all->end() && !removed; ++j) {
|
||||
if (*i == *j) {
|
||||
all->erase(j);
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
Variable::~Variable() {
|
||||
delete ma_;
|
||||
attributes_.clear();
|
||||
delete asserts_;
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i =aliases_->begin();
|
||||
i!= aliases_->end(); ++i) {
|
||||
delete (*i)->second;
|
||||
delete *i;
|
||||
}
|
||||
delete aliases_;
|
||||
}
|
||||
|
||||
void Variable::addAlias(const Node *n, const MemberAccess*ma) {
|
||||
aliases_->push_back(new std::pair<const Node*, const MemberAccess*>(n,ma));
|
||||
}
|
||||
|
||||
bool Variable::hasName(const Node* n, const MemberAccess* ma) const {
|
||||
if (node_ == n && ma_->equals(ma))
|
||||
return true;
|
||||
for (std::vector<std::pair<const Node*,const MemberAccess*>*>::const_iterator i = aliases_->begin();
|
||||
i!= aliases_->end(); ++i)
|
||||
if ((*i)->first == n && (*i)->second->equals(ma))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Variable::mergeVariable(const Variable *v) {
|
||||
std::cerr << "Merging variable " << getFullName() << " : " << getAsserts()->size() << " with " << v->getFullName() << " : " << v->getAsserts()->size() << std::endl;
|
||||
|
||||
if (state_ || v->isState())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("trying to merge varibles that are not flow vars!!!!!!!")));
|
||||
addAttributes(v->getAttributes());
|
||||
addAsserts(v->getAsserts());
|
||||
addAlias(v->getNode(), v->getMA()->clone());
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * valiases = v->getAliases();
|
||||
for (std::vector<std::pair<const Node*, const MemberAccess*>*>::const_iterator i = valiases->begin();
|
||||
i!= valiases->end(); ++i) {
|
||||
addAlias((*i)->first, (*i)->second->clone());
|
||||
}
|
||||
|
||||
std::cerr << " merged variable " << getFullName() << " : " << getAsserts()->size()<< std::endl;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * Variable::getAliases() const {
|
||||
return aliases_;
|
||||
}
|
||||
|
||||
const std::vector<std::string> *Variable::getAttributes() const {
|
||||
return &attributes_;
|
||||
}
|
||||
|
||||
void Variable::removeAssert(Assertion*a) {
|
||||
for (std::vector<Assertion*>::iterator i = asserts_->begin(); i != asserts_->end(); ++i)
|
||||
if (*i == a) {
|
||||
asserts_->erase(i);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Variable::removeOwner(Node *n) {
|
||||
if (node_ == n) {
|
||||
node_ = NULL;
|
||||
if (aliases_->size() == 0)
|
||||
return true;
|
||||
} else {
|
||||
std::vector<std::pair<const Node*, const MemberAccess*>*>::iterator i;
|
||||
for (i = aliases_->begin(); i!= aliases_->end() && (*i)->first!=n; ++i);
|
||||
if (i == aliases_->end())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("unable to find owner!!!!!!!")));
|
||||
delete (*i)->second;
|
||||
delete *i;
|
||||
aliases_->erase(i);
|
||||
if (aliases_->size() == 0 && node_ == NULL)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Variable*> * Variable::infoVars(const AltaricaModel *am, const Node *n, bool flow, bool computed) {
|
||||
if (state_)
|
||||
return NULL;
|
||||
std::vector<Variable*>* vv = new std::vector<Variable*>();
|
||||
for (std::vector<Assertion*>::iterator i = asserts_->begin(); i!= asserts_->end(); ++i) {
|
||||
std::vector<Variable*> *vvv = (*i)->infoVars(am, flow, computed);
|
||||
vv->insert(vv->end(), vvv->begin(), vvv->end());
|
||||
delete vvv;
|
||||
}
|
||||
return vv;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
182
src/grammars/altarica/Variable.hh
Normal file
182
src/grammars/altarica/Variable.hh
Normal file
@@ -0,0 +1,182 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_VARIABLE_H_
|
||||
#define ALTA_VARIABLE_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Node;
|
||||
class Assignment;
|
||||
class Assertion;
|
||||
class MemberAccess;
|
||||
class Value;
|
||||
class Expression;
|
||||
class AltaricaState;
|
||||
class AltaricaModel;
|
||||
class Domain;
|
||||
class LandmarkState;
|
||||
|
||||
class Variable {
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int index_;
|
||||
mutable unsigned int loop_status_; // 0 means nothing
|
||||
// 1 for evaluating
|
||||
// 2 for in_loop debug
|
||||
|
||||
|
||||
//! full qualified name
|
||||
MemberAccess *ma_;
|
||||
//! variable type
|
||||
Domain * domain_;
|
||||
//! state or flow variable
|
||||
bool state_;
|
||||
//! attributes (tool-dependant)
|
||||
std::vector<std::string> attributes_;
|
||||
const Node * node_;
|
||||
Assignment * init_;
|
||||
|
||||
std::vector<Assertion*> * asserts_; // Assertions that change its value
|
||||
|
||||
std::vector<std::pair<const Node*, const MemberAccess*>*> *aliases_;
|
||||
|
||||
static int nbUnComputedOpen(std::vector<Variable*> * vv, AltaricaState *s);
|
||||
|
||||
public:
|
||||
|
||||
inline unsigned int getIndex() const {return index_;}
|
||||
inline void setIndex(unsigned int i) {index_ = i;}
|
||||
|
||||
//! constructeur minimal
|
||||
Variable(std::string name);
|
||||
Variable(MemberAccess* ma);
|
||||
|
||||
//! constructeur un peu plus evolué
|
||||
Variable(std::string name, bool isState);
|
||||
Variable(MemberAccess *ma, bool isState);
|
||||
|
||||
//! encore un autre
|
||||
Variable(std::string name, Domain* d);
|
||||
Variable(MemberAccess *ma, Domain* d);
|
||||
|
||||
//! constructeur quasi-complet
|
||||
Variable(std::string name, Domain* d, bool isState);
|
||||
Variable(MemberAccess *ma, Domain* d, bool isState);
|
||||
|
||||
void setMemberAccess(MemberAccess * ma);
|
||||
const MemberAccess * getMA() const;
|
||||
|
||||
|
||||
void addToMASecond(int i);
|
||||
void addToMASecond(std::string s);
|
||||
|
||||
//! State or flow
|
||||
void setState(bool s);
|
||||
|
||||
//! variable domain
|
||||
void setDomain(Domain *d);
|
||||
|
||||
//! State attribute variable
|
||||
void setState();
|
||||
|
||||
//! Flow attribute
|
||||
void setFlow();
|
||||
|
||||
//! attributs externes a altarica
|
||||
void addAttribute(const std::string a);
|
||||
|
||||
|
||||
//! attributs externes a altarica
|
||||
void addAttributes(const std::vector<std::string> *va);
|
||||
const std::vector<std::string> *getAttributes() const;
|
||||
|
||||
void addAssert(Assertion* a);
|
||||
void addAsserts(const std::vector<Assertion*> * a);
|
||||
const std::vector<Assertion*> * getAsserts() const;
|
||||
|
||||
|
||||
void setNode(const Node* n);
|
||||
const Node * getNode() const;
|
||||
const std::vector<Node *>* getNodes() const;
|
||||
void setParentNode(const Node* n);
|
||||
const Node * getParentNode();
|
||||
|
||||
std::vector<const Node *>* getPath() const;
|
||||
std::string getFullName() const;
|
||||
|
||||
void setInit(Assignment* n);
|
||||
const Assignment * getInit();
|
||||
|
||||
std::vector<Variable*> * flattenDomain();
|
||||
|
||||
Variable * clone() const;
|
||||
|
||||
// std::string* getName();
|
||||
|
||||
Domain * getDomain() const;
|
||||
|
||||
inline bool isState() const {return state_;}
|
||||
inline bool isFlow() const {return !state_;}
|
||||
|
||||
// Value * getInitialValue(); // defined for Prism
|
||||
|
||||
static bool equals(std::vector<Variable*> *v1, std::vector<Variable*> *v2);
|
||||
static std::vector<Variable*> *removeFromVec(std::vector<Variable*> *toRemove, std::vector<Variable*> *all);
|
||||
|
||||
void evaluate(const AltaricaModel* am, AltaricaState *s) const;
|
||||
void forceEvaluate(const AltaricaModel* am, AltaricaState *s) const;
|
||||
void evaluateLM(const AltaricaModel* am, LandmarkState *lms) const;
|
||||
|
||||
|
||||
bool hasName(const Node* n, const MemberAccess* ma) const;
|
||||
void addAlias(const Node* n, const MemberAccess* ma);
|
||||
const std::vector<std::pair<const Node*, const MemberAccess*>*> * getAliases() const;
|
||||
|
||||
std::string toString() const;
|
||||
std::string toFiacre(const bool print_head = true) const ;
|
||||
~Variable();
|
||||
|
||||
void mergeVariable(const Variable *v);
|
||||
|
||||
void removeAssert(Assertion*a);
|
||||
|
||||
bool removeOwner(Node *n);
|
||||
|
||||
std::vector<Variable*> * infoVars(const AltaricaModel*am, const Node *n, bool flow, bool computed);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
202
src/grammars/altarica/altarica.l
Normal file
202
src/grammars/altarica/altarica.l
Normal file
@@ -0,0 +1,202 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Florent Teichteil-Königsbuch (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
%{
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include "altarica_driver.hh"
|
||||
#include "altarica_parser.hh"
|
||||
#undef yywrap
|
||||
#define yywrap(yyscanner) 1
|
||||
//#define yyterminate() yy_delete_buffer(YY_CURRENT_BUFFER); return token::ALTARICA_END
|
||||
#define yyterminate() return token::ALTARICA_END
|
||||
%}
|
||||
|
||||
%option noyywrap nounput batch debug reentrant
|
||||
|
||||
|
||||
|
||||
blank [ \t]
|
||||
|
||||
%{
|
||||
#define YY_USER_ACTION yylloc->columns (yyleng);
|
||||
%}
|
||||
|
||||
%s IN_COMMENT
|
||||
|
||||
%%
|
||||
%{
|
||||
/* Location handling */
|
||||
yylloc->step ();
|
||||
%}
|
||||
|
||||
%{
|
||||
typedef epoch::altarica::altarica_parser::token token;
|
||||
%}
|
||||
|
||||
"," return token::ALTARICA_COMMA;
|
||||
: return token::ALTARICA_COLON;
|
||||
; return token::ALTARICA_SEMICOLON;
|
||||
= return token::ALTARICA_EQUAL;
|
||||
"[" return token::ALTARICA_LEFTBRACKET;
|
||||
"]" return token::ALTARICA_RIGHTBRACKET;
|
||||
"{" return token::ALTARICA_LEFTEMBRACE;
|
||||
"}" return token::ALTARICA_RIGHTEMBRACE;
|
||||
"const" return token::ALTARICA_CONST;
|
||||
CONST return token::ALTARICA_CONST;
|
||||
domain return token::ALTARICA_DOMAIN;
|
||||
DOMAIN return token::ALTARICA_DOMAIN;
|
||||
|
||||
|
||||
"(" return token::ALTARICA_OPAREN;
|
||||
")" return token::ALTARICA_CPAREN;
|
||||
"?" return token::ALTARICA_IMARK;
|
||||
|
||||
SORT return token::ALTARICA_SORT;
|
||||
sort return token::ALTARICA_SORT;
|
||||
SIG return token::ALTARICA_SIG;
|
||||
sig return token::ALTARICA_SIG;
|
||||
"->" return token::ALTARICA_TO;
|
||||
"*" return token::ALTARICA_STAR;
|
||||
if return token::ALTARICA_IF;
|
||||
then return token::ALTARICA_THEN;
|
||||
else return token::ALTARICA_ELSE;
|
||||
case return token::ALTARICA_CASE;
|
||||
or return token::ALTARICA_OR;
|
||||
"|" return token::ALTARICA_LOR;
|
||||
and return token::ALTARICA_AND;
|
||||
"&" return token::ALTARICA_LAND;
|
||||
"!=" return token::ALTARICA_DIF;
|
||||
"#" return token::ALTARICA_CARD;
|
||||
"=>" return token::ALTARICA_IMPLIES;
|
||||
"<" return token::ALTARICA_INF;
|
||||
">" return token::ALTARICA_SUP;
|
||||
"<=" return token::ALTARICA_INFEQ;
|
||||
">=" return token::ALTARICA_SUPEQ;
|
||||
"+" return token::ALTARICA_PLUS;
|
||||
"-" return token::ALTARICA_MINUS;
|
||||
"/" return token::ALTARICA_DIV;
|
||||
MOD return token::ALTARICA_MOD;
|
||||
mod return token::ALTARICA_MOD;
|
||||
"~" return token::ALTARICA_TILDE;
|
||||
NOT return token::ALTARICA_NOT;
|
||||
not return token::ALTARICA_NOT;
|
||||
"." return token::ALTARICA_DOT;
|
||||
MIN return token::ALTARICA_MIN;
|
||||
min return token::ALTARICA_MIN;
|
||||
MAX return token::ALTARICA_MAX;
|
||||
max return token::ALTARICA_MAX;
|
||||
TRUE return token::ALTARICA_TRUE;
|
||||
"true" return token::ALTARICA_TRUE;
|
||||
FALSE return token::ALTARICA_FALSE;
|
||||
"false" return token::ALTARICA_FALSE;
|
||||
NODE return token::ALTARICA_NODE;
|
||||
node return token::ALTARICA_NODE;
|
||||
EDON return token::ALTARICA_EDON;
|
||||
edon return token::ALTARICA_EDON;
|
||||
PARAM return token::ALTARICA_PARAM;
|
||||
param return token::ALTARICA_PARAM;
|
||||
FLOW return token::ALTARICA_FLOW;
|
||||
flow return token::ALTARICA_FLOW;
|
||||
STATE return token::ALTARICA_STATE;
|
||||
state return token::ALTARICA_STATE;
|
||||
EVENT return token::ALTARICA_EVENT;
|
||||
event return token::ALTARICA_EVENT;
|
||||
SUB return token::ALTARICA_SUB;
|
||||
sub return token::ALTARICA_SUB;
|
||||
ASSERT return token::ALTARICA_ASSERT;
|
||||
assert return token::ALTARICA_ASSERT;
|
||||
TRANS return token::ALTARICA_TRANS;
|
||||
trans return token::ALTARICA_TRANS;
|
||||
"|-" return token::ALTARICA_TR;
|
||||
":=" return token::ALTARICA_AFFECT;
|
||||
SYNC return token::ALTARICA_SYNC;
|
||||
sync return token::ALTARICA_SYNC;
|
||||
INIT return token::ALTARICA_INIT;
|
||||
init return token::ALTARICA_INIT;
|
||||
PARAM_SET return token::ALTARICA_PARAM_SET;
|
||||
param_set return token::ALTARICA_PARAM_SET;
|
||||
EXTERN return token::ALTARICA_EXTERN;
|
||||
"extern" return token::ALTARICA_EXTERN;
|
||||
ccf return token::ALTARICA_CCF;
|
||||
withCCF return token::ALTARICA_WITHCCF;
|
||||
nodeproperty return token::ALTARICA_NODEPROPERTY;
|
||||
Dirac return token::ALTARICA_LAW_DIRAC;
|
||||
constant return token::ALTARICA_LAW_DISCRETE;
|
||||
exponential return token::ALTARICA_LAW_EXP;
|
||||
exp return token::ALTARICA_LAW_EXP;
|
||||
time return token::ALTARICA_LAW_TIMED;
|
||||
|
||||
|
||||
|
||||
|
||||
BOOL return token::ALTARICA_BOOL;
|
||||
bool return token::ALTARICA_BOOL;
|
||||
INTEGER return token::ALTARICA_INTEGER;
|
||||
integer return token::ALTARICA_INTEGER;
|
||||
real return token::ALTARICA_REAL;
|
||||
REAL return token::ALTARICA_REAL;
|
||||
int return token::ALTARICA_INTEGER;
|
||||
INT return token::ALTARICA_INTEGER;
|
||||
STRUCT return token::ALTARICA_STRUCT;
|
||||
"struct" return token::ALTARICA_STRUCT;
|
||||
TCURTS return token::ALTARICA_TCURTS;
|
||||
tcurts return token::ALTARICA_TCURTS;
|
||||
law return token::ALTARICA_LAW;
|
||||
remark return token::ALTARICA_REMARK;
|
||||
attribute return token::ALTARICA_ATTRIBUTE;
|
||||
global return token::ALTARICA_GLOBAL;
|
||||
|
||||
[-+]?[0-9]*"."[0-9]+([eE][+-]?[0-9]+)? yylval->fl = atof(yytext); return token::ALTARICA_FLOAT;
|
||||
[1-9][0-9]*|0 yylval->ui = atoi(yytext) ; return token::ALTARICA_UNSIGNED_INTEGER;
|
||||
[a-zA-Z_][a-zA-Z_0-9"^"]* yylval->st = new std::string (yytext); return token::ALTARICA_IDENTIFIER;
|
||||
\".*\" return token::ALTARICA_STRING;
|
||||
|
||||
|
||||
|
||||
"//".* { /* ignore comments */ }
|
||||
<INITIAL>{
|
||||
"/*" BEGIN(IN_COMMENT);
|
||||
}
|
||||
<IN_COMMENT>{
|
||||
"*"+"/" BEGIN(INITIAL);
|
||||
[^*\n]* { /* eat comment in chunks */ }
|
||||
"*"+[^*/\n]* { /* eat the lone star */ }
|
||||
\n yylineno++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
{blank}+ yylloc->step();
|
||||
[\n\r]+ yylloc->lines(yyleng); yylloc->step(); yylineno += yyleng;
|
||||
|
||||
%%
|
||||
|
||||
|
||||
2303
src/grammars/altarica/altarica.yy
Normal file
2303
src/grammars/altarica/altarica.yy
Normal file
File diff suppressed because it is too large
Load Diff
58
src/grammars/altarica/altarica_driver.cc
Normal file
58
src/grammars/altarica/altarica_driver.cc
Normal file
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "altarica_driver.hh"
|
||||
#include "altarica_parser.hh"
|
||||
#include "altarica_lexer.h"
|
||||
#include "grammars/details/parsingdriverbaseimpl.hh"
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
altarica_driver::altarica_driver(epoch::ParsingDriverReporter& reporter, const std::string& parsedRessource,
|
||||
bool traceScanning, bool traceParsing)
|
||||
: epoch::ParsingDriverBase(reporter, parsedRessource, traceScanning, traceParsing)
|
||||
{
|
||||
amodel = new epoch::altarica::AltaricaModel();
|
||||
}
|
||||
|
||||
|
||||
altarica_driver::~altarica_driver() {}
|
||||
|
||||
|
||||
|
||||
int altarica_driver::Parse () {
|
||||
int parsingResult = epoch::ParsingDriverBase::ParseFile(*this);
|
||||
ClearRuleStack();
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void altarica_driver::DeleteRule(boost::any& rule) {
|
||||
if (DeleteRuleHelper<std::string>(rule)) return;
|
||||
// No match: memory leak!
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Rule with type ") + rule.type().name() + " not deleted!"));
|
||||
}
|
||||
77
src/grammars/altarica/altarica_driver.hh
Normal file
77
src/grammars/altarica/altarica_driver.hh
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTARICA_DRIVER_H
|
||||
#define ALTARICA_DRIVER_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "grammars/altarica/altarica_parser.hh"
|
||||
#include "grammars/parsingdriverbase.hh"
|
||||
#include "grammars/altarica/AltaricaModel.hh"
|
||||
|
||||
|
||||
|
||||
#undef YY_DECL
|
||||
#define YY_DECL epoch::altarica::altarica_parser::token_type yylex (epoch::altarica::altarica_parser::semantic_type * yylval, epoch::altarica::altarica_parser::location_type * yylloc, altarica_driver & driver, void* yyscanner)
|
||||
|
||||
YY_DECL;
|
||||
|
||||
|
||||
|
||||
class altarica_driver : public epoch::ParsingDriverBase {
|
||||
public :
|
||||
altarica_driver(epoch::ParsingDriverReporter& reporter, const std::string& parsedRessource,
|
||||
bool traceScanning = false, bool traceParsing = false);
|
||||
virtual ~altarica_driver();
|
||||
|
||||
epoch::altarica::AltaricaModel * amodel;
|
||||
|
||||
|
||||
virtual int Parse ();
|
||||
|
||||
void scan_end();
|
||||
|
||||
typedef epoch::altarica::altarica_parser Parser;
|
||||
|
||||
private :
|
||||
/**
|
||||
* Deletes a stacked rule (useful for Bison-based parsers)
|
||||
* The derived parsing driver must cast the given rule to any possible rule in the parser
|
||||
* Typically, all %type declared rules must be deleted in case of matching cast
|
||||
* @param rule Rule to delete
|
||||
* @see #ClearRuleStack
|
||||
*/
|
||||
virtual void DeleteRule(boost::any& rule);
|
||||
|
||||
// Bison friend
|
||||
friend class epoch::altarica::altarica_parser;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
56
src/grammars/altarica/details/AltaricaGeneratorImpl.hh
Normal file
56
src/grammars/altarica/details/AltaricaGeneratorImpl.hh
Normal file
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
template <typename Tfunctor>
|
||||
void AltaricaGenerator::generateTransitions(const State& s, const Tfunctor& functor) {
|
||||
std::vector<epoch::altarica::MetaEvent*> * ev = amodel_->getEnabledMetaEventsAll(s.as_);
|
||||
if (ev->size() != 0)
|
||||
for (std::vector<epoch::altarica::MetaEvent*>::iterator i = ev->begin(); i!=ev->end(); ++i) {
|
||||
epoch::altarica::AltaricaState * ns = amodel_->getNextState(s.as_, *i);
|
||||
Transition& transition = functor(std::auto_ptr<AltaricaGenerator::State>(new AltaricaGenerator::State(ns)));
|
||||
transition.m_Probability = (*i)->getProba();
|
||||
transition.m_Reward = (*i)->getReward();
|
||||
delete *i;
|
||||
}
|
||||
else {
|
||||
epoch::altarica::AltaricaState * ns = amodel_->getNextState(s.as_, NULL);
|
||||
Transition& transition = functor(std::auto_ptr<AltaricaGenerator::State>(new AltaricaGenerator::State(ns)));
|
||||
if (amodel_->discrete())
|
||||
transition.m_Probability = 1.0;
|
||||
else
|
||||
transition.m_Probability = 0.0;
|
||||
|
||||
transition.m_Reward = 0.0;
|
||||
|
||||
}
|
||||
|
||||
s.as_->releaseFlowVars();
|
||||
delete ev;
|
||||
}
|
||||
} // namespace altarica
|
||||
} // namespace epoch
|
||||
|
||||
100
src/grammars/altarica/domains/ArrayDomain.cc
Normal file
100
src/grammars/altarica/domains/ArrayDomain.cc
Normal file
@@ -0,0 +1,100 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ArrayDomain.hh"
|
||||
#include "Variable.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
ArrayDomain::ArrayDomain(int asize, Domain*d):asize_(asize), adomain_(d) {
|
||||
}
|
||||
|
||||
unsigned int ArrayDomain::index(std::string arg) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("index asked on a Structured domain")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ArrayDomain::text(unsigned int index) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("text asked on a Structured domain")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Value * ArrayDomain::toValue() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("toOpenValue asked on a Structured domain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ArrayDomain::getMin() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMin asked on an ArrayDomain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ArrayDomain::getMax() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMax asked on a ArrayDomain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Value * ArrayDomain::getFixedValue(int i) {
|
||||
// BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a ArrayDomain")));
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
Value * ArrayDomain::getValue(int i) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a ArrayDomain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Variable*> * ArrayDomain::flatten(Variable* v) const {
|
||||
std::vector<Variable*> * nvv = new std::vector<Variable*>();
|
||||
std::vector<Variable*> * fv = adomain_->flatten(v);
|
||||
for (std::vector<Variable*>::iterator fvi= fv->begin(); fvi != fv->end(); ++fvi) {
|
||||
for (int i = 0; i<asize_; ++i) {
|
||||
Variable * nv = (*fvi)->clone();
|
||||
nv->addToMASecond(i);
|
||||
nvv->push_back(nv);
|
||||
}
|
||||
}
|
||||
delete(fv);
|
||||
return nvv;
|
||||
}
|
||||
|
||||
std::string ArrayDomain::toString() const {
|
||||
return "ARRAY";
|
||||
}
|
||||
ArrayDomain::~ArrayDomain() {
|
||||
// delete(adomain_);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
70
src/grammars/altarica/domains/ArrayDomain.hh
Normal file
70
src/grammars/altarica/domains/ArrayDomain.hh
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ARRAY_DOMAIN_H_
|
||||
#define ALTA_ARRAY_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
//! Array Domain
|
||||
/*!
|
||||
Stucture pour stocker les types array d'altarica
|
||||
*/
|
||||
class ArrayDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
|
||||
//! les types sont stockes dans un vecteur
|
||||
int asize_;
|
||||
Domain* adomain_;
|
||||
|
||||
public:
|
||||
|
||||
//! constructeur qui ne fait rien
|
||||
ArrayDomain(int asize, Domain* d);
|
||||
|
||||
//! calcule un index. attention aux debordements
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const;
|
||||
|
||||
virtual ~ArrayDomain();
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
44
src/grammars/altarica/domains/ContinuousDomain.hh
Normal file
44
src/grammars/altarica/domains/ContinuousDomain.hh
Normal file
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_CONTINUOUS_DOMAIN_H_
|
||||
#define ALTA_CONTINUOUS_DOMAIN_H_
|
||||
|
||||
#include "Domain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ContinuousDomain : public Domain {
|
||||
|
||||
protected :
|
||||
public:
|
||||
virtual ~ContinuousDomain() {};
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const = 0;
|
||||
virtual Value * toValue() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
55
src/grammars/altarica/domains/DiscreteDomain.hh
Normal file
55
src/grammars/altarica/domains/DiscreteDomain.hh
Normal file
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_DISCRETE_DOMAIN_H_
|
||||
#define ALTA_DISCRETE_DOMAIN_H_
|
||||
|
||||
#include "Domain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Value;
|
||||
|
||||
class DiscreteDomain : public Domain {
|
||||
|
||||
protected :
|
||||
unsigned int arity_;
|
||||
public:
|
||||
virtual unsigned int getArity() const {return arity_;}
|
||||
virtual int getMin() const = 0;
|
||||
virtual int getMax() const = 0;
|
||||
virtual unsigned int index(std::string arg) const =0;
|
||||
virtual std::string text(unsigned int index) const = 0;
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const = 0;
|
||||
virtual Value * toValue() const = 0;
|
||||
virtual Value * getValue(int i) = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
virtual ~DiscreteDomain() {};
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
73
src/grammars/altarica/domains/Domain.cc
Normal file
73
src/grammars/altarica/domains/Domain.cc
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#include "Domain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
std::string Domain::get_name() {
|
||||
if (name_.size() > 0)
|
||||
return name_[0];
|
||||
else return std::string("");
|
||||
}
|
||||
|
||||
bool Domain::alias(std::string name) {
|
||||
for (std::vector<std::string>::iterator nit = name_.begin();
|
||||
nit != name_.end(); ++nit) {
|
||||
if (name.compare(*nit) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Domain::set_name(std::string n) {
|
||||
name_.push_back(n);
|
||||
}
|
||||
|
||||
// Domain* Domain::findDomainInVector(std::vector<Domain*> vd, std::string *name) {
|
||||
// for (std::vector<Domain*>::iterator vdit = vd.begin();
|
||||
// vdit != vd.end(); ++vdit)
|
||||
// if ((*vdit)->alias(name))
|
||||
// return *vdit;
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
std::vector<Variable*> * Domain::flatten(Variable* v) const {
|
||||
std::vector<Variable*> * nv = new std::vector<Variable*>();
|
||||
nv->push_back(v);
|
||||
return nv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
63
src/grammars/altarica/domains/Domain.hh
Normal file
63
src/grammars/altarica/domains/Domain.hh
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_DOMAIN_H_
|
||||
#define ALTA_DOMAIN_H_
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Variable;
|
||||
class Value;
|
||||
|
||||
class Domain {
|
||||
protected :
|
||||
std::vector<std::string> name_;
|
||||
public :
|
||||
virtual ~Domain() {};
|
||||
Domain () {}
|
||||
virtual unsigned int getArity() const = 0;
|
||||
virtual std::string get_name();
|
||||
bool alias(std::string name);
|
||||
void set_name(std::string n);
|
||||
static Domain* findDomainInVector(std::vector<Domain*>, std::string name);
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
35
src/grammars/altarica/domains/Domains.hh
Normal file
35
src/grammars/altarica/domains/Domains.hh
Normal file
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_DOMAINS_HH
|
||||
#define ALTA_DOMAINS_HH
|
||||
#include "EnumDomain.hh"
|
||||
#include "RangeDomain.hh"
|
||||
#include "RealDomain.hh"
|
||||
#include "ArrayDomain.hh"
|
||||
#include "StructuredDomain.hh"
|
||||
#include "DiscreteDomain.hh"
|
||||
#include "PredefinedDomain.hh"
|
||||
#endif
|
||||
153
src/grammars/altarica/domains/EnumDomain.cc
Normal file
153
src/grammars/altarica/domains/EnumDomain.cc
Normal file
@@ -0,0 +1,153 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "EnumDomain.hh"
|
||||
#include "Values.hh"
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
EnumDomain::EnumDomain() {
|
||||
indexes = NULL;
|
||||
}
|
||||
|
||||
EnumDomain::EnumDomain(int nSymbols) {
|
||||
symbols.reserve(nSymbols);
|
||||
arity_ = nSymbols;
|
||||
}
|
||||
|
||||
void EnumDomain::addSymbol(std::string s) {
|
||||
// symbols.push_back(s);
|
||||
std::vector<std::string>::iterator i = symbols.begin();
|
||||
for (; i!= symbols.end() && s.compare(*i) > 0 ; ++i);
|
||||
symbols.insert(i, s);
|
||||
arity_ = symbols.size();
|
||||
}
|
||||
|
||||
void EnumDomain::addSymbols(std::vector<std::string> *sv) {
|
||||
for (std::vector<std::string>::iterator svit = sv->begin();
|
||||
svit != sv->end(); ++svit)
|
||||
addSymbol(*svit);
|
||||
}
|
||||
|
||||
unsigned int EnumDomain::index(std::string arg) const {
|
||||
// if (indexes == NULL) {
|
||||
// indexes = new std::map<std::string, int>();
|
||||
// int j = 0;
|
||||
// for (std::vector<std::string>::const_iterator i = symbols.begin();i!=symbols.end(); ++i)
|
||||
// (*indexes)[*i] = j++;
|
||||
// }
|
||||
// return (*indexes)[arg];
|
||||
unsigned int i=0;
|
||||
for (std::vector<std::string>::const_iterator sit = symbols.begin(); sit!=symbols.end(); ++sit) {
|
||||
if (sit->compare(arg) == 0)
|
||||
return i;
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
std::string EnumDomain::text(unsigned int index) const {
|
||||
std::string s;
|
||||
s+=symbols[index];
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Value * EnumDomain::toValue() const {
|
||||
return new ValueSymbol(this);
|
||||
}
|
||||
|
||||
int EnumDomain::getMin() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EnumDomain::getMax() const {
|
||||
return arity_-1;
|
||||
}
|
||||
|
||||
// Value * EnumDomain::getFixedValue(int i) {
|
||||
// return new FixedInt(i);
|
||||
// }
|
||||
|
||||
Value * EnumDomain::getValue(int i) {
|
||||
return new ValueInt(i);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::string>* EnumDomain::getSymbols() const {
|
||||
return &symbols;
|
||||
}
|
||||
|
||||
std::string EnumDomain::toString() const {
|
||||
std::string s;
|
||||
s+= "{ ";
|
||||
for (std::vector<std::string>::const_iterator i = symbols.begin(); i!= symbols.end(); ++i) {
|
||||
s+=*i;
|
||||
s+=" ";
|
||||
}
|
||||
s+= "}";
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool EnumDomain::equals(const EnumDomain *d) const {
|
||||
if (d == this)
|
||||
return true;
|
||||
const std::vector<std::string> * os = d->getSymbols();
|
||||
if (os->size() != symbols.size())
|
||||
return false;
|
||||
for (std::vector<std::string>::const_iterator i = os->begin();
|
||||
i!= os->end(); ++i) {
|
||||
bool isIn = false;
|
||||
for (std::vector<std::string>::const_iterator j = symbols.begin();
|
||||
j!= symbols.end() && !isIn; ++j) {
|
||||
if (j->compare(*i) == 0)
|
||||
isIn = true;
|
||||
}
|
||||
if (!isIn)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EnumDomain::~EnumDomain() {
|
||||
symbols.clear();
|
||||
}
|
||||
|
||||
bool EnumDomain::contains(const std::string s) const {
|
||||
for (std::vector<std::string>::const_iterator i = symbols.begin(); i!= symbols.end(); ++i)
|
||||
if (s.compare(*i)==0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
63
src/grammars/altarica/domains/EnumDomain.hh
Normal file
63
src/grammars/altarica/domains/EnumDomain.hh
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_ENUM_DOMAIN_H_
|
||||
#define ALTA_ENUM_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class EnumDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
std::vector<std::string> symbols;
|
||||
mutable std::map<std::string, int> *indexes;
|
||||
public:
|
||||
EnumDomain(int nSymbols);
|
||||
EnumDomain();
|
||||
const std::vector<std::string>* getSymbols() const;
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
void addSymbol(std::string s);
|
||||
void addSymbols(std::vector<std::string> * ss);
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const ;
|
||||
bool contains(const std::string s) const;
|
||||
bool equals(const EnumDomain *d) const;
|
||||
virtual ~EnumDomain();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
146
src/grammars/altarica/domains/PredefinedDomain.cc
Normal file
146
src/grammars/altarica/domains/PredefinedDomain.cc
Normal file
@@ -0,0 +1,146 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PredefinedDomain.hh"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Variable.hh"
|
||||
#include "Values.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
PredefinedDomain::PredefinedDomain(bool type) {
|
||||
if (type) {
|
||||
bool_ = true;
|
||||
arity_ = 2;
|
||||
} else {
|
||||
bool_ = false;
|
||||
arity_ = UINT32_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int PredefinedDomain::index(std::string arg) const {
|
||||
if (bool_) {
|
||||
if (arg == "TRUE" || arg == "true")
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
return (atoi(arg.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
std::string PredefinedDomain::text(unsigned int index) const {
|
||||
std::string s;
|
||||
if (bool_) {
|
||||
if (index == 1)
|
||||
s+="true";
|
||||
else
|
||||
s+="false";
|
||||
} else {
|
||||
std::string *s = new std::string();
|
||||
s +=index;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Value * PredefinedDomain::toValue() const {
|
||||
if (bool_)
|
||||
return new ValueBool();
|
||||
else
|
||||
return new ValueInt();
|
||||
}
|
||||
|
||||
|
||||
int PredefinedDomain::getMin() const {
|
||||
if (bool_)
|
||||
return 0;
|
||||
else
|
||||
return INT32_MIN;
|
||||
}
|
||||
|
||||
int PredefinedDomain::getMax() const {
|
||||
if (bool_)
|
||||
return 1;
|
||||
else
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
int PredefinedDomain::min(bool b) {
|
||||
if (b)
|
||||
return 0;
|
||||
else
|
||||
return INT32_MIN;
|
||||
}
|
||||
int PredefinedDomain::max(bool b) {
|
||||
if (b)
|
||||
return 1;
|
||||
else
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
|
||||
// Value * PredefinedDomain::getFixedValue(int i) {
|
||||
// if (bool_) {
|
||||
// if (i == 0)
|
||||
// return new FixedBool(true);
|
||||
// else
|
||||
// return new FixedBool(false);
|
||||
// } else {
|
||||
// return new FixedInt(i);
|
||||
// }
|
||||
// }
|
||||
|
||||
Value * PredefinedDomain::getValue(int i) {
|
||||
if (bool_) {
|
||||
if (i == 1)
|
||||
return new ValueBool(true,false);
|
||||
else
|
||||
return new ValueBool(false,true);
|
||||
} else {
|
||||
return new ValueInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string PredefinedDomain::toString() const {
|
||||
if (bool_)
|
||||
return "BOOL";
|
||||
else
|
||||
return "INTEGER";
|
||||
}
|
||||
|
||||
PredefinedDomain::~PredefinedDomain() {}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
src/grammars/altarica/domains/PredefinedDomain.hh
Normal file
59
src/grammars/altarica/domains/PredefinedDomain.hh
Normal file
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_PREDEFINED_DOMAIN_H_
|
||||
#define ALTA_PREDEFINED_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class PredefinedDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
bool bool_; //or int
|
||||
public:
|
||||
PredefinedDomain(bool type);
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const ;
|
||||
static int min(bool);
|
||||
static int max(bool);
|
||||
bool isBooleanDomain() const {return bool_;}
|
||||
virtual ~PredefinedDomain();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
85
src/grammars/altarica/domains/RangeDomain.cc
Normal file
85
src/grammars/altarica/domains/RangeDomain.cc
Normal file
@@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "RangeDomain.hh"
|
||||
#include "Values.hh"
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
RangeDomain::RangeDomain(int inf, int sup):
|
||||
inf_(inf), sup_(sup) {
|
||||
arity_ = sup-inf+1;
|
||||
}
|
||||
|
||||
unsigned int RangeDomain::index(std::string arg) const {
|
||||
return (atoi(arg.c_str()));
|
||||
}
|
||||
|
||||
std::string RangeDomain::text(unsigned int index) const {
|
||||
std::string s;
|
||||
s += index;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Value * RangeDomain::toValue() const {
|
||||
return new ValueInt(this);
|
||||
}
|
||||
|
||||
int RangeDomain::getMin() const {
|
||||
return inf_;
|
||||
}
|
||||
|
||||
int RangeDomain::getMax() const {
|
||||
return sup_;
|
||||
}
|
||||
// Value * RangeDomain::getFixedValue(int i) {
|
||||
// return new FixedInt(i);
|
||||
// }
|
||||
|
||||
Value * RangeDomain::getValue(int i) {
|
||||
ValueInt * oi = new ValueInt();
|
||||
oi->setValue(i);
|
||||
return oi;
|
||||
}
|
||||
std::string RangeDomain::toString() const {
|
||||
std::stringstream ss;
|
||||
// std::string s;
|
||||
ss<< "[";
|
||||
ss<<inf_;
|
||||
ss<<",";
|
||||
ss<<sup_;
|
||||
ss<<"]";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
55
src/grammars/altarica/domains/RangeDomain.hh
Normal file
55
src/grammars/altarica/domains/RangeDomain.hh
Normal file
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_RANGE_DOMAIN_H_
|
||||
#define ALTA_RANGE_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
class RangeDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
int inf_;
|
||||
int sup_;
|
||||
public:
|
||||
RangeDomain(int inf, int sup);
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const;
|
||||
virtual ~RangeDomain() {};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
79
src/grammars/altarica/domains/RealDomain.cc
Normal file
79
src/grammars/altarica/domains/RealDomain.cc
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "RealDomain.hh"
|
||||
#include "DiscreteDomain.hh"
|
||||
#include "values/ValueReal.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
RealDomain::RealDomain(const DiscreteDomain *d) :Domain(){
|
||||
if (d != NULL)
|
||||
di = boost::icl::continuous_interval<double>(d->getMin(), d->getMax(), boost::icl::interval_bounds::closed());
|
||||
else
|
||||
di = boost::icl::continuous_interval<double>(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), boost::icl::interval_bounds::closed());
|
||||
}
|
||||
|
||||
|
||||
RealDomain::RealDomain() :Domain(){
|
||||
di = boost::icl::continuous_interval<double>(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), boost::icl::interval_bounds::closed());
|
||||
}
|
||||
|
||||
RealDomain::RealDomain(double inf, double sup, bool openleft, bool openright) {
|
||||
if (openright)
|
||||
if (openleft)
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::open());
|
||||
else
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::right_open());
|
||||
else
|
||||
if (openleft)
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::left_open());
|
||||
else
|
||||
di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::closed());
|
||||
}
|
||||
|
||||
|
||||
Value * RealDomain::toValue() const {
|
||||
return new ValueReal(this);
|
||||
}
|
||||
|
||||
std::string RealDomain::toString() const {
|
||||
std::stringstream ss;
|
||||
ss << di;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
unsigned int RealDomain::getArity() const {
|
||||
if (di.upper() == di.lower() &&
|
||||
di.bounds() == boost::icl::interval_bounds::closed())
|
||||
return 1;
|
||||
return std::numeric_limits<unsigned int>::infinity();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
src/grammars/altarica/domains/RealDomain.hh
Normal file
59
src/grammars/altarica/domains/RealDomain.hh
Normal file
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_REAL_DOMAIN_H_
|
||||
#define ALTA_REAL_DOMAIN_H_
|
||||
|
||||
#include "Domain.hh"
|
||||
#include <boost/icl/continuous_interval.hpp>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class DiscreteDomain;
|
||||
|
||||
class RealDomain : public Domain {
|
||||
|
||||
protected:
|
||||
boost::icl::continuous_interval<double> di;
|
||||
public:
|
||||
RealDomain(const DiscreteDomain *d);
|
||||
RealDomain();
|
||||
RealDomain(double inf, double sup,
|
||||
bool openleft=false,
|
||||
bool openright=false);
|
||||
virtual ~RealDomain() {};
|
||||
// virtual std::vector<Variable*> * flatten(Variable* v) const = 0;
|
||||
virtual Value * toValue() const;
|
||||
virtual std::string toString() const;
|
||||
virtual unsigned int getArity() const;
|
||||
const boost::icl::continuous_interval<double>& getBI() const {return di;}
|
||||
double getMin() const {return di.lower();}
|
||||
double getMax() const {return di.upper();}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
122
src/grammars/altarica/domains/StructuredDomain.cc
Normal file
122
src/grammars/altarica/domains/StructuredDomain.cc
Normal file
@@ -0,0 +1,122 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "StructuredDomain.hh"
|
||||
#include "Variable.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
|
||||
StructuredDomain::StructuredDomain() {
|
||||
arity_ = 1;
|
||||
}
|
||||
|
||||
void StructuredDomain::addDomains(std::vector<std::string> *domainNames, Domain* domain) {
|
||||
for (std::vector<std::string>::iterator idit = domainNames->begin(); idit!=domainNames->end(); ++idit)
|
||||
addDomain(*idit, domain);
|
||||
}
|
||||
|
||||
void StructuredDomain::addDomain(std::string domainName, Domain* domain) {
|
||||
if (sdomain_.find(domainName) != sdomain_.end())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("bad identifier for domain name"));
|
||||
sdomain_[domainName] = domain;
|
||||
arity_ *= domain->getArity();
|
||||
}
|
||||
|
||||
void StructuredDomain::addMyDomainsTo(StructuredDomain * sd) {
|
||||
for (std::map<std::string, Domain*>::iterator dit = sdomain_.begin();
|
||||
dit != sdomain_.end(); ++dit)
|
||||
sd->addDomain((*dit).first,(*dit).second);
|
||||
}
|
||||
|
||||
|
||||
unsigned int StructuredDomain::index(std::string arg) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("index asked on a Structured domain")));
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string StructuredDomain::text(unsigned int index) const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("text asked on a Structured domain")));
|
||||
return "text associated to a structured domain";
|
||||
}
|
||||
|
||||
Value * StructuredDomain::toValue() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("toValue asked on a Structured domain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int StructuredDomain::getMin() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMin asked on a Structured domain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int StructuredDomain::getMax() const {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getMax asked on a Structured domain")));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Value * StructuredDomain::getFixedValue(int i) {
|
||||
// BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a structDomain")));
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
Value * StructuredDomain::getValue(int i) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getFixedValue(i) asked on a structDomain")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::vector<Variable*> * StructuredDomain::flatten(Variable* v) const {
|
||||
std::vector<Variable*> * nvv = new std::vector<Variable*>();
|
||||
|
||||
for (std::map<std::string, Domain*>::const_iterator i = sdomain_.begin(); i != sdomain_.end(); ++i) {
|
||||
std::vector<Variable*> * fv = (*i).second->flatten(v);
|
||||
for (std::vector<Variable*>::iterator fvi= fv->begin(); fvi != fv->end(); ++fvi) {
|
||||
Variable * nv = (*fvi)->clone();
|
||||
nv->addToMASecond((*i).first);
|
||||
nvv->push_back(nv);
|
||||
}
|
||||
delete(fv);
|
||||
}
|
||||
return nvv;
|
||||
}
|
||||
|
||||
std::string StructuredDomain::toString() const {
|
||||
return "STRUCTURED";
|
||||
}
|
||||
|
||||
StructuredDomain::~StructuredDomain() {
|
||||
sdomain_.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
75
src/grammars/altarica/domains/StructuredDomain.hh
Normal file
75
src/grammars/altarica/domains/StructuredDomain.hh
Normal file
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_STRUCT_DOMAIN_H_
|
||||
#define ALTA_STRUCT_DOMAIN_H_
|
||||
|
||||
#include "DiscreteDomain.hh"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
//! Structured Domain
|
||||
/*!
|
||||
Stucture pour stocker les types complexes d'altarica
|
||||
*/
|
||||
class StructuredDomain : public DiscreteDomain {
|
||||
|
||||
protected:
|
||||
|
||||
//! les types sont stockes dans une map id->type
|
||||
std::map<std::string, Domain*> sdomain_;
|
||||
|
||||
public:
|
||||
|
||||
//! constructeur qui ne fait rien
|
||||
StructuredDomain();
|
||||
|
||||
//! ajout des domaines, cas ou on a plusieurs id pour 1 domaine
|
||||
void addDomains(std::vector<std::string>* domainNames, Domain* domain);
|
||||
|
||||
//! ajout d'un domaine au type structure
|
||||
void addDomain(std::string domainName, Domain *domain);
|
||||
|
||||
void addMyDomainsTo(StructuredDomain * sd);
|
||||
|
||||
//! calcule un index. attention aux debordements
|
||||
virtual unsigned int index(std::string arg) const;
|
||||
virtual std::string text(unsigned int index) const;
|
||||
|
||||
virtual std::vector<Variable*> * flatten(Variable* v) const;
|
||||
virtual Value * toValue() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual Value * getValue(int i);
|
||||
virtual std::string toString() const;
|
||||
virtual ~StructuredDomain();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
70
src/grammars/altarica/expressions/EvaluationVisitor.hh
Normal file
70
src/grammars/altarica/expressions/EvaluationVisitor.hh
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2016 ONERA.
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
// This file is part of EPOCH.
|
||||
// File: EvaluationVisitor.hh
|
||||
// Author: Xavier Pucel
|
||||
// Contact: xavier.pucel@onera.fr
|
||||
//
|
||||
// EPOCH is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// EPOCH is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EVALUATION_VISITOR_HH
|
||||
#define EVALUATION_VISITOR_HH
|
||||
|
||||
#include "Visitor.hh"
|
||||
|
||||
namespace epoch {
|
||||
|
||||
namespace altarica {
|
||||
|
||||
class AltaricaState;
|
||||
class Node;
|
||||
class AltaricaModel;
|
||||
|
||||
class EvaluationVisitor: public Visitor {
|
||||
protected:
|
||||
AltaricaState *state_;
|
||||
const AltaricaModel *amodel_;
|
||||
const Node *node_;
|
||||
|
||||
EvaluationVisitor(const AltaricaModel *am, AltaricaState *s, const Node *n):
|
||||
state_(s), amodel_(am), node_(n) {}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
56
src/grammars/altarica/expressions/Expression.cc
Normal file
56
src/grammars/altarica/expressions/Expression.cc
Normal file
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Expression.hh"
|
||||
#include "ExpressionEvaluator.hh"
|
||||
#include "ExpressionEvaluatorLandmark.hh"
|
||||
#include "ExpressionInfoVar.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
Value * Expression::evaluate(const AltaricaModel *am, AltaricaState *s, const Node*n, bool assert) const {
|
||||
ExpressionEvaluator evf(am, s,n,assert);
|
||||
accept(&evf);
|
||||
Value * fv = evf.getValue();
|
||||
return fv;
|
||||
}
|
||||
|
||||
Value * Expression::evaluateLM(const AltaricaModel *am, LandmarkState *lms, const Node*n, bool assert) const {
|
||||
ExpressionEvaluatorLandmark evlm(am, lms,n,assert);
|
||||
accept(&evlm);
|
||||
Value * fv = evlm.getValue();
|
||||
return fv;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Variable*> * Expression::infoVars(const AltaricaModel *am, const Node *n, bool flow, bool computed) const {
|
||||
ExpressionInfoVar eiv(flow, computed, am, NULL, n);
|
||||
accept(&eiv);
|
||||
std::vector<Variable*> * vars = eiv.getVars();
|
||||
return vars;
|
||||
}
|
||||
73
src/grammars/altarica/expressions/Expression.hh
Normal file
73
src/grammars/altarica/expressions/Expression.hh
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_H_
|
||||
#define ALTA_EXPRESSION_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Visitor.hh"
|
||||
#include "../Node.hh"
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class Visitor;
|
||||
class AltaricaState;
|
||||
class LandmarkState;
|
||||
class Node;
|
||||
class Value;
|
||||
class Variable;
|
||||
class AltaricaModel;
|
||||
|
||||
class Expression {
|
||||
|
||||
|
||||
protected:
|
||||
Expression() {}
|
||||
|
||||
|
||||
public:
|
||||
virtual void accept(Visitor * v) const = 0;
|
||||
|
||||
virtual Expression * clone() const = 0;
|
||||
|
||||
virtual ~Expression() {};
|
||||
|
||||
virtual std::string toString() const = 0;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const = 0;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const = 0;
|
||||
|
||||
Value * evaluate(const AltaricaModel *am, AltaricaState *s, const Node* n, bool assert = false) const;
|
||||
Value * evaluateLM(const AltaricaModel *am, LandmarkState *lms, const Node* n, bool assert = false) const;
|
||||
std::vector<Variable*> * infoVars(const AltaricaModel *am, Node const * const n, bool flow, bool computed) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
85
src/grammars/altarica/expressions/ExpressionADD.cc
Normal file
85
src/grammars/altarica/expressions/ExpressionADD.cc
Normal file
@@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionADD.hh"
|
||||
#include "Visitor.hh"
|
||||
#include "ExpressionMUL.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
ExpressionADD * ExpressionADD::clone() const {
|
||||
ExpressionADD * nea = new ExpressionADD(left_->clone(), right_->clone());
|
||||
if (add_type_ == 0)
|
||||
nea->setPlus();
|
||||
else
|
||||
nea ->setMinus();
|
||||
return nea;
|
||||
|
||||
}
|
||||
|
||||
std::string ExpressionADD::toString() const {
|
||||
std::string s;
|
||||
s+= left_->toString();
|
||||
if (add_type_ == 0)
|
||||
s+= " + ";
|
||||
else
|
||||
s+= " - ";
|
||||
s+= right_->toString();
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionADD::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, am);
|
||||
if (add_type_ == 0)
|
||||
s+= " + ";
|
||||
else
|
||||
s+= " - ";
|
||||
s+= right_->toString(n, am);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionADD::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, f, am);
|
||||
if (add_type_ == 0)
|
||||
s+= " + ";
|
||||
else
|
||||
s+= " - ";
|
||||
s+= right_->toString(n, f, am);
|
||||
return s;
|
||||
}
|
||||
ExpressionADD::~ExpressionADD() {
|
||||
delete left_;
|
||||
delete right_;
|
||||
}
|
||||
|
||||
void ExpressionADD::accept(Visitor* v) const {
|
||||
v->visitADD(this);
|
||||
}
|
||||
76
src/grammars/altarica/expressions/ExpressionADD.hh
Normal file
76
src/grammars/altarica/expressions/ExpressionADD.hh
Normal file
@@ -0,0 +1,76 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_ADD_H_
|
||||
#define ALTA_EXPRESSION_ADD_H_
|
||||
|
||||
|
||||
#include "ExpressionARITH.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ExpressionMUL;
|
||||
|
||||
class ExpressionADD : public ExpressionARITH {
|
||||
|
||||
private:
|
||||
|
||||
ExpressionADD * left_;
|
||||
ExpressionMUL * right_;
|
||||
short add_type_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionADD(): left_(NULL), right_(NULL) {}
|
||||
virtual ~ExpressionADD();
|
||||
ExpressionADD(ExpressionADD *l, ExpressionMUL *r) : ExpressionARITH(), left_(l), right_(r) {}
|
||||
|
||||
|
||||
void setPlus() {add_type_ = 0;}
|
||||
void setMinus() {add_type_ = 1;}
|
||||
const ExpressionADD * getLeft() const {return left_;}
|
||||
const ExpressionMUL * getRight() const {return right_;}
|
||||
|
||||
short getType() const {return add_type_;}
|
||||
|
||||
virtual ExpressionADD * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const;
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const ;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const ;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
54
src/grammars/altarica/expressions/ExpressionAND.cc
Normal file
54
src/grammars/altarica/expressions/ExpressionAND.cc
Normal file
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionAND.hh"
|
||||
#include "ExpressionLOG.hh"
|
||||
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
ExpressionAND::~ExpressionAND() {
|
||||
delete left_;
|
||||
delete right_;
|
||||
}
|
||||
|
||||
ExpressionAND * ExpressionAND::clone() const {
|
||||
return new ExpressionAND(left_->clone(), right_->clone());
|
||||
}
|
||||
|
||||
std::string ExpressionAND::toString() const {
|
||||
return left_->toString() + " and " + right_->toString();
|
||||
}
|
||||
|
||||
std::string ExpressionAND::toString(const Node *n, const AltaricaModel& am) const {
|
||||
return left_->toString(n, am) + " and " + right_->toString(n, am);
|
||||
}
|
||||
|
||||
std::string ExpressionAND::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
return left_->toString(n, f, am) + " and " + right_->toString(n, f, am);
|
||||
}
|
||||
71
src/grammars/altarica/expressions/ExpressionAND.hh
Normal file
71
src/grammars/altarica/expressions/ExpressionAND.hh
Normal file
@@ -0,0 +1,71 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_AND_H_
|
||||
#define ALTA_EXPRESSION_AND_H_
|
||||
|
||||
|
||||
#include "ExpressionOR.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ExpressionLOG;
|
||||
|
||||
class ExpressionAND : public ExpressionOR {
|
||||
|
||||
private:
|
||||
|
||||
ExpressionAND * left_;
|
||||
ExpressionLOG * right_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionAND(): left_(NULL), right_(NULL) {}
|
||||
virtual ~ExpressionAND();
|
||||
ExpressionAND(ExpressionAND *l, ExpressionLOG *r) : ExpressionOR(), left_(l), right_(r) {}
|
||||
|
||||
|
||||
const ExpressionAND * getLeft() const {return left_;}
|
||||
const ExpressionLOG * getRight() const {return right_;}
|
||||
|
||||
virtual ExpressionAND * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitAND(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
91
src/grammars/altarica/expressions/ExpressionARITH.cc
Normal file
91
src/grammars/altarica/expressions/ExpressionARITH.cc
Normal file
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ExpressionARITH.hh"
|
||||
#include "ExpressionADD.hh"
|
||||
|
||||
using namespace epoch::altarica;
|
||||
|
||||
|
||||
|
||||
ExpressionARITH * ExpressionARITH::clone() const {
|
||||
ExpressionARITH * nea = new ExpressionARITH(left_->clone(), right_->clone());
|
||||
switch (arith_type_) {
|
||||
case 0: nea->setInf(); break;
|
||||
case 1: nea->setSup(); break;
|
||||
case 2: nea->setInfEq(); break;
|
||||
case 3: nea->setSupEq(); break;
|
||||
}
|
||||
return nea;
|
||||
}
|
||||
|
||||
|
||||
std::string ExpressionARITH::toString() const {
|
||||
std::string s;
|
||||
s+= left_->toString();
|
||||
switch (arith_type_) {
|
||||
case 0: s+= " < "; break;
|
||||
case 1: s+= " > "; break;
|
||||
case 2: s+= " <= "; break;
|
||||
case 3: s+= " >= "; break;
|
||||
}
|
||||
s+= right_->toString();
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionARITH::toString(const Node *n, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, am);
|
||||
switch (arith_type_) {
|
||||
case 0: s+= " < "; break;
|
||||
case 1: s+= " > "; break;
|
||||
case 2: s+= " <= "; break;
|
||||
case 3: s+= " >= "; break;
|
||||
}
|
||||
s+= right_->toString(n, am);
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ExpressionARITH::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
|
||||
std::string s;
|
||||
s+= left_->toString(n, f, am);
|
||||
switch (arith_type_) {
|
||||
case 0: s+= " < "; break;
|
||||
case 1: s+= " > "; break;
|
||||
case 2: s+= " <= "; break;
|
||||
case 3: s+= " >= "; break;
|
||||
}
|
||||
s+= right_->toString(n, f, am);
|
||||
return s;
|
||||
}
|
||||
|
||||
ExpressionARITH::~ExpressionARITH() {
|
||||
delete left_;
|
||||
delete right_;
|
||||
}
|
||||
|
||||
80
src/grammars/altarica/expressions/ExpressionARITH.hh
Normal file
80
src/grammars/altarica/expressions/ExpressionARITH.hh
Normal file
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
|
||||
* Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
|
||||
* l'IRT AESE (IRT Saint Exupéry).
|
||||
* Tous droits réservés.
|
||||
*
|
||||
* Ce programme et les éléments qui l'accompagnent sont mis à disposition
|
||||
* aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
|
||||
* au droit français et respectant les principes de diffusion des logiciels libres.
|
||||
* Vous pouvez utiliser, modifier et/ou redistribuer ce programme
|
||||
* sous les conditions de la licence CeCILL-C (http://www.cecill.info).
|
||||
|
||||
* This software is property of ONERA (the French Aerospace Lab) and of
|
||||
* the IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the CeCILL-C license under French law and
|
||||
* abiding by the rules of distribution of free software.
|
||||
* You can use, modify and/ or redistribute the software under the terms of
|
||||
* the CeCILL-C license (http://www.cecill.info).
|
||||
*
|
||||
* Contributeurs/contributors:
|
||||
* Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
|
||||
* Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ALTA_EXPRESSION_ARITH_H_
|
||||
#define ALTA_EXPRESSION_ARITH_H_
|
||||
|
||||
|
||||
#include "ExpressionLOG.hh"
|
||||
|
||||
|
||||
|
||||
namespace epoch {
|
||||
namespace altarica {
|
||||
|
||||
class ExpressionADD;
|
||||
|
||||
class ExpressionARITH : public ExpressionLOG {
|
||||
|
||||
private:
|
||||
|
||||
ExpressionARITH * left_;
|
||||
ExpressionADD * right_;
|
||||
short arith_type_;
|
||||
|
||||
|
||||
public:
|
||||
ExpressionARITH(): left_(NULL), right_(NULL) {}
|
||||
virtual ~ExpressionARITH();
|
||||
ExpressionARITH(ExpressionARITH *l, ExpressionADD *r) : ExpressionLOG(), left_(l), right_(r) {}
|
||||
|
||||
|
||||
|
||||
void setInf() {arith_type_ = 0;}
|
||||
void setSup() {arith_type_ = 1;}
|
||||
void setInfEq() {arith_type_ = 2;}
|
||||
void setSupEq() {arith_type_ = 3;}
|
||||
|
||||
const ExpressionARITH * getLeft() const {return left_;}
|
||||
const ExpressionADD * getRight() const {return right_;}
|
||||
short getType() const {return arith_type_;}
|
||||
|
||||
|
||||
virtual ExpressionARITH * clone() const;
|
||||
|
||||
virtual void accept(Visitor* v) const {v->visitARITH(this);}
|
||||
virtual std::string toString() const;
|
||||
virtual std::string toString(const Node *n, const AltaricaModel& am) const;
|
||||
virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user