2 #include "IfaceBlaBoC.hxx"
3 #include "IfaceCeVAS.hxx"
4 #include "IfaceCUSES.hxx"
5 #include "IfaceMaLaES.hxx"
6 #include "Utilities.hxx"
11 template<class C
> class CleanupList
17 typename CleanupList
<C
>::iterator i
;
18 for (i
= CleanupList
<C
>::begin(); i
!= CleanupList
<C
>::end(); i
++)
24 : public iface::blaboc_api::BlaBoC
29 CDA_IMPL_QI1(blaboc_api::BlaBoC
);
31 BBABlaBoC(iface::cellml_api::Model
* aModel
);
34 void variableIsInput(iface::cellml_api::CellMLVariable
* aVariable
)
35 throw(std::exception
&);
36 void variableIsOutput(iface::cellml_api::CellMLVariable
* aVariable
)
37 throw(std::exception
&);
38 void othersAreOutput() throw();
39 void othersAreInput() throw();
40 void computeBlaBoC() throw(std::exception
&);
42 wchar_t* errorMessage() throw();
43 wchar_t* classImplementation() throw(std::exception
&);
47 : public iface::XPCOM::IObject
54 BBAEquation(iface::cellml_api::CellMLElement
* aContext
,
55 iface::mathml_dom::MathMLElement
* aEquation
)
56 : _cda_refcount(1), mContext(aContext
), mEquation(aEquation
), used(false)
60 ObjRef
<iface::cellml_api::CellMLElement
> mContext
;
61 ObjRef
<iface::mathml_dom::MathMLElement
> mEquation
;
62 // Not owning because the model is owned the whole time.
63 // For black-boxes, the input variables.
64 std::list
<iface::cellml_api::CellMLVariable
*> mSourceVariables
;
65 // Only used for black boxes.
66 std::list
<iface::cellml_api::CellMLVariable
*> mOutputs
;
70 void BuildEquationList(std::list
<BBAEquation
*>& eqns
);
71 bool IsEquationExternal(iface::mathml_dom::MathMLApplyElement
* mae
);
72 void ClassifyEquations(std::list
<BBAEquation
*>& eqns
,
73 std::list
<BBAEquation
*>& aBlackBoxes
,
74 std::list
<BBAEquation
*>& aWhiteBoxes
);
76 ObjRef
<iface::cellml_services::CUSES
>& cuses
,
77 ObjRef
<iface::cellml_services::MaLaESTransform
>& mt
79 void determineEquationVariables(
80 iface::cellml_services::CUSES
* cuses
,
81 iface::cellml_services::MaLaESTransform
* mt
,
82 std::list
<BBAEquation
*>& eqns
84 void processConstants(
85 iface::cellml_services::MaLaESTransform
* mt
,
86 iface::cellml_services::CUSES
* cuses
,
87 std::set
<iface::cellml_api::CellMLVariable
*>& allSourceVariables
,
88 std::set
<iface::cellml_api::CellMLVariable
*>& directConstants
,
89 std::set
<iface::cellml_api::CellMLVariable
*>& allConstants
,
90 std::set
<iface::cellml_api::CellMLVariable
*>& wanted
,
91 std::list
<BBAEquation
*>& whiteBoxes
,
92 std::wstring
& aComment
,
94 std::list
<std::wstring
>& aSupplementary
96 void determineEvaluationDAG(
97 std::set
<iface::cellml_api::CellMLVariable
*>& know
,
98 std::set
<iface::cellml_api::CellMLVariable
*>& want
,
99 std::list
<BBAEquation
*>& equations
,
100 std::multimap
<iface::cellml_api::CellMLVariable
*,
101 iface::cellml_api::CellMLVariable
*>& forwardEdges
,
102 std::multimap
<iface::cellml_api::CellMLVariable
*,
103 iface::cellml_api::CellMLVariable
*>& backEdges
105 void dfsComputeSet(iface::cellml_services::MaLaESTransform
* mt
,
106 iface::cellml_services::CUSES
* cuses
,
107 std::set
<iface::cellml_api::CellMLVariable
*>& targets
,
108 std::multimap
<iface::cellml_api::CellMLVariable
*,
109 iface::cellml_api::CellMLVariable
*>& backEdges
,
111 std::list
<std::wstring
>& aSupplementary
113 void dfsComputeVariable
115 iface::cellml_services::MaLaESTransform
* mt
,
116 iface::cellml_services::CUSES
* cuses
,
117 iface::cellml_api::CellMLVariable
* var
,
118 std::multimap
<iface::cellml_api::CellMLVariable
*,
119 iface::cellml_api::CellMLVariable
*>& backEdges
,
121 std::list
<std::wstring
>& aSupplementary
123 void WriteDirectAssignment
126 std::list
<std::wstring
>& aSupplementary
,
127 iface::cellml_services::MaLaESTransform
* mt
,
128 iface::cellml_services::CUSES
* cuses
,
129 iface::cellml_api::CellMLVariable
* var
,
130 iface::mathml_dom::MathMLElement
* lhs
,
131 iface::mathml_dom::MathMLElement
* rhs
133 void determineBlackBoxIO
135 iface::cellml_services::MaLaESTransform
* mt
,
136 iface::cellml_services::CUSES
* cuses
,
137 std::list
<BBAEquation
*>& blackBoxes
,
138 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxInputs
,
139 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxOutputs
,
140 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxIO
,
143 std::wstring
& blackBoxCode
145 void addBlackBoxInput
147 iface::cellml_services::MaLaESTransform
* mt
,
148 iface::cellml_services::CUSES
* cuses
,
150 iface::mathml_dom::MathMLCiElement
* el
,
151 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxInputs
,
152 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxIO
154 void addBlackBoxOutput
156 iface::cellml_services::MaLaESTransform
* mt
,
157 iface::cellml_services::CUSES
* cuses
,
159 iface::mathml_dom::MathMLCiElement
* el
,
160 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxOutputs
,
161 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxIO
165 iface::cellml_services::MaLaESTransform
* mt
,
166 iface::cellml_services::CUSES
* cuses
,
167 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxIO
,
168 std::set
<iface::cellml_api::CellMLVariable
*>& allConstants
,
169 std::set
<iface::cellml_api::CellMLVariable
*>& wanted
,
170 std::list
<BBAEquation
*>& whiteBoxes
,
171 std::list
<BBAEquation
*>& blackBoxes
,
172 std::wstring
& trainingCode
,
173 std::list
<std::wstring
>& supplements
177 iface::cellml_services::MaLaESTransform
* mt
,
178 iface::cellml_services::CUSES
* cuses
,
179 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxInputs
,
180 std::set
<iface::cellml_api::CellMLVariable
*>& blackBoxOutputs
,
181 std::set
<iface::cellml_api::CellMLVariable
*>& allConstants
,
182 std::set
<iface::cellml_api::CellMLVariable
*>& wanted
,
183 std::list
<BBAEquation
*>& whiteBoxes
,
184 std::list
<BBAEquation
*>& blackBoxes
,
185 std::wstring
& runCode
,
186 std::list
<std::wstring
>& supplements
188 void assignVariableIndices(std::set
<iface::cellml_api::CellMLVariable
*>& candidates
,
189 std::wstring
& comment
, uint32_t& count
);
190 void resetSeen(std::set
<iface::cellml_api::CellMLVariable
*>& resetSet
);
191 std::wstring
EscapeString(const std::wstring
& input
);
193 std::wstring mMessage
;
195 ObjRef
<iface::cellml_api::Model
> mModel
;
196 ObjRef
<iface::cellml_services::CeVAS
> mCeVAS
;
197 ObjRef
<iface::cellml_services::AnnotationSet
> mAnnoSet
;
198 // Not owner because mModel already owns them, and we own it.
199 std::set
<iface::cellml_api::CellMLVariable
*> mInputVariableSet
;
200 std::set
<iface::cellml_api::CellMLVariable
*> mOutputVariableSet
;
201 uint32_t mUniqueSolve
, mInputIndex
, mOutputIndex
;
204 class BBABlaBoCBootstrap
205 : public iface::blaboc_api::BlaBoCBootstrap
210 CDA_IMPL_QI1(blaboc_api::BlaBoCBootstrap
);
213 : _cda_refcount(1) {}
215 iface::blaboc_api::BlaBoC
* createBlaBoC(iface::cellml_api::Model
* aModel
)
218 return new BBABlaBoC(aModel
);
221 char* assembleBlaBoC(const wchar_t* aSource
, uint32_t* aLen
) throw();