Пример #1
0
 public void addMembers(OrderedSolutionList a_list)
 {
     int nMembers = a_list.size();
     for (int i = 0; i < nMembers; ++i)
     {
         Solution member = a_list.get(i);
         this.add(member);
     }
 }
Пример #2
0
        public void addMembers(OrderedSolutionList a_list)
        {
            int nMembers = a_list.size();

            for (int i = 0; i < nMembers; ++i)
            {
                Solution member = a_list.get(i);
                this.add(member);
            }
        }
Пример #3
0
        public int bestActionIndex(double[] targets)
        {
            bool verbose  = false;
            int  selected = -1;

            double[][]          bounds    = m_player.getValueBounds();
            double              bestValue = -Double.MaxValue;
            OrderedSolutionList myPA      = pa.m_members;
            int numMembers = myPA.size();

            if (verbose && numMembers > 1)
            {
                Console.WriteLine("Choosing among " + myPA.size() + " members.");
            }
            for (int i = 0; i < numMembers; ++i)
            {
                double[] thisRes = myPA.get(i).m_data;

                /*
                 * double val0 = Utils.normalise(thisRes[0], bounds[0][0], bounds[0][1]);
                 * double val1 = Utils.normalise(thisRes[1], bounds[1][0], bounds[1][1]);
                 * double val2 = Utils.normalise(thisRes[2], bounds[2][0], bounds[2][1]);
                 * double val = targets[0] * val0 + targets[1] * val1 + targets[2] * val2;*/

                double val = 0.0;
                for (int t = 0; t < targets.Length; ++t)
                {
                    double v = Utils.normalise(thisRes[t], bounds[t][0], bounds[t][1]);
                    val += v * targets[t];
                }


                if (verbose && numMembers > 1)
                {
                    if (thisRes.Length == 3)
                    {
                        Console.WriteLine("   [%.4f, %.4f, %.4f] => %.4f, from %d\n", thisRes[0], thisRes[1], thisRes[2], val, myPA.get(i).m_through);
                    }
                    if (thisRes.Length == 2)
                    {
                        Console.WriteLine("   [%.4f, %.4f] => %.4f, from %d\n", thisRes[0], thisRes[1], val, myPA.get(i).m_through);
                    }
                }
                //Console.WriteLine("Element in PA " + i + ": " + val);

                if (val > bestValue)
                {
                    bestValue = val;
                    selected  = i;
                }
            }

            if (verbose && numMembers > 1)
            {
                Console.WriteLine("   Selected: " + selected);
            }

            if (selected == -1)
            {
                //Console.WriteLine(" ********************* SELECTED -1, myPA.Count(): " + myPA.Count() + " ***************");
                return(0);
            }

            double[] selectedTarget = myPA.get(selected).m_data;
            //List<int> navSet = valueRoute.Keys.ToList();
            foreach (int key in valueRoute.Keys)
            {
                List <Solution> resFromThisChild = valueRoute[key];

                for (int i = 0; i < resFromThisChild.Count; ++i)
                {
                    double[] sol = resFromThisChild[i].m_data;
                    //Console.WriteLine("PA point " + key + ":" + i + ": " + sol[0] + ", " + sol[1] + ", nVis: " + children[key].nVisits);

                    if (sol.Length == 3 && sol[0] == selectedTarget[0] && sol[1] == selectedTarget[1] && sol[2] == selectedTarget[2])
                    //if(sol[0] == selectedTarget[0] && sol[1] == selectedTarget[1])
                    {
                        //Console.WriteLine("SELECTED-3: " + children[key].nVisits + "," + sol[0] + "," + sol[1] + ": " + key);
                        return(key);
                    }
                    else if (sol.Length == 2 && sol[0] == selectedTarget[0] && sol[1] == selectedTarget[1])
                    {
                        //Console.WriteLine("SELECTED-2: " + children[key].nVisits + "," + sol[0] + "," + sol[1] + ": " + key);
                        return(key);
                    }
                }
            }


            //If we get down here, we've done something wrong.

            /* pa.printArchive();
             *
             * Console.WriteLine("Looking for: " + selectedTarget[0] + "," + selectedTarget[1]);
             * for(Integer key : navSet)
             * {
             *   LinkedList<double[]> resFromThisChild = valueRoute.get(key);
             *
             *   for(int i =0; i < resFromThisChild.Count(); ++i)
             *   {
             *       double[] sol = resFromThisChild.get(i);
             *       Console.WriteLine(key + ": " + sol[0] + "," + sol[1]);
             *       if(sol[0] == selectedTarget[0] && sol[1] == selectedTarget[1])
             *           Console.WriteLine("FOUND!");
             *   }
             * }
             */
            //throw new Exception("Unexpected selection: " + selected);
            return(selected);
        }
