public void RRHeurStageI(string filename)
        {
            for (int i = 0; i < ntests; i++)
            {
                var algname = nameof(RRHeurStageI) + "20extra";
                //  formulation.AvailabilityHardConstraint = false;
                var data = Data.ReadXml(dataPath + filename, "120", "4");

                //var formulation = ProblemFormulation.UD2NoOverbook;
                // formulation.AvailabilityHardConstraint = false;
                //   formulation.OverbookingAllowed = 0.35;
                var ModelParameters = new CCTModel.MIPModelParameters()
                {
                    UseStageIandII        = false,
                    TuneGurobi            = true,
                    UseHallsConditions    = true,
                    UseRoomHallConditions = true,
                    // UseRoomsAsTypes = true,
                    UseRoomsAsTypes          = false,
                    RoomBoundForEachTimeSlot = true,
                    Seed = seeds[i],
                };
                var heuristics = new Heuristics(TimelimitStageI + 20, data, formulation, ModelParameters);
                var sol        = heuristics.Run();
                Console.WriteLine(sol.AnalyzeSolution());
                var objective = (int)Math.Round(sol.Objective);

                var dataname = System.IO.Path.GetFileNameWithoutExtension(filename);

                File.AppendAllText(@"c:\temp\heuristic.txt",
                                   $"{algname};{dataname};{DateTime.Now};{i};{objective};{heuristics.totalseconds};{heuristics.roomtightseconds}\n");
            }
        }
Beispiel #2
0
 /*----------------------------------------------------------------------------------------*/
 private void InitializeHeuristics()
 {
     Heuristics.Add(new StandardHeuristic <ConstructorInfo>());
     Heuristics.Add(new StandardHeuristic <MethodInfo>());
     Heuristics.Add(new StandardHeuristic <PropertyInfo>());
     Heuristics.Add(new StandardHeuristic <FieldInfo>());
 }
Beispiel #3
0
    public static Heuristics getInstance()
    {
        if (instance == null)
        {
            instance = new Heuristics();
        }

        return(instance);
    }
Beispiel #4
0
        /// <summary>
        /// Splits the tree into a branch containing clauses where P appears and another branch with clauses where Not(p) appears.
        /// </summary>
        /// <param name="cnf"></param>
        /// <returns>Returns a Tuple with two CnFs one for the first branch and another for the second branch.</returns>
        private Tuple <Cnf, Cnf> Split(Cnf cnf)
        {
            var literal = Heuristics.ChooseLiteral(cnf);

            if (literal == null)
            {
                return(new Tuple <Cnf, Cnf>(new Cnf(), new Cnf()));
            }
            var tuple = SplittingOnLiteral(cnf, literal);

            return(new Tuple <Cnf, Cnf>(RemoveLiteral(tuple.Item1, literal), RemoveLiteral(tuple.Item2, NegateLiteral(literal))));
        }
Beispiel #5
0
        public void DetectBackgroundTest()
        {
            var path1 = "PicassoUnitTest/DetectBackgroundTest/249-238-32.png";

            var    filepath1 = Path.Combine(Drive.GetDriveRoot(), path1);
            Bitmap image1    = new Bitmap(filepath1);

            Bgr expectedBackGround = new Bgr(249, 238, 32);
            Bgr actualBackGround   = Heuristics.DetectBackground(image1, 10);

            Assert.IsTrue(Utility.IsEqual(expectedBackGround, actualBackGround));
        }
