public int[] Route(RoutingData data)
        {
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return(new int[0]);
            }

            var nodes = graph[s];
            var res   = new List <int>();

            int min = int.MaxValue;

            foreach (var node in nodes)
            {
                int w = weights[node, d];
                if (w != int.MaxValue)
                {
                    if (w < min)
                    {
                        res.Clear();
                        res.Add(node);
                        min = w;
                    }
                    else if (w == min)
                    {
                        res.Add(node);
                    }
                }
            }

            return(res.ToArray());
        }
Пример #2
0
        public int[] Route(RoutingData data)
        {
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return(new int[0]);
            }
            var dests = Graph[s];

            if (dests.Length < 1)
            {
                return(new int[0]);
            }

            var res = new List <int>(2);

            var cur_del = Data[d].Sub(Data[s]);

            res.Add(dests[0]);
            int max_dot = cur_del.Dot(Data[dests[0]].Sub(Data[s]));

            for (int i = 1; i < dests.Length; i++)
            {
                int cur_dot = cur_del.Dot(Data[dests[i]].Sub(Data[s]));
                if (cur_dot > max_dot)
                {
                    res.Clear();
                    res.Add(dests[i]);
                    max_dot = cur_dot;
                }
                else if (cur_dot == max_dot)
                {
                    res.Add(dests[i]);
                }
            }

            return(res.ToArray());
        }
        public int[] Route(RoutingData data)
        {
            var dests = RegularOutputs(data.Source, data.Destination);

            var result = new List <int>(2);

            if (dests.Count == 1)
            {
                int dest = dests[0];

                if (Graph.Enabled[dest])
                {
                    result.Add(dest);
                }
                else
                {
                    var perpendiculars = Perpendicular(data.Source, dest);
                    foreach (int p in perpendiculars)
                    {
                        if (Graph.Enabled[p])
                        {
                            result.Add(p);
                        }
                    }
                }
            }
            else if (dests.Count == 2)
            {
                foreach (int dest in dests)
                {
                    if (Graph.Enabled[dest])
                    {
                        result.Add(dest);
                    }
                }
            }

            return(null);
        }
Пример #4
0
        public int[] Route(RoutingData data)
        {
            int p = data.Previous;
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return(new int[0]);
            }
            var dests = Graph[s];

            if (dests.Length < 1)
            {
                return(new int[0]);
            }
            else if (dests.Length == 1)
            {
                return new int[] { dests[0] }
            }
            ;

            // MODIFICATION //
            int j = 0;

            for (int i = 0; i < dests.Length; i++)
            {
                if (dests[i] != p)
                {
                    dests[j++] = dests[i];
                }
            }
            var old = dests;

            dests = new int[j];
            for (int i = 0; i < j; i++)
            {
                dests[i] = old[i];
            }
            // ------------ //

            var res = new List <int>(2);

            var cur_del = Data[d].Sub(Data[s]);

            res.Add(dests[0]);
            int max_dot = cur_del.Dot(Data[dests[0]].Sub(Data[s]));

            for (int i = 1; i < dests.Length; i++)
            {
                int cur_dot = cur_del.Dot(Data[dests[i]].Sub(Data[s]));
                if (cur_dot > max_dot)
                {
                    res.Clear();
                    res.Add(dests[i]);
                    max_dot = cur_dot;
                }
                else if (cur_dot == max_dot)
                {
                    res.Add(dests[i]);
                }
            }

            // MODIFICATION //
            if (res.Count == 0)
            {
                res.Add(p);
            }
            // ------------ //

            return(res.ToArray());
        }
Пример #5
0
        public int[] Route(RoutingData data)
        {
            int p = data.Previous;
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return(new int[] { d });
            }


            var result = new List <int>(2);

            int index = d - s;

            if (index < 0)
            {
                index += Graph.Count;
            }
            for (int i = 1; i < Coordinates.GetLength(1); i++)
            {
                int steps = Coordinates[index, i];
                int next  = -1;
                if (steps > 0)
                {
                    next = (s + Generators[i - 1]) % Graph.Count;
                }
                if (steps < 0)
                {
                    next = s - Generators[i - 1];
                    if (next < 0)
                    {
                        next += Graph.Count;
                    }
                }
                if (next >= 0 && Graph.Enabled[next] && next != p)
                {
                    result.Add(next);
                }
            }

            if (result.Count == 0)
            {
                for (int i = 1; i < Coordinates.GetLength(1); i++)
                {
                    int steps = Coordinates[index, i];
                    int next  = -1;
                    int ind   = i % Generators.Count;
                    if (steps > 0)
                    {
                        next = (s + Generators[ind]) % Graph.Count;
                    }
                    if (steps < 0)
                    {
                        next = s - Generators[ind];
                        if (next < 0)
                        {
                            next += Graph.Count;
                        }
                    }
                    if (next >= 0 && Graph.Enabled[next])
                    {
                        result.Add(next);
                    }
                }
            }

            return(result.ToArray());
        }
