From: stephane Domas Date: Mon, 22 May 2017 07:28:30 +0000 (+0200) Subject: patter compat continued X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/commitdiff_plain/84eeae848c9d322ea4c935b8ec7338f69becbc10 patter compat continued --- diff --git a/AbstractBlock.h b/AbstractBlock.h index 9216212..aee8c99 100644 --- a/AbstractBlock.h +++ b/AbstractBlock.h @@ -70,6 +70,7 @@ public: BlockParameter* getParameterFromName(QString name); // patterns + virtual bool checkInputPatternCompatibility() = 0; virtual bool computeOutputPattern(int nbExec = -1) = 0; protected: diff --git a/FunctionalBlock.cpp b/FunctionalBlock.cpp index ac27de4..66e89b4 100644 --- a/FunctionalBlock.cpp +++ b/FunctionalBlock.cpp @@ -22,6 +22,12 @@ FunctionalBlock::FunctionalBlock(GroupBlock *_parent, ReferenceBlock *_reference else { implementation = reference->getImplementations().at(0); } + lengthAP = -1; + lengthCP = -1; + lengthIP = -1; + lengthOP = -1; + lengthPP = -1; + delta = -1; } @@ -397,6 +403,11 @@ double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) } void FunctionalBlock::createInputPattern() { + static QString fctName = "FunctionalBlock::createInputPattern())"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + lengthIP = -1; foreach(AbstractInterface* iface, getControlInputs()) { ConnectedInterface* connIface = AI_TO_CON(iface); @@ -486,7 +497,15 @@ bool FunctionalBlock::createAdmittance(int nbExec) { } } } - + // turn all X into 0 + QMapIterator* > iterA(admittance); + while (iterA.hasNext()) { + iterA.next(); + QList* pattern = iterA.value(); + for(int i=0;isize();i++) { + if (pattern->at(i) == -1) pattern->replace(i,0); + } + } return true; } @@ -508,6 +527,24 @@ bool FunctionalBlock::checkInputPatternCompatibility() { ok = createAdmittance(nbExec); if (!ok) return false; + int clock = 0; // index in IP + int i = 0; // index in AP + while (clock < lengthIP) { + if (samePatterns(inputPattern,clock,admittance,i)) { + clock++; + i++; + } + else { + if (isValidDataGroup(admittance,i)) { + + } + else { + // IP and AP are not equal and AP is a valid group -> not compatible + return false; + } + + } + } return true; } @@ -638,6 +675,23 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { return true; } +bool FunctionalBlock::samePatterns(const QMap* >& patternSrc, int srcCol, const QMap* >& patternDest, int destCol) { + + if (patternSrc.size() != patternDest.size()) return false; + QMapIterator* > iterSrc(patternSrc); + QMapIterator* > iterDest(patternDest); + while (iterSrc.hasNext()) { + iterSrc.next(); + iterDest.next(); + QList* srcPat = iterSrc.value(); + QList* destPat = iterDest.value(); + if (srcCol >= srcPat->size()) return false; + if (destCol >= destPat->size()) return false; + if (srcPat->at(srcCol) != destPat->at(destCol)) return false; + } + return true; +} + bool FunctionalBlock::canCombinePatterns(const QMap* >& patternSrc, int srcCol, QMap* > patternDest, int destCol) { if (patternSrc.size() != patternDest.size()) return false; QMapIterator* > iterSrc(patternSrc); diff --git a/FunctionalBlock.h b/FunctionalBlock.h index 6f47a00..f27bef6 100644 --- a/FunctionalBlock.h +++ b/FunctionalBlock.h @@ -56,7 +56,12 @@ public: QString getReferenceHashMd5(); // patterns - bool createPatterns(); + bool createPatterns(); // called in Graph, before checking compatibility and computing output pattern + bool checkInputPatternCompatibility(); + bool computeOutputPattern(int nbExec = -1); + +private: + // patterns bool createDelta(); bool createConsumptionPattern(); // initialize a QList for each interface from patterns defined in implementation bool createProductionPattern(); // initialize a QList for each interface from patterns defined in implementation @@ -67,14 +72,20 @@ public: void createInputPattern(); void clearInputPattern(); int getNumberOfExecution(); // compute number of block execution from inputPattern and delta - bool checkInputPatternCompatibility(); - bool computeOutputPattern(int nbExec = -1); -private: - // patterns double evaluateExpression(const QString& expression, bool* ok); QList* expandPattern(const QString& patternIn, bool* ok); void expandPatternRecur(const QString& patternIn, int* offset, bool* ok, QList *patternOut); + /*! + * \brief samePatterns + * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest) + * \param srcCol the column index within patternSrc + * \param patternDest the pattern that must be tested with patternSrc + * \param destCol the column index within patternDest + * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...) + leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before. + */ + bool samePatterns(const QMap* >& patternSrc, int srcCol, const QMap* >& patternDest, int destCol); /*! * \brief canCombinePatterns * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc) diff --git a/GroupBlock.cpp b/GroupBlock.cpp index 2fc3012..1560d98 100644 --- a/GroupBlock.cpp +++ b/GroupBlock.cpp @@ -105,7 +105,7 @@ void GroupBlock::removeGenericParameter(QString name) { if (p != NULL) params.removeAll(p); } -void GroupBlock::initInputPattern() { +void GroupBlock::createInputPattern() { foreach(AbstractInterface* iface, getControlInputs()) { ConnectedInterface* connIface = AI_TO_CON(iface); QList* pattern = new QList(*(connIface->getConnectedFrom()->getOutputPattern())); @@ -113,6 +113,10 @@ void GroupBlock::initInputPattern() { } } +bool GroupBlock::checkInputPatternCompatibility() { + return true; +} + bool GroupBlock::computeOutputPattern(int nbExec) { static QString fctName = "GroupBlock::computeOutputPattern()"; @@ -123,8 +127,9 @@ bool GroupBlock::computeOutputPattern(int nbExec) { cout << "computing output pattern of group " << qPrintable(name) << endl; bool canCompute = true; + bool compatible = true; // get the input pattern on each inputs - initInputPattern(); + createInputPattern(); cout << "Input pattern OK" << endl; // find blocks that are connected to that inputs and generators @@ -158,8 +163,13 @@ bool GroupBlock::computeOutputPattern(int nbExec) { while (!fifo.isEmpty()) { AbstractBlock* block = fifo.takeFirst(); - if (block->getPatternComputed()) continue; // block has laready been processed - + if (block->getPatternComputed()) continue; // block has already been processed + + compatible = block->checkInputPatternCompatibility(); + if (!compatible) { + cout << qPrintable(block->getName()) << " is not compatible with his input pattern" << endl; + break; + } canCompute = block->computeOutputPattern(); if (!canCompute) { cout << "cannot finalize output pattern computation of " << qPrintable(block->getName()) << endl; diff --git a/GroupBlock.h b/GroupBlock.h index 4a147ab..27e43cc 100644 --- a/GroupBlock.h +++ b/GroupBlock.h @@ -42,6 +42,7 @@ public: // public attributes static int counter; + bool checkInputPatternCompatibility(); bool computeOutputPattern(int nbExec = -1); private: @@ -54,12 +55,12 @@ private: */ /*! - * \brief initInputPattern + * \brief createInputPattern * Since input GroupInterface are just tunnels to input interfaces of inner blocks, they must * have an output pattern that can be provided to inner interfaces. That outpu pattern is just * found by taking the output pattern of the connectedFrom interface. */ - void initInputPattern(); + void createInputPattern(); bool topGroup; diff --git a/ReferenceBlock.cpp b/ReferenceBlock.cpp index 12db4b4..89bde3a 100644 --- a/ReferenceBlock.cpp +++ b/ReferenceBlock.cpp @@ -567,6 +567,10 @@ QDataStream& operator>>(QDataStream &in, ReferenceBlock &b) { return in; } +bool ReferenceBlock::checkInputPatternCompatibility() { + return false; +} + bool ReferenceBlock::computeOutputPattern(int nbExec) { // does strictly nothing return false; diff --git a/ReferenceBlock.h b/ReferenceBlock.h index b10c142..8212fcd 100644 --- a/ReferenceBlock.h +++ b/ReferenceBlock.h @@ -68,6 +68,7 @@ public: private: // patterns + bool checkInputPatternCompatibility(); bool computeOutputPattern(int nbExec = -1); }; diff --git a/blast.creator.user b/blast.creator.user index acd48e9..9bc7661 100755 --- a/blast.creator.user +++ b/blast.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/lib/implementations/impls.bmf b/lib/implementations/impls.bmf index f108eac..8d7e296 100644 Binary files a/lib/implementations/impls.bmf and b/lib/implementations/impls.bmf differ