Esempio n. 1
0
        public TreeSet AddRiver(River river)
        {
            var ans = new TreeSet(this);

            ans.AddRiverImpl(river.source, river.target);
            return(ans);
        }
Esempio n. 2
0
        static Tuple <River, double> FindBestChoke(
            IEnumerable <River> allRivers,
            AdjacencyMap allRiversAdjacencyMap,
            List <River> availableRivers,
            HashSet <int> sourceMine,
            HashSet <int> targetMine,
            List <int> shortestPath)
        {
            Func <List <int>, int> lengthOrDefault = (list) => list == null ? 10000 : list.Count;

            var rivers = shortestPath.Zip(
                shortestPath.Skip(1),
                (source, target) =>
            {
                var river = new River()
                {
                    source = source, target = target
                };
                return(allRivers.Contains(river) ? river : new River()
                {
                    source = target, target = source
                });
            });

            var bestRivers = availableRivers
                             .Select(river =>
            {
                bool removedItem = allRiversAdjacencyMap.Remove(river);

                var ans = new
                {
                    river        = river,
                    shortestPath = lengthOrDefault(
                        Utils.FindShortestPath(
                            sourceMine,
                            targetMine,
                            allRivers.Where(i => !i.Equals(river)),
                            allRiversAdjacencyMap))
                };

                if (removedItem)
                {
                    allRiversAdjacencyMap.Add(river);
                }

                return(ans);
            })
                             .OrderByDescending(i => i.shortestPath);

            var bestRiver = bestRivers.First();

            return(Tuple.Create(bestRiver.river, (double)bestRiver.shortestPath / shortestPath.Count));
        }
Esempio n. 3
0
        public static IEnumerable <River> ConvertMovesToRivers(
            Map map,
            IEnumerable <Move> moves,
            Func <int, bool> idFilter)
        {
            var validRivers = map.rivers.ToLookup(river => river, river => true);

            Func <int, int, River> createRiver = (source, target) =>
            {
                River ans = new River()
                {
                    source = source, target = target
                };
                return(validRivers.Contains(ans) ? ans : new River()
                {
                    source = target, target = source
                });
            };

            foreach (var move in moves)
            {
                if (move.claim != null)
                {
                    if (idFilter(move.claim.punter))
                    {
                        yield return(createRiver(move.claim.source, move.claim.target));
                    }
                }
                else if (move.option != null)
                {
                    if (idFilter(move.option.punter))
                    {
                        yield return(createRiver(move.option.source, move.option.target));
                    }
                }
                else if (move.splurge != null)
                {
                    if (idFilter(move.splurge.punter))
                    {
                        var rivers = move.splurge.route.Zip(
                            move.splurge.route.Skip(1),
                            (source, target) => createRiver(source, target));

                        foreach (var river in rivers)
                        {
                            yield return(river);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 static Move CreateOptionMove(
     int myId,
     River river)
 {
     return(new Move()
     {
         option = new OptionMove()
         {
             punter = myId,
             source = river.source,
             target = river.target,
         }
     });
 }
Esempio n. 5
0
 static Move CreateClaimMove(
     int myId,
     River river)
 {
     return(new Move()
     {
         claim = new ClaimMove()
         {
             punter = myId,
             source = river.source,
             target = river.target,
         }
     });
 }
Esempio n. 6
0
 public bool Remove(River river)
 {
     map[river.source].Remove(river.target);
     return(map[river.target].Remove(river.source));
 }
Esempio n. 7
0
 public void Add(River river)
 {
     AddImpl(river.source, river.target);
     AddImpl(river.target, river.source);
 }