Beispiel #6
0
        public override float CalculateSpamValue(Message sentMessage, bool keepCached = true)
        {
            switch (AggregateMethod)
            {
            case HeuristicAggregateMethod.Sum:
                return(Heuristics.Sum(d => d.Key.CalculateSpamValue(sentMessage, keepCached) * d.Value));

            case HeuristicAggregateMethod.Average:
                return(Heuristics.Average(d => d.Key.CalculateSpamValue(sentMessage, keepCached) * d.Value));

            case HeuristicAggregateMethod.Max:
                return(Heuristics.Max(d => d.Key.CalculateSpamValue(sentMessage, keepCached) * d.Value));

            default:
                return(Heuristics.Sum(d => d.Key.CalculateSpamValue(sentMessage, keepCached) * d.Value));
            }
        }
        public static float HeuristicsFunc(Heuristics heuristics, Point start, Point end, float D = 1)
        {
            float dx = Math.Abs(start.X - end.X);
            float dy = Math.Abs(start.Y - end.Y);

            switch (heuristics)
            {
            case Heuristics.Manhattan:
                return(D * (dx + dy));

            case Heuristics.Euclidean:
                return(D * (float)Math.Sqrt(dx * dx + dy * dy));

            default:
                throw new Exception("Invalid Heuristic Function");
            }
        }
Beispiel #8
0
        public void ExtractImagesTest()
        {
            //var path1 = "PicassoUnitTest/PreprocessingTest/10images.jpg";
            //var path2 = "PicassoUnitTest/PreprocessingTest/12images.jpg";
            //var path3 = "PicassoUnitTest/PreprocessingTest/19images.jpg";
            var path1 = "PicassoUnitTest/PreprocessingTest/17images.jpg";

            var    filepath1       = Path.Combine(Drive.GetDriveRoot(), path1);
            Bitmap image1          = new Bitmap(filepath1);
            Bgr    backgroundColor = Heuristics.DetectBackground(image1, 10);
            Bitmap mask1           = Preprocessing.FloodFill(image1, 100, 100, 50, backgroundColor);

            List <Bitmap> List1 = new List <Bitmap>();

            List1 = Preprocessing.ExtractImages(image1, mask1);
            Assert.IsTrue(List1.Count == 17);
        }
Beispiel #9
0
        /// <summary>
        /// Estimates path cost between a and b using selected heuristics function
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public float Heuristic(Vector3 a, Vector3 b)
        {
            switch (heuristic)
            {
            case HeuristicsFunction.euclidean:
                return(Heuristics.Euclidean(a, b));

            case HeuristicsFunction.manhattan:
                return(Heuristics.Manhattan(a, b));

            case HeuristicsFunction.chebyshev:
                return(Heuristics.Chebyshev(a, b));

            case HeuristicsFunction.octile:
                return(Heuristics.Octile(a, b));
            }
            return(0);
        }
