コード例 #1
0
        public Value GetValueAt(ILayoutAccess layout, ISimulationAccess sim, Location loc)
        {
            layout.CheckReadAccess();
            sim.CheckReadAccess();
            LayoutNode sup = layout.FindNode(loc);

            if (nodeMap.ContainsKey(sup))
            {
                return(sim.Get(nodeMap[sup]));
            }
            else
            {
                return(Value.X);
            }
        }
コード例 #2
0
ファイル: LayoutNode.cs プロジェクト: SirHall/toves-simulator
            private List <LayoutNode> determineNodes(IEnumerable <LocationSet> newSets, List <LayoutNode> newNodes)
            {
                Dictionary <LocationSet, LayoutNode> oldSets = new Dictionary <LocationSet, LayoutNode>();

                foreach (LayoutNode n in this.curNodes)
                {
                    oldSets[n.locs] = n;
                }
                HashSet <LocationSet> unmatched = new HashSet <LocationSet>();

                foreach (LocationSet newSet in newSets)
                {
                    if (oldSets.ContainsKey(newSet))
                    {
                        newNodes.Add(oldSets[newSet]);
                        oldSets.Remove(newSet);
                    }
                    else
                    {
                        unmatched.Add(newSet);
                    }
                }

                if (oldSets.Count == 0 && unmatched.Count == 0)
                {
                    return(new List <LayoutNode>(0));
                }

                List <LayoutNode>  changedNodes = new List <LayoutNode>(oldSets.Values);
                List <LocationSet> toReplace    = new List <LocationSet>(oldSets.Keys);

                toReplace.Sort((a, b) => b.Count - a.Count);
                foreach (LocationSet replSrc in toReplace)
                {
                    LayoutNode         replNode = oldSets[replSrc];
                    HashSet <Location> replLocs = new HashSet <Location>(replSrc);
                    int         maxCount        = 0;
                    LocationSet maxSet          = null;
                    foreach (LocationSet candidate in unmatched)
                    {
                        int count = 0;
                        foreach (Location loc in candidate)
                        {
                            if (replLocs.Contains(loc))
                            {
                                ++count;
                            }
                        }
                        if (count > maxCount)
                        {
                            maxCount = count;
                            maxSet   = candidate;
                        }
                    }
                    replNode.prev = replNode.locs;
                    replNode.locs = maxSet;
                    if (maxSet != null)
                    {
                        newNodes.Add(replNode);
                        unmatched.Remove(maxSet);
                    }
                }

                foreach (LocationSet newSet in unmatched)
                {
                    this.nodeId++;
                    LayoutNode n = new LayoutNode(this.nodeId, newSet);
                    changedNodes.Add(n);
                    newNodes.Add(n);
                }
                return(changedNodes);
            }