Пример #4
0
        public bool add(Solution a_sol)
        {
            //Check if the new entry is dominated by any in the set:

            bool dominated    = false;
            bool dominatesAny = false;
            bool crowded      = false;
            int  i            = 0;

            while (!dominated && i < m_members.size())
            {
                Solution member = m_members.get(i);
                int      dom    = Utils.dominates(member.m_data, a_sol.m_data);

                //if(dom == -1)
                if (dom == -1)
                {
                    //if(crowded)
                    //  System.out.println("OUT ["+m_members.size()+"]");

                    dominated = true;
                }
                else if (dom == 1)
                {
                    //This one is dominated. It must be out.
                    m_members.remove(i);
                    m_hvClean    = false;
                    dominatesAny = true;
                    //And keep the index in place:
                    --i;
                }
                else if (dom == 2)    //Use this line to allow any distance between points in pareto.
                //}else if(dom == 2 || crowded) //Use this line to avoid crowded fronts (min. distance: EPSILON).
                {
                    //There is another identical member in the set. Do NOT include:
                    return(false);
                }
                else if (dom == 0)
                {
                    //crowded |= Utils.crowded(member.m_data, a_sol.m_data, EPSILON);
                }
                ++i;
            }

            if (dominatesAny)
            {
                crowded = false;
            }

            if (!dominated && !crowded)
            {
                /*double[] newOne = new double[a_candidate.length];
                 * System.arraycopy(a_candidate, 0, newOne, 0, a_candidate.length);
                 * Solution newSol = new Solution(newOne);    */
                //Helpfunctions.Instance.logg("Yes added sol:" + a_sol.m_data[0] + ", " + a_sol.m_data[1] + ", " + a_sol.m_data[2]);
                //a_sol.m_state.printLastTurnActions();
                m_members.add(a_sol);
                m_hvClean = false;
                return(true);
            }
            else
            {
                //Helpfunctions.Instance.logg("No added sol:" + a_sol.m_data[0] + ", " + a_sol.m_data[1]);
            }

            return(false);
        }
Пример #5
0
        public int bestActionIndexEuqDistance(double[] targets)
        {
            bool verbose  = false;
            int  selected = -1;

            double[][]          bounds   = m_player.getValueBounds();
            double              distance = Double.MaxValue;
            OrderedSolutionList myPA     = pa.m_members;
            int numMembers = myPA.size();

            if (verbose && numMembers > 1)
            {
                Console.WriteLine("Choosing among " + myPA.size() + " members.");
            }

            for (int i = 0; i < numMembers; ++i)
            {
                double[] thisRes = myPA.get(i).m_data;

                double[] val = new double[targets.Length];
                for (int t = 0; t < targets.Length; ++t)
                {
                    double v = Utils.normalise(thisRes[t], bounds[t][0], bounds[t][1]);
                    val[t] = v;
                }

                double thisDist = Utils.distanceEuq(val, targets);
                if (thisDist < distance)
                {
                    distance = thisDist;
                    selected = i;
                }
            }

            if (verbose && numMembers > 1)
            {
                Console.WriteLine("   Selected: " + selected);
            }

            double[] selectedTarget = myPA.get(selected).m_data;
            //List<int> navSet = valueRoute.Keys.ToList();
            foreach (int key in valueRoute.Keys)
            {
                List <Solution> resFromThisChild = valueRoute[key];

                for (int i = 0; i < resFromThisChild.Count; ++i)
                {
                    double[] sol = resFromThisChild[i].m_data;

                    if (sol.Length == 3 && sol[0] == selectedTarget[0] && sol[1] == selectedTarget[1] && sol[2] == selectedTarget[2])
                    {
                        return(key);
                    }
                    else if (sol.Length == 2 && sol[0] == selectedTarget[0] && sol[1] == selectedTarget[1])
                    {
                        return(key);
                    }
                }
            }
            //throw new Exception("Unexpected selection: " + selected);
            return(selected);
        }