Beispiel #10
0
    void ProcessTile(BlockPos pos)
    {
        Heuristics h      = new Heuristics();
        bool       exists = open.TryGetValue(pos, out h);

        if (!exists)
        {
            return;
        }

        Debug.DrawLine(new Vector3(h.parent.x, h.parent.y + 1, h.parent.z),
                       new Vector3(pos.x, pos.y + 1, pos.z), Color.red, 40);

        open.Remove(pos);
        closed.Add(pos, h);

        CheckAdjacent(pos, h);
    }
        /// <summary>
        /// Logs the search statistics.
        /// </summary>
        protected override void LogSearchStatistics()
        {
            if (LoggingEnabled)
            {
                string message = $"Closed nodes: {GetClosedNodesCount()}" +
                                 $"\tOpen nodes: {GetOpenNodesCount()}" +
                                 $"\tMax g-value: {MaxGValue}";

                IHeuristic heuristic = Heuristic as IHeuristic;
                if (heuristic != null)
                {
                    message += $"\tHeuristic calls: {heuristic.GetCallsCount()}" +
                               $"\tMin heuristic: ({string.Join(", ", Heuristics.Select(h => ((IHeuristic)h).GetStatistics().BestHeuristicValue))})" +
                               $"\tAvg heuristic: ({string.Join(", ", Heuristics.Select(h => ((IHeuristic)h).GetStatistics().AverageHeuristicValue.ToString("0.###")))})";
                }
                message += $"\tCurrent time: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}";

                LogMessage(message);
            }
        }
        public void TestSolveStageIRoomRelaxedAndFixed(string filename)
        {
            for (int i = 0; i < ntests; i++)
            {
                var algname = nameof(TestSolveStageIRoomRelaxedAndFixed) + "roomrelaxontimeslot";
                //  formulation.AvailabilityHardConstraint = false;
                var data = Data.ReadXml(dataPath + filename, "120", "4");

                //var formulation = ProblemFormulation.UD2NoOverbook;
                // formulation.AvailabilityHardConstraint = false;
                //   formulation.OverbookingAllowed = 0.35;
                var ModelParameters = new CCTModel.MIPModelParameters()
                {
                    UseStageIandII        = false,
                    TuneGurobi            = true,
                    UseHallsConditions    = true,
                    UseRoomHallConditions = true,
                    // UseRoomsAsTypes = true,
                    UseRoomsAsTypes          = false,
                    RoomBoundForEachTimeSlot = true,
                    Seed = seeds[i],
                };
                var heuristics = new Heuristics(TimelimitStageI, data, formulation, ModelParameters);
                var sol        = heuristics.Run();
                Console.WriteLine(sol.AnalyzeSolution());

                //sol = heuristics.SolveStageII();
                //Console.WriteLine(sol.AnalyzeSolution());

                //var model = RoomRelaxAndTight(data, ModelParameters);


                var objective = (int)Math.Round(sol.Objective);
                File.AppendAllText(@"c:\temp\heuristic.txt",
                                   $"{algname};{filename};{DateTime.Now.ToString()};{i};{objective}\n");
            }
        }
Beispiel #13
0
    void CheckAdjacent(BlockPos pos, Heuristics dist)
    {
        List<BlockPos> adjacentPositions = new List<BlockPos>();
        List<float> distanceFromStart= new List<float>();

        //Cardinal directions
        adjacentPositions.Add(new BlockPos(pos.x, pos.y, pos.z + 1));
        distanceFromStart.Add(dist.g +1);
        adjacentPositions.Add(new BlockPos(pos.x + 1, pos.y, pos.z));
        distanceFromStart.Add(dist.g +1);
        adjacentPositions.Add(new BlockPos(pos.x, pos.y, pos.z - 1));
        distanceFromStart.Add(dist.g +1);
        adjacentPositions.Add(new BlockPos(pos.x - 1, pos.y, pos.z));
        distanceFromStart.Add(dist.g +1);

        //diagonal directions
        adjacentPositions.Add(new BlockPos(pos.x + 1, pos.y, pos.z + 1));
        distanceFromStart.Add(dist.g +1.414f);
        adjacentPositions.Add(new BlockPos(pos.x + 1, pos.y, pos.z - 1));
        distanceFromStart.Add(dist.g +1.414f);
        adjacentPositions.Add(new BlockPos(pos.x - 1, pos.y, pos.z - 1));
        distanceFromStart.Add(dist.g +1.414f);
        adjacentPositions.Add(new BlockPos(pos.x - 1, pos.y, pos.z + 1));
        distanceFromStart.Add(dist.g +1.414f);

        //climb up directions
        adjacentPositions.Add(new BlockPos(pos.x, pos.y+1, pos.z+1));
        distanceFromStart.Add(dist.g + 1.414f);
        adjacentPositions.Add(new BlockPos(pos.x+1, pos.y+1, pos.z));
        distanceFromStart.Add(dist.g + 1.414f);
        adjacentPositions.Add(new BlockPos(pos.x, pos.y+1, pos.z-1));
        distanceFromStart.Add(dist.g + 1.414f);
        adjacentPositions.Add(new BlockPos(pos.x-1, pos.y+1, pos.z));
        distanceFromStart.Add(dist.g + 1.414f);

        //climb down directions
        adjacentPositions.Add(new BlockPos(pos.x, pos.y-1, pos.z+1));
        distanceFromStart.Add(dist.g + 1.414f);
        adjacentPositions.Add(new BlockPos(pos.x+1, pos.y-1, pos.z));
        distanceFromStart.Add(dist.g + 1.414f);
        adjacentPositions.Add(new BlockPos(pos.x, pos.y-1, pos.z-1));
        distanceFromStart.Add(dist.g + 1.414f);
        adjacentPositions.Add(new BlockPos(pos.x-1, pos.y-1, pos.z));
        distanceFromStart.Add(dist.g + 1.414f);

        for (int i = 0; i<adjacentPositions.Count; i++)
        {
            if(!closed.ContainsKey(adjacentPositions[i])){

                var h = new Heuristics(
                            distanceFromStart[i],
                            Distance(targetLocation,
                            adjacentPositions[i]),
                            pos);

                if (IsWalkable(world, adjacentPositions[i]))
                {

                    Heuristics existingTile;
                    if (open.TryGetValue(adjacentPositions[i], out existingTile))
                    {
                        if(existingTile.g > distanceFromStart[i]){
                            open.Remove(adjacentPositions[i]);
                            open.Add(adjacentPositions[i], h);
                        }

                    } else {
                        open.Add(adjacentPositions[i],h);
                    }

                }
            }

        }
    }
