Dynamic_Games.PAES.archive_soln C# (CSharp) Method

archive_soln() public method

public archive_soln ( Solution s ) : void
s Solution
return void
        void archive_soln(Solution s)
        {
            // given a solution s, add it to the archive if
            // a) the archive is empty
            // b) the archive is not full and s is not dominated or equal to anything currently in the archive
            // c) s dominates anything in the archive
            // d) the archive is full but s is nondominated and is in a no more crowded square than at least one solution
            // in addition, maintain the archive such that all solutions are nondominated.

            int i;
            int repl = 0;
            bool yes = false;
            int most;
            int result;
            int join = 0;
            int old_arclength;
            int set = 0;

            int[] tag = new int[200];//MAX_ARC
            List<Solution> tmp = new List<Solution>(50);

            for (i = 0; i < archive; i++)
            {
                tag[i] = 0;
            }

            if (arclength == 0)
            {
                add_to_archive(s);
                return;
            }

            i = 0;
            result = 0;
            while ((i < arclength) && (result != -1))
            {
                result = equal(s.obj, arc[i].obj, objectives);
                if (result == 1)
                    break;
                if (equil.Equals("Pareto"))
                    result = compare_max_Pareto(s.obj, arc[i].obj, objectives);
                else
                    result = compare_max_Nash(s.obj, arc[i].obj, objectives);

                if ((result == 1) && (join == 0))
                {
                    arc[i] = s;
                    join = 1;
                }
                else if (result == 1)
                {
                    tag[i] = 1;
                    set = 1;
                }
                i++;
            }

            old_arclength = arclength;
            if (set == 1)
            {
                for (i = 0; i < arclength; i++)
                {
                    tmp.Add(arc[i]);
                }
                arclength = 0;

                for (i = 0; i < old_arclength; i++)
                {
                    if (tag[i] != 1)
                    {
                        arc[arclength] = tmp[i];
                        arclength++;
                    }
                }
            }

            if ((join == 0) && (result == 0))  // ie solution is non-dominated by the list
            {
                if (arclength == archive)
                {
                    most = grid_pop[s.grid_loc];
                    for (i = 0; i < arclength; i++)
                    {
                        if (grid_pop[arc[i].grid_loc] > most)
                        {
                            most = grid_pop[arc[i].grid_loc];
                            repl = i;
                            yes = true;
                        }
                    }
                    if (yes)
                    {
                        arc[repl] = s;
                    }
                }
                else
                {
                    add_to_archive(s);
                }
            }
        }