Пример #6
0
        public int[] Route(RoutingData data)
        {
            int p = data.Previous;
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return(new int[0]);
            }
            var dests = Graph[s];

            if (dests.Length < 1)
            {
                return(new int[0]);
            }
            else if (dests.Length == 1)
            {
                return new int[] { dests[0] }
            }
            ;

            // MODIFICATION //
            int j = 0;

            for (int i = 0; i < dests.Length; i++)
            {
                if (dests[i] != p)
                {
                    dests[j++] = dests[i];
                }
            }
            var old = dests;

            dests = new int[j];
            for (int i = 0; i < j; i++)
            {
                dests[i] = old[i];
            }
            // ------------ //

            var res = new List <int>(2);

            var cur_del = Data[d].Sub(Data[s]);

            int max_dot         = int.MinValue;
            int total_available = 1;

            foreach (int dest in dests)
            {
                if (dest != d && Graph.Available(dest) <= 2)
                {
                    continue;
                }
                total_available++;
                int cur_dot = cur_del.Dot(Data[dest].Sub(Data[s]));
                if (cur_dot > max_dot)
                {
                    res.Clear();
                    res.Add(dest);
                    max_dot = cur_dot;
                }
                else if (cur_dot == max_dot)
                {
                    res.Add(dest);
                }
            }

            if (total_available <= 2 && p >= 0)
            {
                int cur_dot = cur_del.Dot(Data[p].Sub(Data[s]));
                if (cur_dot > max_dot)
                {
                    res.Clear();
                    res.Add(p);
                    max_dot = cur_dot;
                }
                else if (cur_dot == max_dot)
                {
                    res.Add(p);
                }
            }

            // MODIFICATION //
            if (res.Count == 0 && p >= 0)
            {
                res.Add(p);
            }
            // ------------ //
            return(res.ToArray());
        }
Пример #7
0
        public int[] Route(RoutingData data)
        {
            int p = data.Previous;
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return new int[] { d }
            }
            ;

            int sx = s % Width;
            int sy = s / Width;

            int dx = d % Width;
            int dy = d / Width;

            var dests = new List <int>();

            int t = (sy + 1) * Width + sx;
            int l = sy * Width + sx - 1;
            int b = (sy - 1) * Width + sx;
            int r = sy * Width + sx + 1;

            if (dx - sx < 0 && sx > 1 && Graph.Enabled[l] && l != p)
            {
                dests.Add(l);
            }
            else if (dy - sy < 0 && sy > 1 && Graph.Enabled[b] && b != p)
            {
                dests.Add(b);
            }
            else if (dx - sx < 0 && Graph.Enabled[l] && l != p)
            {
                dests.Add(l);
            }
            else if (dy - sy < 0 && Graph.Enabled[b] && b != p)
            {
                dests.Add(b);
            }
            else if (dx - sx < 0 && sy == 0 && Graph.Enabled[t])
            {
                dests.Add(t);
            }
            else if (dy - sy < 0 && sx == 0 && Graph.Enabled[r])
            {
                dests.Add(r);
            }
            // ------------------ //
            else if (dx - sx > 1 && Graph.Enabled[r])
            {
                dests.Add(r);
            }
            else if (dy - sy > 1 && Graph.Enabled[t])
            {
                dests.Add(t);
            }
            else if (dx - sx > 0 && Graph.Enabled[r])
            {
                dests.Add(r);
            }
            else if (dy - sy > 0 && Graph.Enabled[t])
            {
                dests.Add(t);
            }
            else if (dx - sx > 0 && sy == 0 && Graph.Enabled[t])
            {
                dests.Add(t);
            }
            else if (dy - sy > 0 && sx == 0 && Graph.Enabled[r])
            {
                dests.Add(r);
            }
            else if (dx - sx == 0 && sx > 0)
            {
                dests.Add(l);
            }
            else if (dy - sy == 0 && sy > 0)
            {
                dests.Add(b);
            }

            return(dests.ToArray());
        }
 public int[] Route(RoutingData data)
 {
     return(null);
 }
        public int[] Route(RoutingData data)
        {
            int p = data.Previous;
            int s = data.Source;
            int d = data.Destination;

            if (s == d)
            {
                return new int[] { d }
            }
            ;

            int sx = s % Width;
            int sy = s / Width;

            int dx = d % Width;
            int dy = d / Width;

            var dests = new List <int>();

            if (dx - sx > 0 && sx < Width - 1)
            {
                dests.Add(sy * Width + sx + 1);
            }
            if (dx - sx < 0 && sx > 0)
            {
                dests.Add(sy * Width + sx - 1);
            }
            if (dy - sy > 0 && sy < Height - 1)
            {
                dests.Add((sy + 1) * Width + sx);
            }
            if (dy - sy < 0 && sy > 0)
            {
                dests.Add((sy - 1) * Width + sx);
            }

            dests.RemoveAll((int node) => !Graph.Enabled[node]);

            if (dests.Count == 0)
            {
                if (dx - sx <= 0 && sx < Width - 1)
                {
                    dests.Add(sy * Width + sx + 1);
                }
                if (dx - sx >= 0 && sx > 0)
                {
                    dests.Add(sy * Width + sx - 1);
                }
                if (dy - sy <= 0 && sy < Height - 1)
                {
                    dests.Add((sy + 1) * Width + sx);
                }
                if (dy - sy >= 0 && sy > 0)
                {
                    dests.Add((sy - 1) * Width + sx);
                }
            }

            if (dests.Count > 1)
            {
                dests.RemoveAll((int node) => node == p);
            }

            return(dests.ToArray());
        }