Beispiel #14
0
    void ProcessTile(BlockPos pos)
    {
        Heuristics h = new Heuristics();
        bool exists = open.TryGetValue(pos, out h);

        if (!exists)
            return;

        Debug.DrawLine(new Vector3(h.parent.x, h.parent.y + 1, h.parent.z),
                new Vector3(pos.x, pos.y + 1, pos.z), Color.red, 40);

        open.Remove(pos);
        closed.Add(pos, h);

        CheckAdjacent(pos, h);
    }
Beispiel #15
0
    void ProcessTile(BlockPos pos)
    {
        Heuristics h = new Heuristics();
        bool exists = open.TryGetValue(pos, out h);

        if (!exists)
            return;

        open.Remove(pos);
        closed.Add(pos, h);

        CheckAdjacent(pos, h);
    }
 /**
  * @param inputStream
  * @param errorHandler
  * @param locator
  * @throws IOException
  * @throws SAXException
  */
 public HtmlInputStreamReader(Stream inputStream,
         ErrorHandler errorHandler, Tokenizer tokenizer, Driver driver,
         Heuristics heuristics)
 {
     this.inputStream = inputStream;
     this.errorHandler = errorHandler;
     this.tokenizer = tokenizer;
     this.driver = driver;
     this.sniffing = true;
     Encoding encoding = (new BomSniffer(this)).sniff();
     if (encoding == null) {
         position = 0;
         encoding = (new MetaSniffer(errorHandler, this)).sniff(this);
         if (encoding == null
                 && (heuristics == Heuristics.CHARDET || heuristics == Heuristics.ALL)) {
             encoding = (new ChardetSniffer(byteArray, limit)).sniff();
         }
         if (encoding == null
                 && (heuristics == Heuristics.ICU || heuristics == Heuristics.ALL)) {
             position = 0;
             encoding = (new IcuDetectorSniffer(this)).sniff();
         }
         sniffing = false;
         if (encoding == null) {
             encoding = Encoding.WINDOWS1252;
         }
         if (driver != null) {
             driver.setEncoding(encoding, Confidence.TENTATIVE);
         }
     } else {
         if (encoding == Encoding.UTF8) {
             if (driver != null) {
                 driver.setEncoding(Encoding.UTF8, Confidence.CERTAIN);
             }
         } else {
             if (driver != null) {
                 driver.setEncoding(Encoding.UTF16, Confidence.CERTAIN);
             }
         }
     }
     this.decoder = encoding.newDecoder();
     sniffing = false;
     position = 0;
     bytesRead = 0;
     byteBuffer.position(position);
     byteBuffer.limit(limit);
     initDecoder();
 }