public override string GetCode(ControllerModel c, CCOLCodeTypeEnum type, string ts) { var sb = new StringBuilder(); var molens = new List <ModuleMolenModel> { c.ModuleMolen }; if (c.Data.MultiModuleReeksen) { molens = c.MultiModuleMolens.Where(x => x.Modules.Any(x2 => x2.Fasen.Any())).ToList(); } switch (type) { case CCOLCodeTypeEnum.RegCRealisatieAfhandelingModules: sb.AppendLine($"{ts}/* versnelde primaire realisaties */"); sb.AppendLine($"{ts}/* ------------------------------ */"); sb.AppendLine($"{ts}/* periode versnelde primaire realisatie - aantal modulen vooruit */"); sb.AppendLine($"{ts}/* -------------------------------------------------------------- */"); // NOTE: all fasen are present in the list in the ML module. others are empty // this accounts for all places below where FasenModuleData is references foreach (var fc in c.ModuleMolen.FasenModuleData) { var r = molens.FirstOrDefault(x => x.Modules.Any(x2 => x2.Fasen.Any(x3 => x3.FaseCyclus == fc.FaseCyclus))); if (r != null) { sb.AppendLine($"{ts}PFPR[{_fcpf}{fc.FaseCyclus}] = ml_fpr({_fcpf}{fc.FaseCyclus}, PRM[{_prmpf}{_prmmlfpr}{fc.FaseCyclus}], PR{r.Reeks}, {r.Reeks}, {r.Reeks}MAX);"); } } sb.AppendLine(""); sb.AppendLine($"{ts}VersneldPrimair_Add();"); sb.AppendLine(""); sb.AppendLine($"{ts}for (fc = 0; fc < FCMAX; ++fc)"); sb.AppendLine($"{ts}{{"); foreach (var r in molens) { sb.AppendLine($"{ts}{ts}set_FPRML_fk_gkl(fc, PR{r.Reeks}, {r.Reeks}, {r.Reeks}MAX, (bool)PFPR[fc]);"); } sb.AppendLine($"{ts}}}"); sb.AppendLine(); if (c.ModuleMolen.LangstWachtendeAlternatief) { sb.AppendLine($"{ts}/* langstwachtende alternatieve realisatie */"); sb.AppendLine($"{ts}/* --------------------------------------- */"); sb.AppendLine(); foreach (var r in molens) { sb.AppendLine($"{ts}afsluiten_aanvraaggebied_pr(PR{r.Reeks}, {r.Reeks});"); } sb.AppendLine(); sb.AppendLine($"{ts}for (fc=0; fc<FCMAX; fc++)"); sb.AppendLine($"{ts}{{"); sb.AppendLine($"{ts}{ts}RR[fc] &= ~BIT5;"); sb.AppendLine($"{ts}{ts}FM[fc] &= ~BIT5;"); sb.AppendLine($"{ts}}}"); sb.AppendLine(); sb.AppendLine($"{ts}/* zet richtingen die alternatief gaan realiseren */"); sb.AppendLine($"{ts}/* terug naar RV als er geen alternatieve ruimte meer is. */"); if (c.Fasen.Any(x => x.WachttijdVoorspeller && molens.Any(x2 => x2.FasenModuleData.Any(x3 => x3.FaseCyclus == x.Naam)))) { sb.AppendLine($"{ts}/* Dit gebeurt niet voor fasen met een wachttijd voorspeller, */"); sb.AppendLine($"{ts}/* of fasen waarvan de voedende richting die heeft. */"); } foreach (var fc in c.ModuleMolen.FasenModuleData) { // find signalgroup instance var ffc = c.Fasen.FirstOrDefault(x => x.Naam == fc.FaseCyclus); // if the sg has no predictor if (ffc != null && !ffc.WachttijdVoorspeller) { // find a potential feeding sg var fcnl = c.InterSignaalGroep.Nalopen.FirstOrDefault(x => x.FaseNaar == fc.FaseCyclus); // if there is a feeding sg, set the sg instance to that sg if (fcnl != null) { ffc = c.Fasen.FirstOrDefault(x => x.Naam == fcnl.FaseVan); } } // if the instance is not null, and it has a predictor, skip setting RR if (ffc != null && ffc.WachttijdVoorspeller) { continue; } sb.AppendLine( $"{ts}RR[{_fcpf}{fc.FaseCyclus}] |= R[{_fcpf}{fc.FaseCyclus}] && AR[{_fcpf}{fc.FaseCyclus}] && (!PAR[{_fcpf}{fc.FaseCyclus}] || ERA[{_fcpf}{fc.FaseCyclus}]) ? BIT5 : 0;"); } sb.AppendLine(); var gelijkstarttuples = CCOLCodeHelper.GetFasenWithGelijkStarts(c); var yes = false; foreach (var gs in gelijkstarttuples.Where(x => c.ModuleMolen.FasenModuleData.Any(x2 => x2.FaseCyclus == x.Item1))) { if (gs.Item2.Count > 1) { yes = true; sb.Append($"{ts}RR[{_fcpf}{gs.Item1}] |= R[{_fcpf}{gs.Item1}] && "); if (gs.Item2.Count > 1) { sb.Append("("); } var i = 0; foreach (var ofc in gs.Item2) { if (ofc == gs.Item1) { continue; } if (i > 0) { sb.Append(" || "); } sb.Append($"(RR[{_fcpf}{ofc}] & BIT5)"); ++i; } if (gs.Item2.Count > 1) { sb.Append(")"); } sb.AppendLine(" ? BIT5 : 0;"); } } if (yes) { sb.AppendLine(); } foreach (var fc in c.ModuleMolen.FasenModuleData) { sb.AppendLine( $"{ts}FM[{_fcpf}{fc.FaseCyclus}] |= (fm_ar_kpr({_fcpf}{fc.FaseCyclus}, PRM[{_prmpf}{_prmaltg}{fc.FaseCyclus}])) ? BIT5 : 0;"); } sb.AppendLine(); AppendNalopenEG_RRFMCorrection(c, sb, ts); var maxtartotig = c.Data.CCOLVersie >= CCOLVersieEnum.CCOL95 && c.Data.Intergroen ? "max_tar_tig" : "max_tar_to"; foreach (var fc in c.ModuleMolen.FasenModuleData) { Tuple <string, List <string> > hasgs = null; foreach (var gs in gelijkstarttuples) { if (gs.Item1 == fc.FaseCyclus && gs.Item2.Count > 1) { hasgs = gs; break; } } if (hasgs != null) { sb.Append( $"{ts}PAR[{_fcpf}{fc.FaseCyclus}] = ({maxtartotig}({_fcpf}{fc.FaseCyclus}) >= PRM[{_prmpf}{_prmaltp}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.Append($"]) && SCH[{_schpf}{_schaltg}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.AppendLine("];"); } else { sb.AppendLine( $"{ts}PAR[{_fcpf}{fc.FaseCyclus}] = ({maxtartotig}({_fcpf}{fc.FaseCyclus}) >= PRM[{_prmpf}{_prmaltp}{fc.FaseCyclus}]) && SCH[{_schpf}{_schaltg}{fc.FaseCyclus}];"); } } sb.AppendLine(); if (c.InterSignaalGroep.Nalopen.Count > 0) { if (c.InterSignaalGroep.Nalopen.Any(x => c.ModuleMolen.FasenModuleData.Any(x2 => x2.FaseCyclus == x.FaseVan))) { sb.AppendLine($"{ts}/* Verzorgen PAR voor voedende richtingen */"); foreach (var nl in c.InterSignaalGroep.Nalopen.Where(x => c.ModuleMolen.FasenModuleData.Any(x2 => x2.FaseCyclus == x.FaseVan))) { var hasgs = gelijkstarttuples.FirstOrDefault(x => x.Item1 == nl.FaseVan && x.Item2.Count > 1); if (hasgs != null) { sb.Append( $"{ts}PAR[{_fcpf}{nl.FaseVan}] = PAR[{_fcpf}{nl.FaseVan}] && PAR[{_fcpf}{nl.FaseNaar}] && ({maxtartotig}({_fcpf}{nl.FaseNaar}) >= (PRM[{_prmpf}{_prmaltp}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.AppendLine($"] + TNL_PAR[{_fcpf}{nl.FaseNaar}]));"); } else { sb.AppendLine( $"{ts}PAR[{_fcpf}{nl.FaseVan}] = PAR[{_fcpf}{nl.FaseVan}] && PAR[{_fcpf}{nl.FaseNaar}] && ({maxtartotig}({_fcpf}{nl.FaseNaar}) >= (PRM[{_prmpf}{_prmaltp}{nl.FaseVan}] + TNL_PAR[{_fcpf}{nl.FaseNaar}]));"); } } sb.AppendLine(); } sb.AppendLine($"{ts}/* Verzorgen PAR voor naloop richtingen */"); if (c.InterSignaalGroep.Nalopen.Any(x => c.ModuleMolen.FasenModuleData.Any(x2 => x2.FaseCyclus == x.FaseVan))) { foreach (var nl in c.InterSignaalGroep.Nalopen.Where(x => c.ModuleMolen.FasenModuleData.Any(x2 => x2.FaseCyclus == x.FaseVan))) { sb.AppendLine( $"{ts}PAR[{_fcpf}{nl.FaseNaar}] = PAR[{_fcpf}{nl.FaseNaar}] || RA[{_fcpf}{nl.FaseVan}] || FG[{_fcpf}{nl.FaseVan}];"); } sb.AppendLine(); } } yes = false; foreach (var gs in gelijkstarttuples.Where(x => c.ModuleMolen.FasenModuleData.Any(x2 => x2.FaseCyclus == x.Item1))) { if (gs.Item2.Count > 1) { yes = true; sb.Append($"{ts}PAR[{_fcpf}{gs.Item1}] = PAR[{_fcpf}{gs.Item1}]"); foreach (var ofc in gs.Item2) { if (ofc == gs.Item1) { continue; } sb.Append($" && (PAR[{_fcpf}{ofc}] || !A[{_fcpf}{ofc}])"); } sb.AppendLine(";"); } } if (yes) { sb.AppendLine(); } yes = false; foreach (var fcm in c.Fasen) { if (fcm.Meeverlengen != NooitAltijdAanUitEnum.Nooit) { var fm = c.FileIngrepen.FirstOrDefault( x => x.TeDoserenSignaalGroepen.Any(x2 => x2.FaseCyclus == fcm.Naam && c.ModuleMolen.FasenModuleData.Any(x3 => x3.FaseCyclus == x2.FaseCyclus))); if (fm != null) { if (!yes) { yes = true; sb.AppendLine(); sb.AppendLine($"{ts}/* Niet alternatief komen tijdens file */"); } sb.AppendLine( $"{ts}if (IH[{_hpf}{_hfile}{fm.Naam}]) PAR[{_fcpf}{fcm.Naam}] = FALSE;"); } } } if (yes) { sb.AppendLine(); } foreach (var gen in CCOLGenerator.OrderedPieceGenerators[CCOLCodeTypeEnum.RegCAlternatieven]) { sb.Append(gen.Value.GetCode(c, CCOLCodeTypeEnum.RegCAlternatieven, ts)); sb.AppendLine(); } sb.AppendLine($"{ts}Alternatief_Add();"); sb.AppendLine(); foreach (var r in molens) { sb.AppendLine($"{ts}langstwachtende_alternatief_modulen(PR{r.Reeks}, {r.Reeks}, {r.Reeks}_MAX);"); } } else if (!c.Data.MultiModuleReeksen) { var r = c.ModuleMolen; sb.AppendLine($"{ts}/* alternatieve realisaties */"); sb.AppendLine($"{ts}/* ------------------------ */"); if (c.ModuleMolen.Modules.SelectMany(x => x.Fasen).Any(x => x.Alternatieven.Any())) { // Build a list of dictionaries for signalgroups that may realize alternatively; // each dictionary contains alternative signalgroups as keys, and a list of primary // signalgroups under whose CV the alternative may realise var modulesWithAlternatives = new List <Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > > >(); foreach (var ml in r.Modules) { var altdict = new Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > >(); foreach (var mlfc in ml.Fasen) { foreach (var amlfc in mlfc.Alternatieven) { if (!altdict.ContainsKey(amlfc.FaseCyclus)) { altdict.Add( amlfc.FaseCyclus, new List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > { new Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc) }); } else { altdict[amlfc.FaseCyclus].Add(new Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc)); } } } modulesWithAlternatives.Add(altdict); } var mlidx = 1; foreach (var moduleWithAlternatives in modulesWithAlternatives) { foreach (var alternativeSignalGroup in moduleWithAlternatives) { var pre = $"{ts}set_FARML({_fcpf}{alternativeSignalGroup.Key}, PR{r.Reeks}, {r.Reeks}, {r.Reeks}_MAX, {r.Reeks}{mlidx}, " .Length; sb.Append( $"{ts}set_FARML({_fcpf}{alternativeSignalGroup.Key}, PR{r.Reeks}, {r.Reeks}, {r.Reeks}_MAX, {r.Reeks}{mlidx}, "); var i = 0; foreach (var primarySignalGroup in alternativeSignalGroup.Value) { if (i > 0) { sb.AppendLine(" || "); sb.Append("".PadLeft(pre)); } ++i; sb.Append($"(bool) (CV[{_fcpf}{primarySignalGroup.Item2.FaseCyclus}] && AlternatieveRuimte({_fcpf}{alternativeSignalGroup.Key}, {_fcpf}{primarySignalGroup.Item2.FaseCyclus}, {_prmpf}{_prmaltg}{mlidx}{alternativeSignalGroup.Key}))"); } sb.AppendLine(");"); } ++mlidx; } sb.AppendLine(); sb.AppendLine($"{ts}for (fc = 0; fc < FCMAX; ++fc)"); sb.AppendLine($"{ts}{{"); sb.AppendLine($"{ts}{ts}RR[fc] &= ~BIT5;"); sb.AppendLine($"{ts}{ts}FM[fc] &= ~BIT5;"); sb.AppendLine($"{ts}}}"); sb.AppendLine(); mlidx = 1; foreach (var moduleWithAlternatives in modulesWithAlternatives) { foreach (var alternativeSignalGroup in moduleWithAlternatives) { var pre = $"{ts}RR[{_fcpf}{alternativeSignalGroup.Key}] |= (AR[{_fcpf}{alternativeSignalGroup.Key}] && RA[{_fcpf}{alternativeSignalGroup.Key}] && " .Length; sb.Append( $"{ts}RR[{_fcpf}{alternativeSignalGroup.Key}] |= (AR[{_fcpf}{alternativeSignalGroup.Key}] && RA[{_fcpf}{alternativeSignalGroup.Key}] && "); var i = 0; foreach (var primarySignalGroup in alternativeSignalGroup.Value) { if (i > 0) { sb.AppendLine(" && "); sb.Append("".PadLeft(pre)); } ++i; sb.Append($"!(CV[{_fcpf}{primarySignalGroup.Item2.FaseCyclus}] && AlternatieveRuimte({_fcpf}{alternativeSignalGroup.Key}, " + $"{_fcpf}{primarySignalGroup.Item2.FaseCyclus}, {_prmpf}{_prmaltg}{mlidx}{alternativeSignalGroup.Key}))"); } sb.AppendLine(") ? BIT5 : 0;"); } ++mlidx; } sb.AppendLine(); mlidx = 1; foreach (var moduleWithAlternatives in modulesWithAlternatives) { foreach (var alternativeSignalGroup in moduleWithAlternatives) { sb.AppendLine( $"{ts}FM[{_fcpf}{alternativeSignalGroup.Key}] |= (AR[{_fcpf}{alternativeSignalGroup.Key}] && " + $"G[{_fcpf}{alternativeSignalGroup.Key}] && fm_ar_kpr({_fcpf}{alternativeSignalGroup.Key}, PRM[{_prmpf}{_prmaltg}{mlidx}{alternativeSignalGroup.Key}])) ? BIT5 : 0;"); } ++mlidx; } AppendNalopenEG_RRFMCorrection(c, sb, ts); } sb.AppendLine(); sb.AppendLine($"{ts}for (fc = 0; fc < FCMAX; ++fc)"); sb.AppendLine($"{ts}{ts}if (SR[fc] && AG[fc])"); sb.AppendLine($"{ts}{ts}{{"); sb.AppendLine($"{ts}{ts}{ts}reset_FARML(fc, PR{r.Reeks}, {r.Reeks}, {r.Reeks}_MAX);"); sb.AppendLine($"{ts}{ts}}}"); sb.AppendLine(); sb.AppendLine($"{ts}Alternatief_Add();"); if (c.HalfstarData.IsHalfstar) { sb.AppendLine($"{ts}Alternatief_halfstar();"); } } return(sb.ToString()); default: return(null); } }
public override void CollectCCOLElements(ControllerModel c) { _myElements = new List <CCOLElement>(); var gelijkstarttuples = CCOLCodeHelper.GetFasenWithGelijkStarts(c); foreach (var fc in c.ModuleMolen.FasenModuleData) { // Vooruit realisaties _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmmlfpr}{fc.FaseCyclus}", fc.ModulenVooruit, CCOLElementTimeTypeEnum.None, _prmmlfpr, fc.FaseCyclus)); } // Alternatieven if (c.ModuleMolen.LangstWachtendeAlternatief) { foreach (var fc in c.ModuleMolen.FasenModuleData) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmaltg}{fc.FaseCyclus}", fc.AlternatieveGroenTijd, CCOLElementTimeTypeEnum.TE_type, _prmaltg, fc.FaseCyclus)); // For prmaltp and schaltg: combine if the signal group is part of a simultaneous synchronisation var gs = gelijkstarttuples.FirstOrDefault(x => x.Item1 == fc.FaseCyclus); if (gs != null) { var namealtp = _prmaltp + string.Join(string.Empty, gs.Item2); var namealtg = _schaltg + string.Join(string.Empty, gs.Item2); var containsaltp = _myElements.Any(i => i.Naam == namealtp); var containsaltg = _myElements.Any(i => i.Naam == namealtg); if (!containsaltp) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( namealtp, fc.AlternatieveRuimte, CCOLElementTimeTypeEnum.TE_type, _prmaltp, "fasen", string.Join(", ", gs.Item2))); } if (!containsaltg) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( namealtg, fc.AlternatiefToestaan ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, _schaltg, "fasen", string.Join(", ", gs.Item2))); } } else { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmaltp}{fc.FaseCyclus}", fc.AlternatieveRuimte, CCOLElementTimeTypeEnum.TE_type, _prmaltp, "fase", fc.FaseCyclus)); _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_schaltg}{fc.FaseCyclus}", fc.AlternatiefToestaan ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, _schaltg, "fase", fc.FaseCyclus)); } } } else { // Build a list of dictionaries for signalgroups that may realize alternatively; // each dictionary contains alternative signalgroups as keys, and a list of primary // signalgroups under whose CV the alternative may realise var altsdict = new List <Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > > >(); foreach (var ml in c.ModuleMolen.Modules) { var altdict = new Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > >(); foreach (var mlfc in ml.Fasen) { foreach (var amlfc in mlfc.Alternatieven) { if (!altdict.ContainsKey(amlfc.FaseCyclus)) { altdict.Add( amlfc.FaseCyclus, new List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > { new Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc) }); } } } altsdict.Add(altdict); } var mlidx = 1; foreach (var alts in altsdict) { foreach (var altg in alts) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmaltg}{mlidx}{altg.Key}", altg.Value.First().Item1.AlternatieveGroenTijd, CCOLElementTimeTypeEnum.TE_type, _prmaltg, altg.Key, "ML" + mlidx)); } ++mlidx; } /* not supported yet * foreach (var r in c.MultiModuleMolens) * { * foreach (var ml in r.Modules) * { * var altdict = * new Dictionary<string, List<Tuple<ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>>>(); * foreach (var mlfc in ml.Fasen) * { * foreach (var amlfc in mlfc.Alternatieven) * { * if (!altdict.ContainsKey(amlfc.FaseCyclus)) * { * altdict.Add( * amlfc.FaseCyclus, * new List<Tuple<ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>> * { * new Tuple<ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc) * }); * } * } * } * altsdict.Add(altdict); * } * var mlidx2 = 1; * foreach (var alts in altsdict) * { * foreach (var altg in alts) * { * _myElements.Add( * CCOLGeneratorSettingsProvider.Default.CreateElement( * $"{_prmaltg}{mlidx}{altg.Key}", * altg.Value.First().Item1.AlternatieveGroenTijd, * CCOLElementTimeTypeEnum.TE_type, * _prmaltg, altg.Key, r.Reeks + mlidx)); * } ++mlidx2; * } * } */ } }
#pragma warning restore 0169 #pragma warning restore 0649 #endregion // Fields #region Properties #endregion // Properties public override void CollectCCOLElements(ControllerModel c) { _MyElements = new List <CCOLElement>(); _MyDetectors = new List <DetectorModel>(); _MyBitmapOutputs = new List <CCOLIOElement>(); _MyBitmapInputs = new List <CCOLIOElement>(); if (c.OVData.OVIngrepen.Count > 0 || c.OVData.HDIngrepen.Count > 0) { /* Variables independent of signal groups */ _MyElements.Add(new CCOLElement($"{_prmmwta}", c.OVData.MaxWachttijdAuto, CCOLElementTimeTypeEnum.TS_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmmwtfts}", c.OVData.MaxWachttijdFiets, CCOLElementTimeTypeEnum.TS_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmmwtvtg}", c.OVData.MaxWachttijdVoetganger, CCOLElementTimeTypeEnum.TS_type, CCOLElementTypeEnum.Parameter)); if (c.OVData.OVIngrepen.Count > 0 && c.OVData.OVIngrepen.Any(x => x.KAR) || c.OVData.HDIngrepen.Count > 0 && c.OVData.HDIngrepen.Any(x => x.KAR)) { _MyElements.Add(new CCOLElement($"{_uskarmelding}", CCOLElementTypeEnum.Uitgang)); _MyElements.Add(new CCOLElement($"{_uskarog}", CCOLElementTypeEnum.Uitgang)); _MyBitmapOutputs.Add(new CCOLIOElement(c.OVData.KARMeldingBitmapData, $"{_uspf}{_uskarmelding}")); _MyBitmapOutputs.Add(new CCOLIOElement(c.OVData.KAROnderGedragBitmapData, $"{_uspf}{_uskarog}")); _MyElements.Add(new CCOLElement($"{_tkarmelding}", 15, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_tkarog}", 1440, CCOLElementTimeTypeEnum.TM_type, CCOLElementTypeEnum.Timer)); } } if (c.OVData.OVIngrepen.Count > 0) { /* Variables independent of signal groups */ _MyElements.Add(new CCOLElement($"{_schcprio}", 0, CCOLElementTimeTypeEnum.SCH_type, CCOLElementTypeEnum.Schakelaar)); _MyElements.Add(new CCOLElement($"{_prmlaatcrit}", 0, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); if (c.OVData.OVIngrepen.Any(x => x.KAR)) { var prmtest1 = new CCOLElement($"{_prmtestkarvert}", 0, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter); var prmtest2 = new CCOLElement($"{_prmtestkarlyn}", 0, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter); prmtest1.Dummy = true; prmtest2.Dummy = true; _MyElements.Add(prmtest1); _MyElements.Add(prmtest2); } // TODO: This is not nice. Need to improve! should only be generated when needed //if (c.OVData.OVIngrepen.Where(x => x.Vecom).Any()) //{ _MyElements.Add(new CCOLElement($"{_schcheckopdsin}", c.OVData.CheckOpDSIN ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, CCOLElementTypeEnum.Schakelaar)); //} /* Variables for conflicting signal groups */ foreach (var ovfc in c.OVData.OVIngreepSignaalGroepParameters) { if (!CCOLCodeHelper.HasSignalGroupConflictWithPT(c, ovfc.FaseCyclus)) { continue; } var fct = c.Fasen.First(x => x.Naam == ovfc.FaseCyclus).Type; _MyElements.Add(new CCOLElement($"{_prmpmgt}{ovfc.FaseCyclus}", ovfc.PercMaxGroentijdVoorTerugkomen, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmognt}{ovfc.FaseCyclus}", ovfc.OndergrensNaTerugkomen, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); if (fct != FaseTypeEnum.Voetganger) { _MyElements.Add(new CCOLElement($"{_prmnofm}{ovfc.FaseCyclus}", ovfc.AantalKerenNietAfkappen, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmmgcov}{ovfc.FaseCyclus}", ovfc.MinimumGroentijdConflictOVRealisatie, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmpmgcov}{ovfc.FaseCyclus}", ovfc.PercMaxGroentijdConflictOVRealisatie, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmohpmg}{ovfc.FaseCyclus}", ovfc.OphoogpercentageNaAfkappen, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); } } } /* Variables for OV */ foreach (var ov in c.OVData.OVIngrepen) { _MyBitmapOutputs.Add(new CCOLIOElement(ov.OVInmeldingBitmapData, $"{_uspf}{_usovinm}{ov.FaseCyclus}")); _MyElements.Add(new CCOLElement($"{_usovinm}{ov.FaseCyclus}", CCOLElementTypeEnum.Uitgang)); _MyElements.Add(new CCOLElement($"{_hov}{ov.FaseCyclus}", CCOLElementTypeEnum.HulpElement)); _MyElements.Add(new CCOLElement($"{_hovin}{ov.FaseCyclus}", CCOLElementTypeEnum.HulpElement)); _MyElements.Add(new CCOLElement($"{_hovuit}{ov.FaseCyclus}", CCOLElementTypeEnum.HulpElement)); if (ov.KAR) { _MyElements.Add(new CCOLElement($"{_tdhkarin}{ov.FaseCyclus}", 15, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_tdhkaruit}{ov.FaseCyclus}", 15, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); } _MyElements.Add(new CCOLElement($"{_tbtovg}{ov.FaseCyclus}", 0, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_trt}{ov.FaseCyclus}", 0, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_cvc}{ov.FaseCyclus}", 999, CCOLElementTimeTypeEnum.CT_type, CCOLElementTypeEnum.Counter)); _MyElements.Add(new CCOLElement($"{_tgb}{ov.FaseCyclus}", ov.GroenBewaking, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_prmrto}{ov.FaseCyclus}", ov.RijTijdOngehinderd, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmrtbg}{ov.FaseCyclus}", ov.RijTijdBeperktgehinderd, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmrtg}{ov.FaseCyclus}", ov.RijTijdGehinderd, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmomx}{ov.FaseCyclus}", ov.OnderMaximum, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_tblk}{ov.FaseCyclus}", 0, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_schupinagb}{ov.FaseCyclus}", 0, CCOLElementTimeTypeEnum.SCH_type, CCOLElementTypeEnum.Schakelaar)); _MyElements.Add(new CCOLElement($"{_prmovstp}{ov.FaseCyclus}", 0, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); if (ov.VersneldeInmeldingKoplus == NooitAltijdAanUitEnum.SchAan || ov.VersneldeInmeldingKoplus == NooitAltijdAanUitEnum.SchUit) { _MyElements.Add(new CCOLElement($"{_schvi}{ov.FaseCyclus}", ov.VersneldeInmeldingKoplus == NooitAltijdAanUitEnum.SchAan ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, CCOLElementTypeEnum.Schakelaar)); } var opties = 0; if (ov.AfkappenConflicten || ov.AfkappenConflictenOV) { opties += 100; } if (ov.AfkappenConflictenOV) { opties += 300; } if (ov.TussendoorRealiseren) { opties += 30; } if (ov.VasthoudenGroen) { opties += 2; } _MyElements.Add(new CCOLElement($"{_prmprio}{ov.FaseCyclus}", opties, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); // Note!!! "allelijnen" must alway be DIRECTLY above the line prms, cause of the way these prms are used in code _MyElements.Add(new CCOLElement($"{_prmallelijnen}{ov.FaseCyclus}", ov.AlleLijnen == true ? 1 : 0, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); var n = 1; foreach (var l in ov.LijnNummers) { if (!int.TryParse(l.Nummer, out var num)) { continue; } _MyElements.Add( new CCOLElement($"{_prmlijn}{ov.FaseCyclus}_{n:00}", num, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); ++n; } if (ov.KAR) { _MyDetectors.Add(ov.DummyKARInmelding); _MyDetectors.Add(ov.DummyKARUitmelding); } if (ov.Vecom) { _MyDetectors.Add(ov.DummyVecomInmelding); _MyDetectors.Add(ov.DummyVecomUitmelding); } } /* Variables for HD */ foreach (var hd in c.OVData.HDIngrepen) { _MyBitmapOutputs.Add(new CCOLIOElement(hd.HDInmeldingBitmapData, $"{_uspf}{_ushdinm}{hd.FaseCyclus}")); _MyElements.Add(new CCOLElement($"{_ushdinm}{hd.FaseCyclus}", CCOLElementTypeEnum.Uitgang)); _MyElements.Add(new CCOLElement($"{_hhd}{hd.FaseCyclus}", CCOLElementTypeEnum.HulpElement)); _MyElements.Add(new CCOLElement($"{_hhdin}{hd.FaseCyclus}", CCOLElementTypeEnum.HulpElement)); _MyElements.Add(new CCOLElement($"{_hhduit}{hd.FaseCyclus}", CCOLElementTypeEnum.HulpElement)); _MyElements.Add(new CCOLElement($"{_tgbhd}{hd.FaseCyclus}", hd.GroenBewaking, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_trthd}{hd.FaseCyclus}", 0, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_cvchd}{hd.FaseCyclus}", 999, CCOLElementTimeTypeEnum.CT_type, CCOLElementTypeEnum.Counter)); _MyElements.Add(new CCOLElement($"{_prmpriohd}{hd.FaseCyclus}", 9005, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmrtohd}{hd.FaseCyclus}", hd.RijTijdOngehinderd, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmrtbghd}{hd.FaseCyclus}", hd.RijTijdBeperktgehinderd, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_prmrtghd}{hd.FaseCyclus}", hd.RijTijdGehinderd, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Parameter)); _MyElements.Add(new CCOLElement($"{_schupinagbhd}{hd.FaseCyclus}", 0, CCOLElementTimeTypeEnum.SCH_type, CCOLElementTypeEnum.Schakelaar)); // For signal groups that have HD but not OV if (c.OVData.OVIngrepen.All(x => x.FaseCyclus != hd.FaseCyclus)) { if (hd.KAR) { _MyElements.Add(new CCOLElement($"{_tdhkarin}{hd.FaseCyclus}", 15, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); _MyElements.Add(new CCOLElement($"{_tdhkaruit}{hd.FaseCyclus}", 15, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); } _MyElements.Add(new CCOLElement($"{_tbtovg}{hd.FaseCyclus}", 0, CCOLElementTimeTypeEnum.TE_type, CCOLElementTypeEnum.Timer)); } if (hd.KAR) { _MyDetectors.Add(hd.DummyKARInmelding); _MyDetectors.Add(hd.DummyKARUitmelding); } } }
#pragma warning restore 0649 #endregion #region CCOLCodePieceGeneratorBase Overrides public override void CollectCCOLElements(ControllerModel c) { _myElements = new List <CCOLElement>(); _myBitmapOutputs = new List <CCOLIOElement>(); if (c.PrioData.PrioIngrepen.Any(x => x.GeconditioneerdePrioriteit != NooitAltijdAanUitEnum.Nooit)) { _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_prmOVtstpgrensvroeg}", c.PrioData.GeconditioneerdePrioGrensTeVroeg, CCOLElementTimeTypeEnum.TS_type, _prmOVtstpgrensvroeg)); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_prmOVtstpgrenslaat}", c.PrioData.GeconditioneerdePrioGrensTeLaat, CCOLElementTimeTypeEnum.TS_type, _prmOVtstpgrenslaat)); } foreach (var ov in c.PrioData.PrioIngrepen.Where(x => x.GeconditioneerdePrioriteit != NooitAltijdAanUitEnum.Nooit)) { if (ov.GeconditioneerdePrioriteit != NooitAltijdAanUitEnum.Altijd) { _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_schovstipt}{CCOLCodeHelper.GetPriorityName(ov)}", ov.GeconditioneerdePrioriteit == NooitAltijdAanUitEnum.SchAan ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, _schovstipt, ov.FaseCyclus, ov.Type.GetDescription())); } _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_mstp}{CCOLCodeHelper.GetPriorityName(ov)}", _mstp, ov.FaseCyclus, ov.Type.GetDescription())); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_hstp}{CCOLCodeHelper.GetPriorityName(ov)}", _hstp, ov.FaseCyclus, ov.Type.GetDescription())); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_prmovstipttevroeg}{CCOLCodeHelper.GetPriorityName(ov)}", ov.GeconditioneerdePrioTeVroeg, CCOLElementTimeTypeEnum.None, _prmovstipttevroeg, ov.FaseCyclus, ov.Type.GetDescription())); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_prmovstiptoptijd}{CCOLCodeHelper.GetPriorityName(ov)}", ov.GeconditioneerdePrioOpTijd, CCOLElementTimeTypeEnum.None, _prmovstiptoptijd, ov.FaseCyclus, ov.Type.GetDescription())); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_prmovstipttelaat}{CCOLCodeHelper.GetPriorityName(ov)}", ov.GeconditioneerdePrioTeLaat, CCOLElementTimeTypeEnum.None, _prmovstipttelaat, ov.FaseCyclus, ov.Type.GetDescription())); if (!c.PrioData.PrioUitgangPerFase) { _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_usovtevroeg}{CCOLCodeHelper.GetPriorityName(ov)}", _usovtevroeg, ov.FaseCyclus, ov.Type.GetDescription())); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_usovoptijd}{CCOLCodeHelper.GetPriorityName(ov)}", _usovoptijd, ov.FaseCyclus, ov.Type.GetDescription())); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_usovtelaat}{CCOLCodeHelper.GetPriorityName(ov)}", _usovtelaat, ov.FaseCyclus, ov.Type.GetDescription())); _myBitmapOutputs.Add(new CCOLIOElement(ov.GeconditioneerdePrioTeVroegBitmapData, $"{_uspf}{_usovtevroeg}{CCOLCodeHelper.GetPriorityName(ov)}")); _myBitmapOutputs.Add(new CCOLIOElement(ov.GeconditioneerdePrioOpTijdBitmapData, $"{_uspf}{_usovoptijd}{CCOLCodeHelper.GetPriorityName(ov)}")); _myBitmapOutputs.Add(new CCOLIOElement(ov.GeconditioneerdePrioTeLaatBitmapData, $"{_uspf}{_usovtelaat}{CCOLCodeHelper.GetPriorityName(ov)}")); } } if (c.PrioData.PrioUitgangPerFase) { foreach (var sg in c.Fasen.Where(x => c.PrioData.PrioIngrepen.Any(x2 => x2.FaseCyclus == x.Naam && x2.GeconditioneerdePrioriteit != NooitAltijdAanUitEnum.Nooit))) { _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_usovtevroeg}{sg.Naam}", _usovtevroeg, sg.Naam, "")); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_usovoptijd}{sg.Naam}", _usovoptijd, sg.Naam, "")); _myElements.Add(CCOLGeneratorSettingsProvider.Default.CreateElement($"{_usovtelaat}{sg.Naam}", _usovtelaat, sg.Naam, "")); _myBitmapOutputs.Add(new CCOLIOElement(sg.GeconditioneerdePrioTeVroegBitmapData, $"{_uspf}{_usovtevroeg}{sg.Naam}")); _myBitmapOutputs.Add(new CCOLIOElement(sg.GeconditioneerdePrioOpTijdBitmapData, $"{_uspf}{_usovoptijd}{sg.Naam}")); _myBitmapOutputs.Add(new CCOLIOElement(sg.GeconditioneerdePrioTeLaatBitmapData, $"{_uspf}{_usovtelaat}{sg.Naam}")); } } }
public override void CollectCCOLElements(ControllerModel c) { _myElements = new List <CCOLElement>(); var dets = c.Fasen.SelectMany(x => x.Detectoren).ToList(); // Detectie aanvraag functie foreach (var dm in dets) { if (dm.Aanvraag == DetectorAanvraagTypeEnum.Geen) { continue; } if (!dm.AanvraagHardOpStraat) { var set = CCOLCodeHelper.GetAanvraagSetting(dm); _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmda}{dm.Naam}", set, CCOLElementTimeTypeEnum.None, _prmda, dm.Naam)); } if (dm.ResetAanvraag) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_tav}{dm.Naam}", dm.ResetAanvraagTijdsduur, CCOLElementTimeTypeEnum.TE_type, _tav, dm.Naam)); } } // Detectie verlengkriterium foreach (var fc in c.Fasen) { foreach (var dm in fc.Detectoren) { if (dm.Verlengen == DetectorVerlengenTypeEnum.Geen) { continue; } if (!dm.VerlengenHardOpStraat) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmmk}{dm.Naam}", GetVerlengenSetting(fc, dm), CCOLElementTimeTypeEnum.TE_type, _prmmk, dm.Naam)); } } } // Collect Kopmax foreach (var fcm in c.Fasen.Where(x => x.Detectoren.Any(x2 => x2.Verlengen != DetectorVerlengenTypeEnum.Geen))) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_tkm}{fcm.Naam}", fcm.Kopmax, CCOLElementTimeTypeEnum.TE_type, _tkm, fcm.Naam)); } // Memory elems for meetkriterium2 foreach (var fcm in c.Fasen.Where(x => x.ToepassenMK2)) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_mmk}{fcm.Naam}", _mmk, fcm.Naam)); } }
public override string GetCode(ControllerModel c, CCOLCodeTypeEnum type, string ts) { var sb = new StringBuilder(); switch (type) { case CCOLCodeTypeEnum.RegCRealisatieAfhandelingModules: sb.AppendLine($"{ts}/* versnelde primaire realisaties */"); sb.AppendLine($"{ts}/* ------------------------------ */"); sb.AppendLine($"{ts}/* periode versnelde primaire realisatie - aantal modulen vooruit */"); sb.AppendLine($"{ts}/* -------------------------------------------------------------- */"); foreach (var fc in c.ModuleMolen.FasenModuleData) { sb.AppendLine($" PFPR[{_fcpf}{fc.FaseCyclus}] = ml_fpr({_fcpf}{fc.FaseCyclus}, PRM[{_prmpf}{_prmmlfpr}{fc.FaseCyclus}], PRML, ML, MLMAX);"); } sb.AppendLine(""); sb.AppendLine($"{ts}VersneldPrimair_Add();"); if (c.HalfstarData.IsHalfstar) { sb.AppendLine($"{ts}VersneldPrimair_halfstar();"); } sb.AppendLine(""); sb.AppendLine($"{ts}for (fc = 0; fc < FCMAX; ++fc)"); sb.AppendLine($"{ts}{ts}set_FPRML(fc, PRML, ML, MLMAX, (bool)PFPR[fc]);"); sb.AppendLine(); if (c.ModuleMolen.LangstWachtendeAlternatief) { sb.AppendLine($"{ts}/* langstwachtende alternatieve realisatie */"); sb.AppendLine($"{ts}/* --------------------------------------- */"); sb.AppendLine(""); sb.AppendLine($"{ts}afsluiten_aanvraaggebied_pr(PRML, ML);"); sb.AppendLine(""); sb.AppendLine($"{ts}for (fc=0; fc<FCMAX; fc++)"); sb.AppendLine($"{ts}" + "{"); sb.AppendLine($"{ts}{ts}RR[fc] &= ~BIT5;"); sb.AppendLine($"{ts}{ts}FM[fc] &= ~BIT5;"); sb.AppendLine($"{ts}" + "}"); sb.AppendLine(); sb.AppendLine($"{ts}/* zet richtingen die alternatief gaan realiseren */"); sb.AppendLine($"{ts}/* terug naar RV als er geen alternatieve ruimte meer is. */"); foreach (var fc in c.ModuleMolen.FasenModuleData) { sb.AppendLine( $"{ts}RR[{_fcpf}{fc.FaseCyclus}] |= R[{_fcpf}{fc.FaseCyclus}] && AR[{_fcpf}{fc.FaseCyclus}] && (!PAR[{_fcpf}{fc.FaseCyclus}] || ERA[{_fcpf}{fc.FaseCyclus}]) ? BIT5 : 0;"); } sb.AppendLine(); var gelijkstarttuples = CCOLCodeHelper.GetFasenWithGelijkStarts(c); var yes = false; foreach (var gs in gelijkstarttuples) { if (gs.Item2.Count > 1) { yes = true; sb.Append($"{ts}RR[{_fcpf}{gs.Item1}] |= R[{_fcpf}{gs.Item1}] && "); if (gs.Item2.Count > 1) { sb.Append("("); } var i = 0; foreach (var ofc in gs.Item2) { if (ofc == gs.Item1) { continue; } if (i > 0) { sb.Append(" || "); } sb.Append($"(RR[{_fcpf}{ofc}] & BIT5)"); ++i; } if (gs.Item2.Count > 1) { sb.Append(")"); } sb.AppendLine(" ? BIT5 : 0;"); } } if (yes) { sb.AppendLine(); } foreach (var fc in c.ModuleMolen.FasenModuleData) { sb.AppendLine( $"{ts}FM[{_fcpf}{fc.FaseCyclus}] |= (fm_ar_kpr({_fcpf}{fc.FaseCyclus}, PRM[{_prmpf}{_prmaltg}{fc.FaseCyclus}])) ? BIT5 : 0;"); } sb.AppendLine(); foreach (var fc in c.ModuleMolen.FasenModuleData) { Tuple <string, List <string> > hasgs = null; foreach (var gs in gelijkstarttuples) { if (gs.Item1 == fc.FaseCyclus && gs.Item2.Count > 1) { hasgs = gs; break; } } if (hasgs != null) { sb.Append( $"{ts}PAR[{_fcpf}{fc.FaseCyclus}] = (max_tar_to({_fcpf}{fc.FaseCyclus}) >= PRM[{_prmpf}{_prmaltp}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.Append($"]) && SCH[{_schpf}{_schaltg}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.AppendLine("];"); } else { sb.AppendLine( $"{ts}PAR[{_fcpf}{fc.FaseCyclus}] = (max_tar_to({_fcpf}{fc.FaseCyclus}) >= PRM[{_prmpf}{_prmaltp}{fc.FaseCyclus}]) && SCH[{_schpf}{_schaltg}{fc.FaseCyclus}];"); } } sb.AppendLine(); if (c.InterSignaalGroep.Nalopen.Count > 0) { foreach (var nl in c.InterSignaalGroep.Nalopen) { #warning Is this correct and desired? Need to look (also?) at other timers? #warning This would be better moved to the naloop generator; for that though, we need to be able to specify order in generated code elems. TODO! var tnl = ""; if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.VastGroenDetectie)) { tnl = _tnlfgd; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.StartGroenDetectie)) { tnl = _tnlsgd; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.EindeGroenDetectie)) { tnl = _tnlegd; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.EindeVerlengGroenDetectie)) { tnl = _tnlcvd; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.VastGroen)) { tnl = _tnlfg; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.StartGroen)) { tnl = _tnlsg; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.EindeGroen)) { tnl = _tnleg; } else if (nl.Tijden.Any(x => x.Type == NaloopTijdTypeEnum.EindeVerlengGroen)) { tnl = _tnlcv; } sb.AppendLine( $"{ts}PAR[{_fcpf}{nl.FaseVan}] = PAR[{_fcpf}{nl.FaseVan}] && ((max_tar_to({_fcpf}{nl.FaseNaar}) >= T_max[{_tpf}{tnl}{nl.FaseVan}{nl.FaseNaar}]) || G[{_fcpf}{nl.FaseVan}] || !A[{_fcpf}{nl.FaseNaar}]);"); } sb.AppendLine(); } yes = false; foreach (var gs in gelijkstarttuples) { if (gs.Item2.Count > 1) { yes = true; sb.Append($"{ts}PAR[{_fcpf}{gs.Item1}] = PAR[{_fcpf}{gs.Item1}]"); foreach (var ofc in gs.Item2) { if (ofc == gs.Item1) { continue; } sb.Append($" && (PAR[{_fcpf}{ofc}] || !A[{_fcpf}{ofc}])"); } sb.AppendLine(";"); } } if (yes) { sb.AppendLine(); } yes = false; foreach (var fcm in c.Fasen) { if (fcm.Meeverlengen != NooitAltijdAanUitEnum.Nooit) { { var fm = c.FileIngrepen.FirstOrDefault( x => x.TeDoserenSignaalGroepen.Any(x2 => x2.FaseCyclus == fcm.Naam)); if (fm != null) { if (!yes) { yes = true; sb.AppendLine(); sb.AppendLine($"{ts}/* Niet alternatief komen tijdens file */"); } sb.AppendLine( $"{ts}if (IH[{_hpf}{_hfile}{fm.Naam}]) PAR[{_fcpf}{fcm.Naam}] = FALSE;"); } } } } if (yes) { sb.AppendLine(); } foreach (var gen in CCOLGenerator.OrderedPieceGenerators[CCOLCodeTypeEnum.RegCAlternatieven]) { sb.Append(gen.Value.GetCode(c, CCOLCodeTypeEnum.RegCAlternatieven, ts)); sb.AppendLine(); } sb.AppendLine($"{ts}Alternatief_Add();"); if (c.HalfstarData.IsHalfstar) { sb.AppendLine($"{ts}Alternatief_halfstar();"); } sb.AppendLine(); sb.AppendLine($"{ts}langstwachtende_alternatief_modulen(PRML, ML, ML_MAX);"); } else { if (c.ModuleMolen.Modules.SelectMany(x => x.Fasen).Any(x => x.Alternatieven.Any())) { sb.AppendLine($"{ts}/* alternatieve realisaties */"); sb.AppendLine($"{ts}/* ------------------------ */"); // Build a list of dictionaries for signalgroups that may realize alternatively; // each dictionary contains alternative signalgroups as keys, and a list of primary // signalgroups under whose CV the alternative may realise var modulesWithAlternatives = new List <Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > > >(); foreach (var ml in c.ModuleMolen.Modules) { var altdict = new Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > >(); foreach (var mlfc in ml.Fasen) { foreach (var amlfc in mlfc.Alternatieven) { if (!altdict.ContainsKey(amlfc.FaseCyclus)) { altdict.Add( amlfc.FaseCyclus, new List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > { new Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc) }); } else { altdict[amlfc.FaseCyclus].Add(new Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc)); } } } modulesWithAlternatives.Add(altdict); } var mlidx = 1; foreach (var moduleWithAlternatives in modulesWithAlternatives) { foreach (var alternativeSignalGroup in moduleWithAlternatives) { var pre = $"{ts}set_FARML({_fcpf}{alternativeSignalGroup.Key}, PRML, ML, ML_MAX, ML{mlidx}, " .Length; sb.Append( $"{ts}set_FARML({_fcpf}{alternativeSignalGroup.Key}, PRML, ML, ML_MAX, ML{mlidx}, "); var i = 0; foreach (var primarySignalGroup in alternativeSignalGroup.Value) { if (i > 0) { sb.AppendLine(" || "); sb.Append("".PadLeft(pre)); } ++i; sb.Append($"(bool) (CV[{_fcpf}{primarySignalGroup.Item2.FaseCyclus}] && AlternatieveRuimte({_fcpf}{alternativeSignalGroup.Key}, {_fcpf}{primarySignalGroup.Item2.FaseCyclus}, {_prmpf}{_prmaltg}{mlidx}{alternativeSignalGroup.Key}))"); } sb.AppendLine(");"); } ++mlidx; } sb.AppendLine(); sb.AppendLine($"{ts}for (fc = 0; fc < FCMAX; ++fc)"); sb.AppendLine($"{ts}{{"); sb.AppendLine($"{ts}{ts}RR[fc] &= ~BIT5;"); sb.AppendLine($"{ts}{ts}FM[fc] &= ~BIT5;"); sb.AppendLine($"{ts}}}"); sb.AppendLine(); mlidx = 1; foreach (var moduleWithAlternatives in modulesWithAlternatives) { foreach (var alternativeSignalGroup in moduleWithAlternatives) { var pre = $"{ts}RR[{_fcpf}{alternativeSignalGroup.Key}] |= (AR[{_fcpf}{alternativeSignalGroup.Key}] && RA[{_fcpf}{alternativeSignalGroup.Key}] && " .Length; sb.Append( $"{ts}RR[{_fcpf}{alternativeSignalGroup.Key}] |= (AR[{_fcpf}{alternativeSignalGroup.Key}] && RA[{_fcpf}{alternativeSignalGroup.Key}] && "); var i = 0; foreach (var primarySignalGroup in alternativeSignalGroup.Value) { if (i > 0) { sb.AppendLine(" && "); sb.Append("".PadLeft(pre)); } ++i; sb.Append($"!(CV[{_fcpf}{primarySignalGroup.Item2.FaseCyclus}] && AlternatieveRuimte({_fcpf}{alternativeSignalGroup.Key}, " + $"{_fcpf}{primarySignalGroup.Item2.FaseCyclus}, {_prmpf}{_prmaltg}{mlidx}{alternativeSignalGroup.Key}))"); } sb.AppendLine(") ? BIT5 : 0;"); } ++mlidx; } sb.AppendLine(); mlidx = 1; foreach (var moduleWithAlternatives in modulesWithAlternatives) { foreach (var alternativeSignalGroup in moduleWithAlternatives) { sb.AppendLine( $"{ts}FM[{_fcpf}{alternativeSignalGroup.Key}] |= (AR[{_fcpf}{alternativeSignalGroup.Key}] && " + $"G[{_fcpf}{alternativeSignalGroup.Key}] && fm_ar_kpr({_fcpf}{alternativeSignalGroup.Key}, PRM[{_prmpf}{_prmaltg}{mlidx}{alternativeSignalGroup.Key}])) ? BIT5 : 0;"); } ++mlidx; } } sb.AppendLine(); sb.AppendLine($"{ts}for (fc = 0; fc < FCMAX; ++fc) if (SR[fc] && AG[fc])"); sb.AppendLine($"{ts}{ts}if (SR[fc] && AG[fc])"); sb.AppendLine($"{ts}{ts}{ts}reset_FARML(fc, PRML, ML, ML_MAX);"); sb.AppendLine(); sb.AppendLine($"{ts}Alternatief_Add();"); if (c.HalfstarData.IsHalfstar) { sb.AppendLine($"{ts}Alternatief_halfstar();"); } } sb.AppendLine(); return(sb.ToString()); case CCOLCodeTypeEnum.HstCAlternatief: var gelijkstarttuples2 = CCOLCodeHelper.GetFasenWithGelijkStarts(c); foreach (var fc in c.ModuleMolen.FasenModuleData) { Tuple <string, List <string> > hasgs = null; foreach (var gs in gelijkstarttuples2) { if (gs.Item1 == fc.FaseCyclus && gs.Item2.Count > 1) { hasgs = gs; break; } } if (hasgs != null) { sb.Append( $"{ts}alternatief_halfstar({_fcpf}{fc.FaseCyclus}, PRM[{_prmpf}{_prmaltp}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.Append($"], SCH[{_schpf}{_schaltg}"); foreach (var ofc in hasgs.Item2) { sb.Append(ofc); } sb.AppendLine("]);"); } else { sb.AppendLine( $"{ts}alternatief_halfstar({_fcpf}{fc.FaseCyclus}, PRM[{_prmpf}{_prmaltp}{fc.FaseCyclus}], SCH[{_schpf}{_schaltg}{fc.FaseCyclus}]);"); } } foreach (var nl in c.InterSignaalGroep.Nalopen) { if (nl.Type == NaloopTypeEnum.EindeGroen || nl.Type == NaloopTypeEnum.CyclischVerlengGroen) { var t = nl.Type == NaloopTypeEnum.EindeGroen ? $"{_tpf}{_tnleg}{nl.FaseVan}{nl.FaseNaar}" : $"{_tpf}{_tnlcv}{nl.FaseVan}{nl.FaseNaar}"; if (nl.DetectieAfhankelijk) { t = nl.Type == NaloopTypeEnum.EindeGroen ? $"{_tpf}{_tnlegd}{nl.FaseVan}{nl.FaseNaar}" : $"{_tpf}{_tnlcvd}{nl.FaseVan}{nl.FaseNaar}"; } sb.AppendLine($"{ts}altcor_kop_halfstar({_fcpf}{nl.FaseVan}, {_fcpf}{nl.FaseNaar}, {t});"); } if (nl.Type == NaloopTypeEnum.StartGroen) { if (nl.DetectieAfhankelijk && nl.Detectoren.Any()) { sb.AppendLine($"{ts}altcor_naloopSG_halfstar({_fcpf}{nl.FaseVan}, {_fcpf}{nl.FaseNaar}, IH[{_hpf}{_hnla}{nl.Detectoren[0].Detector}], {_tpf}{_tnlsgd}{nl.FaseVan}{nl.FaseNaar}, TRUE);"); } else { sb.AppendLine($"{ts}altcor_naloopSG_halfstar({_fcpf}{nl.FaseVan}, {_fcpf}{nl.FaseNaar}, TRUE, {_tpf}{_tnlsg}{nl.FaseVan}{nl.FaseNaar}, TRUE);"); } } } return(sb.ToString()); default: return(null); } }
public override void CollectCCOLElements(ControllerModel c) { _myElements = new List <CCOLElement>(); var gelijkstarttuples = CCOLCodeHelper.GetFasenWithGelijkStarts(c); foreach (var fc in c.ModuleMolen.FasenModuleData) { // Vooruit realisaties _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmmlfpr}{fc.FaseCyclus}", fc.ModulenVooruit, CCOLElementTimeTypeEnum.None, _prmmlfpr, fc.FaseCyclus)); } if (c.Data.SynchronisatiesType == SynchronisatiesTypeEnum.RealFunc) { var groenSyncData = GroenSyncDataModel.ConvertSyncFuncToRealFunc(c); var sortedSyncs = GroenSyncDataModel.OrderSyncs(c, groenSyncData); foreach (var nl in c.InterSignaalGroep.Nalopen) { // Only do this for pedestrians with sync var sync = sortedSyncs.twoWayPedestrians?.FirstOrDefault(x => x.m1.FaseVan == nl.FaseVan && x.m1.FaseNaar == nl.FaseNaar || x.m1.FaseVan == nl.FaseNaar && x.m1.FaseNaar == nl.FaseVan); if (sync == null) { continue; } var hnl = nl.Type switch { NaloopTypeEnum.StartGroen => _tnlsg, NaloopTypeEnum.EindeGroen => _tnleg, NaloopTypeEnum.CyclischVerlengGroen => _tnlcv, _ => throw new ArgumentOutOfRangeException() }; _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{hnl}{nl.FaseVan}{nl.FaseNaar}", 0, CCOLElementTimeTypeEnum.None, CCOLElementTypeEnum.HulpElement, "")); } } // Alternatieven if (c.ModuleMolen.LangstWachtendeAlternatief) { foreach (var fc in c.ModuleMolen.FasenModuleData) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmaltg}{fc.FaseCyclus}", fc.AlternatieveGroenTijd, CCOLElementTimeTypeEnum.TE_type, _prmaltg, fc.FaseCyclus)); // For prmaltp and schaltg: combine if the signal group is part of a simultaneous synchronisation var gs = gelijkstarttuples.FirstOrDefault(x => x.Item1 == fc.FaseCyclus); if (gs != null) { var namealtp = _prmaltp + string.Join(string.Empty, gs.Item2); var namealtg = _schaltg + string.Join(string.Empty, gs.Item2); var containsaltp = _myElements.Any(i => i.Naam == namealtp); var containsaltg = _myElements.Any(i => i.Naam == namealtg); if (!containsaltp) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( namealtp, fc.AlternatieveRuimte, CCOLElementTimeTypeEnum.TE_type, _prmaltp, "fasen", string.Join(", ", gs.Item2))); } if (!containsaltg) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( namealtg, fc.AlternatiefToestaan ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, _schaltg, "fasen", string.Join(", ", gs.Item2))); } } else { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmaltp}{fc.FaseCyclus}", fc.AlternatieveRuimte, CCOLElementTimeTypeEnum.TE_type, _prmaltp, "fase", fc.FaseCyclus)); _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_schaltg}{fc.FaseCyclus}", fc.AlternatiefToestaan ? 1 : 0, CCOLElementTimeTypeEnum.SCH_type, _schaltg, "fase", fc.FaseCyclus)); } } } else { // Build a list of dictionaries for signalgroups that may realize alternatively; // each dictionary contains alternative signalgroups as keys, and a list of primary // signalgroups under whose CV the alternative may realise var altsdict = new List <Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > > >(); foreach (var ml in c.ModuleMolen.Modules) { var altdict = new Dictionary <string, List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > >(); foreach (var mlfc in ml.Fasen) { foreach (var amlfc in mlfc.Alternatieven) { if (!altdict.ContainsKey(amlfc.FaseCyclus)) { altdict.Add( amlfc.FaseCyclus, new List <Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel> > { new Tuple <ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc) }); } } } altsdict.Add(altdict); } var mlidx = 1; foreach (var alts in altsdict) { foreach (var altg in alts) { _myElements.Add( CCOLGeneratorSettingsProvider.Default.CreateElement( $"{_prmaltg}{mlidx}{altg.Key}", altg.Value.First().Item1.AlternatieveGroenTijd, CCOLElementTimeTypeEnum.TE_type, _prmaltg, altg.Key, "ML" + mlidx)); } ++mlidx; } /* not supported yet * foreach (var r in c.MultiModuleMolens) * { * foreach (var ml in r.Modules) * { * var altdict = * new Dictionary<string, List<Tuple<ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>>>(); * foreach (var mlfc in ml.Fasen) * { * foreach (var amlfc in mlfc.Alternatieven) * { * if (!altdict.ContainsKey(amlfc.FaseCyclus)) * { * altdict.Add( * amlfc.FaseCyclus, * new List<Tuple<ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>> * { * new Tuple<ModuleFaseCyclusAlternatiefModel, ModuleFaseCyclusModel>(amlfc, mlfc) * }); * } * } * } * altsdict.Add(altdict); * } * var mlidx2 = 1; * foreach (var alts in altsdict) * { * foreach (var altg in alts) * { * _myElements.Add( * CCOLGeneratorSettingsProvider.Default.CreateElement( * $"{_prmaltg}{mlidx}{altg.Key}", * altg.Value.First().Item1.AlternatieveGroenTijd, * CCOLElementTimeTypeEnum.TE_type, * _prmaltg, altg.Key, r.Reeks + mlidx)); * } ++mlidx2; * } * } */ } }