/// <summary> /// Constructor with parameters /// </summary> /// <param name="nodeIndices">Nodes present in this instance</param> /// <param name="activeComponentsIndices">Active components indices present in this instance</param> /// <param name="defaultValueFactory">Func used for generating initial values in <see cref="Potentials"/> and <see cref="Currents"/>, /// if null (which is the default value) <see cref="default(T)"/> will be used</param> /// <param name="sourceDescription">Description of source that produced this state. Can be null - it means that it's indetermined or /// many sources produced this state</param> public GenericState(IEnumerable <int> nodeIndices, IEnumerable <int> activeComponentsIndices, ISourceDescription sourceDescription, Func <T> defaultValueFactory = null) { // Null checks if (nodeIndices == null) { throw new ArgumentNullException(nameof(nodeIndices)); } if (activeComponentsIndices == null) { throw new ArgumentNullException(nameof(activeComponentsIndices)); } // Make an entry for each node foreach (var node in nodeIndices) { Potentials.Add(node, defaultValueFactory == null ? default(T) : defaultValueFactory()); } // Make an entry for each index foreach (var index in activeComponentsIndices) { Currents.Add(index, defaultValueFactory == null ? default(T) : defaultValueFactory()); } // Assign source description SourceDescription = sourceDescription; }
public string GetPotentialString(Potentials potential) { switch (potential) { case (Potentials.vhigh): return(potentialStrings[0]); case (Potentials.high): return(potentialStrings[1]); case (Potentials.normal): return(potentialStrings[2]); case (Potentials.low): return(potentialStrings[3]); case (Potentials.vlow): return(potentialStrings[4]); } return("Potential string unresolved"); }
protected override void ExecuteDay(byte[] input) { var weights = input.GetLines() .Select(i => Convert.ToInt32(i)) .OrderByDescending(i => i) .ToList(); totalWeight = weights.Sum(); groupWeight = totalWeight / 3; GetSubsets(weights); Dump('A', Potentials .Select(l => new { List = l, QE = l.Aggregate(1ul, (p, w) => p * (ulong)w), }) .OrderBy(l => l.QE) .First() .QE); groupWeight = totalWeight / 4; Potentials = new List <IList <int> >(); GetSubsets(weights); Dump('B', Potentials .Select(l => new { List = l, QE = l.Aggregate(1ul, (p, w) => p * (ulong)w), }) .OrderBy(l => l.QE) .First() .QE); }