// this needs to do what usually DefIL does and, in addition, create all the contained variables private void RegisterILAndContent(ParIL parIL, int iteration) { // first create the content: e.g. for ils_earns_loop3: yem_loop3, yse_loop3 ... Dictionary <string, double> content = new Dictionary <string, double>(); foreach (var entry in parIL.GetFlatContent()) { string origVarName = entry.varSpec.name; if (!RegisterVar(origVarName, parIL.description, iteration)) { return; } string storeName = ComposeStoreName(origVarName, iteration); // entry of new il: e.g. name: yem_loop3, factor: 1 if (!content.ContainsKey(storeName)) { content.Add(storeName, entry.addFactor); // the usual case } else { content[storeName] += entry.addFactor; // exception: e.g. il contains two ils, which share variables } } // ... then do do what usually DefIL does, i.e. register the incomelist (e.g. ils_earns_loop3) // note: this IL differs from its original by being "flat", i.e. ils are resolved into their variables infoStore.operandAdmin.RegisterIL( name: ComposeStoreName(parIL.name, iteration), creatorFun: DefFun.Store, description: parIL.description, content: content, warnIfNonMon: false); }
protected override void PrepareNonCommonPar() { // get parameters ParIL parOperatorIL = GetUniquePar <ParIL>(DefPar.IlVarOp.Operator_IL); if (parOperatorIL == null) { return; // error is handled by global check } ParFormula parOperand = GetUniquePar <ParFormula>(DefPar.IlVarOp.Operand); bool useFactors = GetParBoolValueOrDefault(DefFun.IlVarOp, DefPar.IlVarOp.Operand_Factors); ParIL parOperandIL = GetUniquePar <ParIL>(DefPar.IlVarOp.Operand_IL); ParCateg parMulAdd = GetUniquePar <ParCateg>(DefPar.IlVarOp.Operation); if (parMulAdd != null) { mulAdd = parMulAdd.GetCateg(); } ParCateg parSelVar = GetUniquePar <ParCateg>(DefPar.IlVarOp.Sel_Var); if (parSelVar != null) { selVar = parSelVar.GetCateg(); } // assess what to do and check for insufficient or contradictory information if (parOperand != null) { //if (parOperand.IsGlobal()) opTask = OPERAND_TYPE.SCALAR; // out-commented to replace by the weaker condtion below, otherwise it produces an error with constants if (double.TryParse(parOperand.xmlValue, out double x)) { opTask = OPERAND_TYPE.SCALAR; } else { opTask = OPERAND_TYPE.FORMULA; formulaOperand = parOperand; } } else if (parOperandIL != null) { if (!CheckDoubleDef(OPERAND_TYPE.IL)) { return; } } if (useFactors) { if (!CheckDoubleDef(OPERAND_TYPE.FACTORS)) { return; } } if (mulAdd == DefPar.Value.ILVAROP_NEGTOZERO) { if (!CheckDoubleDef(OPERAND_TYPE.NEGTOZERO)) { return; } } if (opTask == OPERAND_TYPE.INVALID) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: missing definition of operand" }); return; } if (opTask == OPERAND_TYPE.IL && parOperandIL.GetFlatContent().Count != parOperatorIL.GetFlatContent().Count) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: incomelists {parOperatorIL.name} and {parOperandIL.name} do not have the same number of variables, operation is not possible" }); return; } // prepare information for run for (int i = 0; i < parOperatorIL.GetFlatContent().Count; ++i) { OpItem oi = new OpItem() { varOperator = parOperatorIL.GetFlatContent()[i].varSpec }; switch (opTask) { case OPERAND_TYPE.FACTORS: oi.numOperand = parOperatorIL.GetFlatContent()[i].addFactor; break; case OPERAND_TYPE.SCALAR: oi.numOperand = parOperand.GetGlobalValue(); break; case OPERAND_TYPE.IL: oi.varOperand = parOperandIL.GetFlatContent()[i].varSpec; break; } opItems.Add(oi); } bool CheckDoubleDef(OPERAND_TYPE ot) { if (opTask == OPERAND_TYPE.INVALID) { opTask = ot; return(true); } infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: contradictory definition of operand" }); return(false); } }