// connect ctInc
//ctInc.connect(ctIncIn, ctIncH.input);
//ctInc.connect(ctIncH.output, ctIncI.input);
ctInc.connect(ctIncIn, ctIncI.input);
Relation ctIncR2 = ctInc.newRelation("R2");
ctIncGF.output.link(ctIncR2);
ctIncD.trigger.link(ctIncR2);
ctIncTr.link(ctIncR2);
ctInc.connect(ctIncD.output, ctIncOut);
//ctInc.connect(ctIncS.output, ctIncSt);
TypedIORelation ctIncR1 = (TypedIORelation) ctInc
.newRelation("CTIncR1");
ctIncI.output.link(ctIncR1);
//ctIncS.input.link(ctIncR1);
ctIncGFi.link(ctIncR1);
ctIncSt.link(ctIncR1);
CTEmbeddedDirector ctIncDir = new CTEmbeddedDirector(ctInc, "CTIncDir");
//ctIncDir.addDebugListener(dbl);
CTCompositeActor ctDec = new CTCompositeActor(hs, "Decreasing");
//ctDec.addDebugListener(dbl);
//ZeroOrderHold ctDecH = new ZeroOrderHold(ctDec, "Hold");
Integrator ctDecI = new Integrator(ctDec, "Integrator");
Scale ctGain = new Scale(ctDec, "Gain");
ZeroCrossingDetector ctDecD = new ZeroCrossingDetector(ctDec, "ZD");
Expression ctDecGF = new Expression(ctDec, "EXPRESSION");
TypedIOPort ctDecGFi = (TypedIOPort) ctDecGF.newPort("in");
ctDecGFi.setInput(true);
ctDecGFi.setTypeEquals(BaseType.DOUBLE);
ctDecGF.output.setTypeEquals(BaseType.DOUBLE);
ctDecGF.expression.setExpression("in + 0.0");
// the ports
TypedIOPort ctDecIn = (TypedIOPort) ctDec.newPort("input");
ctDecIn.setInput(true);
ctDecIn.setTypeEquals(BaseType.DOUBLE);
TypedIOPort ctDecOut = (TypedIOPort) ctDec.newPort("output");
ctDecOut.setOutput(true);
ctDecOut.setTypeEquals(BaseType.DOUBLE);
TypedIOPort ctDecSt = (TypedIOPort) ctDec.newPort("state");
ctDecSt.setOutput(true);
ctDecSt.setTypeEquals(BaseType.DOUBLE);
TypedIOPort ctDecTr = (TypedIOPort) ctDec.newPort("trig");
ctDecTr.setOutput(true);
ctDecTr.setTypeEquals(BaseType.DOUBLE);
// connect ctDec
//ctDec.connect(ctDecIn, ctDecH.input);
//ctDec.connect(ctDecH.output, ctGain.input);
ctDec.connect(ctDecIn, ctGain.input);
ctDec.connect(ctGain.output, ctDecI.input);
Relation ctDecR2 = ctDec.newRelation("R2");
ctDecGF.output.link(ctDecR2);
ctDecD.trigger.link(ctDecR2);
ctDecTr.link(ctDecR2);
ctDec.connect(ctDecD.output, ctDecOut);
//ctDec.connect(ctDecS.output, ctDecSt);
TypedIORelation ctDecR1 = (TypedIORelation) ctDec
.newRelation("CTDecR1");
ctDecI.output.link(ctDecR1);
//ctDecS.input.link(ctDecR1);
ctDecGFi.link(ctDecR1);
ctDecSt.link(ctDecR1);
CTEmbeddedDirector ctDecDir = new CTEmbeddedDirector(ctDec, "CTDecDir");
//ctDecDir.addDebugListener(dbl);
ctrlInc.refinementName.setExpression("Increasing");
ctrlDec.refinementName.setExpression("Decreasing");
// connect hs
TypedIORelation hsr1 = (TypedIORelation) hs.newRelation("HSr1");
hsin.link(hsr1);
ctIncIn.link(hsr1);
ctDecIn.link(hsr1);
TypedIORelation hsr2 = (TypedIORelation) hs.newRelation("HSr2");
ctrlIn.link(hsr2);
ctIncOut.link(hsr2);
ctDecOut.link(hsr2);
TypedIORelation hsr3 = (TypedIORelation) hs.newRelation("HSr3");
hsst.link(hsr3);
ctIncSt.link(hsr3);
ctDecSt.link(hsr3);
ctrlSt.link(hsr3);
Relation hsr4 = hs.newRelation("HSr4");
//hstr.link(hsr4);
ctIncTr.link(hsr4);
ctDecTr.link(hsr4);