⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dalgo.h

📁 数字电路故障分析之D算法C++实现。按照教科书编写
💻 H
字号:
/*-----------------------------------------------------------------------------
 Unit Name: Dalgo
 Author:    Lincoln Yu
 Purpose:   Implementation of D algorithm. Refer to CAT.pas
 History:
-----------------------------------------------------------------------------*/

//---------------------------------------------------------------------------

#ifndef DalgoH
#define DalgoH
//---------------------------------------------------------------------------

#include <contnrs\arrays.h>
#include <contnrs\tables.h>

#define __Dalgo_debug__

////////////////////////////////
namespace DAlgorithm {
////////////////////////////////

using namespace Tables;

enum DLogic {DL_0, DL_1, DL_D, DL_N, DL_X, DL_E};
typedef TableRow<DLogic> DCube;
typedef ConstArray<DLogic> ConstDCube;
typedef Table<DLogic>   DCubeTable;

enum NodeStyle {None, Input, Output, Intermediate};
typedef Array<NodeStyle> NodeStyles;
typedef ConstArray<NodeStyle> ConstNodeStyles;

enum DRes{Success, IndexTooLarge, NoTest, Failure};

typedef Array<int> CubeMap;

typedef bool DevSel;
typedef Array<DevSel> DevTable;

struct ATableUnit
{
    int curDev;
    int transDIndex;
    DevTable devTable;
};
typedef Array<ATableUnit> ATable;

struct DeviceInfo
{
    int firstOriginalCubeIndex;
    int firstTransDCubeIndex;
    int outpNode;
    NodeStyles devCube;
};
typedef Array<DeviceInfo> DevInfoList;

enum TestNodeRes{Out, NoOut, Fail};

class DAlgorithmRenderer
{
protected:
    int transDEnd;
    DCubeTable originalTable, faultDTable, transDTable;

    int ptFaultD;           // index of current fault-D-cube
    int inputNum;           // number of the input nodes of the circuit

    //  circuit system supplementary info
    int originalNum;
    int transDNum;
    int devNum, nodeNum;
    NodeStyles nodeStyleList;
    DevInfoList devInfoList;
    CubeMap originalDevMap; // original-D-cube-to-device map
    CubeMap transDDevMap;   // trans-D-cube-to-device map

    bool intercube(DCube &cube, const DCube &cube1, const DCube &cube2);

    //  for "autoCreateTransDCube"
    struct _TestPD
    {
        int cubeIndex, devNode, vPD, ptEnd;
        DCube tryCube, transDCube;
        Array<int> ptKeep;
    };
    void add(const DCube &cube);
    void addTransDCube(/* const */ DCube &cube);
    void testPDCheck(_TestPD &testPD);
    void testPD(_TestPD &testPD) const;
    int contained(const DCube &cube1, const DCube &cube2) const;
    void compressTransD();

    bool implication(DCube &res, const DCube &tc);

    //  for "dspec"
    struct _Spec
    {
        ATable aTable;
        DCubeTable tc;
        DCube c;
        int tailOfTC, i, faultDIndex;
    };
    void setTCLen(int index, _Spec &spec) const;
    TestNodeRes testNode(const _Spec &spec) const;
    void initializeAlg(_Spec &spec) const;
    void getNewA(_Spec &spec) const;
    bool selectNewDev(_Spec &spec) const;
    bool selectTransD(_Spec &spec) const;

#ifdef __Dalgo_debug__
    void copyCube(DCube &dest, const DCube &src);
    void setCube(DCube &cube, const DCube &src);
    bool cubeExists(const DCube &cube);

    bool lineConfirm();
#endif

public:
    DAlgorithmRenderer();
    ~DAlgorithmRenderer();

    void setParams(ConstDCube &original, ConstNodeStyles &nodeStyles,
            int nodeNum, int devNum);

    void autoCreateTransDTable();
    void autoCreateFaultDTable();
    const DCubeTable &getTransDTable() const;
    const DCubeTable &getFaultDTable() const;
    const CubeMap &getOriginalDevMap() const;
    const CubeMap &getTransDDevMap() const;
    const DevInfoList &getDevInfoList() const;
    DRes dspec(DCube &resCube, int faultDIndex);

#ifdef __Dalgo_debug__
    static void writeD(DLogic dLogic);
    void showTransD();
    void showFaultD();
    void showDevInfo();
    bool testImplication(DCube &res, const DCube &tc);
#endif
};

}   // namespace DAlgorithm

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -