public bool MiscEqual(AdditiveLogicChain chain) { if (chain.GetHashCode() == GetHashCode()) { return(misc.Intersect(chain.misc).Count() == misc.Length); } return(false); }
public static AdditiveLogicChain Plus(AdditiveLogicChain chain1, AdditiveLogicChain chain2) { return(new AdditiveLogicChain { target = chain1.target, waypoints = chain1.waypoints.Union(chain2.waypoints).ToArray(), misc = chain1.misc.Union(chain2.misc).ToArray() }); }
public AdditiveLogicChain Literalize(AdditiveLogicChain chain) { string[] reducedWaypoints = waypoints.Except(new string[] { chain.target }).Union(chain.waypoints).ToArray(); string[] oldMisc = misc; string _target = target; return(new AdditiveLogicChain { target = _target, waypoints = reducedWaypoints, misc = oldMisc.Union(chain.misc).ToArray() }); }
public AdditiveLogicChain[] SubstituteWaypoints(AdditiveLogicChain chain) { IEnumerable <IEnumerable <string> > miscReqs = new string[][] { chain.misc }; foreach (string waypoint in chain.waypoints) { miscReqs = miscReqs.NondeterministicUnion(newWaypointLogic[waypoint].Select(c => (IEnumerable <string>)c.misc)); } return(miscReqs.Select(m => new AdditiveLogicChain { target = chain.target, waypoints = new string[0], misc = m.ToArray() }).ToArray()); }
// ignores target public bool IsContainedIn(AdditiveLogicChain chain) { return(misc.All(s => chain.misc.Contains(s)) && waypoints.All(w => chain.waypoints.Contains(w))); }
public SimpleLogicChain(AdditiveLogicChain chain) { reqs = new HashSet <string>(chain.misc); }
public void SimplifyWaypoints(string startPoint) { Dictionary <string, List <AdditiveLogicChain> > relLogic = origWaypointLogic.ToDictionary(c => c.Key, c => c.Value.ToList()); Dictionary <string, List <AdditiveLogicChain> > absLogic = WData.WaypointNames.ToDictionary(c => c, c => new List <AdditiveLogicChain>()); int counter = 0; Stack <AdditiveLogicChain> updates = new Stack <AdditiveLogicChain>(); AdditiveLogicChain startChain = new AdditiveLogicChain { target = startPoint, misc = new string[0], waypoints = new string[0] }; updates.Push(startChain); absLogic[startPoint].Add(startChain); while (updates.Any()) { counter++; var upChain = updates.Pop(); SolveWaypointsHook.Invoke(upChain, counter, updates, relLogic, absLogic); IEnumerable <AdditiveLogicChain> updatedLogic = relLogic.Values.SelectMany(l => l).Where(l => l.DependsOn(upChain.target)) .Select(l => l.Literalize(upChain)); List <AdditiveLogicChain> newRelLogic = updatedLogic.Where(l => !l.literal).ToList(); List <AdditiveLogicChain> newAbsLogic = updatedLogic.Where(l => l.literal).ToList(); // monotonicity check -- no new absolute logic statement should be a superset of another new statement newAbsLogic = RemoveSupersets(newAbsLogic); // monotonicity check -- no new relative logic statement should be a superset of another new statement newRelLogic = RemoveSupersets(newRelLogic); // monotonicity check -- new absolute logic should not be a superset of any existing statements newAbsLogic = newAbsLogic.Where(l => absLogic[l.target].All(r => !r.IsContainedInT(l))).ToList(); // monotonicity check -- new relative logic should not be a superset of any existing statements newRelLogic = newRelLogic.Where(l => relLogic[l.target].All(r => !r.IsContainedInT(l))).ToList(); // monotonicity check -- remove any old absolute logic statements that are supersets of new statements, and add new statements foreach (var absChain in newAbsLogic) { List <AdditiveLogicChain> temp = absLogic[absChain.target].Where(r => !absChain.IsContainedInT(r)).ToList(); temp.Add(absChain); absLogic[absChain.target] = temp; updates.Push(absChain); } // monotonicity check -- remove any old relative logic statements that are supersets of new statements, and add new statements foreach (var relChain in newRelLogic) { List <AdditiveLogicChain> temp = relLogic[relChain.target].Where(r => !relChain.IsContainedInT(r)).ToList(); temp.Add(relChain); relLogic[relChain.target] = temp; //updates.Push(relChain); } } newWaypointLogic = absLogic.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToArray()); }