public static int RunGAMapFinder(GAFinderOption option) { var map = _loadMap(option.MapFileName, option.Diagonal); if (map == null) { return(1); } var heuristic = (new HeuristicFactory()).GetImplementation(option.Heuristic); var mutate = new MutateFactory().GetImplementation(option.Mutate); var crossover = new CrossoverFactory().GetImplementation(option.Crossover); var selection = new SelectionFactory().GetImplementation(option.Selection); var fitness = new FitnessFactory().GetImplementation(option.Fitness); fitness.Heuristic = heuristic; var finder = FinderFactory.GetGAImplementation( crossover, mutate, fitness, selection, option.Population, option.GenerationLimit, option.BestToPick ); return(_runFinder(finder, heuristic, map, option.Window, option.NoShowSteps, option.BlockSize, option.UISleep)); }
public List <string> FindPath(string start, string stop) { ; IFinder finder; using (var ctx = new TestDbContext("TestDBCompact")) { var nodes = ctx.Nodes.ToList(); var adjacencies = ctx.Adjacencies.ToList(); finder = FinderFactory.GetFinder(FinderType.Dijkstra, new Common.Enities.Graph(adjacencies, nodes)); } return(finder.Find(start, stop)); }
public winSimpleSearch() { InitializeComponent(); // _vm = ViewModelSource.Create(() => new SimpleSearchViewModel()); lblEntityName.Text = typeof(T).Name; _search = FinderFactory.CreateFinder <T>(); txtSearch.AllowHtmlTextInToolTip = DefaultBoolean.True; txtSearch.ToolTip = _search.Descripcion; Resultado = null; }
public void FindTest() { var finder = FinderFactory.GetInstance(); var result = finder.Find( new Waypoint("A", 10.0, 20.0), new Waypoint("B", 60.0, 150.0)); for (int i = result.Count - 1; i >= 1; i--) { Assert.IsTrue(result[i].Distance( result[i - 1]) <= RandomRouteFinder.MaxLegDis); } }
public IMap DefineMap(DiagonalMovement diagonal, int width, int height, int seed, int minPathLength) { var IsAGoodMap = false; IMap ret = null; var aStar = FinderFactory.GetAStarImplementation(); IHeuristic heuristic; heuristic = diagonal == DiagonalMovement.Never ? HeuristicFactory.GetManhattamImplementation() : HeuristicFactory.GetOctileImplementation(); while (!IsAGoodMap) { var nodes = new List <Node>(); var _map = new Map(diagonal, width, height); var size = Convert.ToInt32((width * height) * (seed / 100M)); var rand = new Random(); while (size > 0) { var p = RandNode(rand, width, height, true); GridMap.Add(p); size--; } _map.DefineAllNodes(GridMap); _map.StartNode = RandNode(rand, width, height, false); _map.EndNode = RandNode(rand, width, height, false); if (!_map.ValidMap()) { throw new Exception("Invalid map configuration"); } if (aStar.Find(_map, heuristic)) // verifica se o mapa possui um caminho { var path = _map.GetPath(); if (path.Max(e => e.G) >= minPathLength) // verifica se o caminho sastifaz o tamanho minimo { IsAGoodMap = true; ret = _map; } } GridMap = new List <Node>(); } ret.Clear(); ret.MapType = MapGeneratorEnum.Random; return(ret); }
private Route GetRandRoute(IReadOnlyList <SubRoute> analyzed, int index) { var startEnd = GetStartEndWpts(analyzed, index); var randRoute = FinderFactory.GetInstance() .Find(startEnd.Start, startEnd.End) .ToRoute(); // The first and last waypoint idents generated by the // random route are based on lat/lon and may be different // than expected. randRoute.Nodes.RemoveFirst(); randRoute.AddFirstWaypoint(startEnd.Start, "DCT"); randRoute.Nodes.RemoveLast(); randRoute.AddLastWaypoint(startEnd.End, "DCT"); return(randRoute); }
private void Initializated() { FinderStatus finderStatus; ColorStatus colorStatus; bool error = _comand.ReturnCommands(out finderStatus, out colorStatus, out _chain, out _path); _displayer = new ConsolDisplayer(_chain, ColorConsoleFactory.GetColor(colorStatus)); if (error) { _displayer.Display(new string[] { "Incorret data" }); Environment.Exit(1); } _finder = FinderFactory.GetFinder(finderStatus); if (_path.Equals(string.Empty)) { _reader = new ConsoleReader(); } else { _reader = new FileTxtReader(); } }
static void Process(BatchOption option) { var ft = new FileTool(); var now = DateTime.Now; var folder = option.Directory; var dataFile = "_data.csv"; var dataFileGA = "_dataGA.csv"; var files = Directory.GetFiles(folder, "*.txt"); var fileCount = files.Count(); var finders = option.Finder.ToArray(); var heuristics = option.Heuristic.ToArray(); var Mutation = option.Mutate.ToArray(); var Crossover = option.Crossover.ToArray(); var Fitness = option.Fitness.ToArray(); var Selection = option.Selection.Cast <SelectionEnum>().ToArray(); var newdatafile = !File.Exists(dataFile); var newdatafileGA = !File.Exists(dataFileGA); StreamWriter csvFile; StreamWriter csvGAFile; if (newdatafile) { csvFile = File.CreateText(dataFile); } else { csvFile = File.AppendText(dataFile); } if (newdatafileGA) { csvGAFile = File.CreateText(dataFileGA); } else { csvGAFile = File.AppendText(dataFileGA); } //csvFile = new StreamWriter(File.Open(dataFile, FileMode.OpenOrCreate), Encoding.UTF8, 4096, false); //csvGAFile = new StreamWriter(File.Open(dataFileGA, FileMode.OpenOrCreate), Encoding.UTF8, 4096, false); if (newdatafile) { csvFile.Write(new TextWrapper().GetHeader()); } if (newdatafileGA) { csvGAFile.Write(new TextGAWrapper().GetHeader()); } for (int i = 0; i < fileCount; i++) { var map = FileTool.ReadMapFromFile(files[i]); foreach (var _finder in finders) { foreach (var _h in heuristics) { var h = new HeuristicFactory().GetImplementation(_h); var finder = new FinderFactory().GetImplementation(_finder); if (finder is IGeneticAlgorithm) { for (int cross = 0; cross < Crossover.Count(); cross++) { for (int mut = 0; mut < Mutation.Count(); mut++) { for (int fit = 0; fit < Fitness.Count(); fit++) { for (int sel = 0; sel < Selection.Count(); sel++) { for (int j = 0; j < option.GaTimes; j++) { GC.Collect(); GC.WaitForPendingFinalizers(); var GAFinder = (IGeneticAlgorithm) new FinderFactory().GetImplementation(_finder); GAFinder.Crossover = new CrossoverFactory().GetImplementation(Crossover[cross]); GAFinder.Mutate = new MutateFactory().GetImplementation(Mutation[mut]); GAFinder.Fitness = new FitnessFactory().GetImplementation(Fitness[fit]); GAFinder.Selection = new SelectionFactory().GetImplementation(Selection[sel]); var helper = $"\n n:{j},cx:{GAFinder.Crossover.GetType().Name},m:{GAFinder.Mutate.GetType().Name},f:{GAFinder.Fitness.GetType().Name},s:{GAFinder.Selection.GetType().Name}"; var csv = new TextWrapper(); csv = RunStep(csv, i, fileCount, map, h, GAFinder, option.Directory, Path.GetFileName(files[i]), helper); csvFile.Write(csv.ToString()); var csvGA = new TextGAWrapper { Alg = csv.Alg, MapNumber = csv.MapNumber, Heuristic = csv.Heuristic, MapTypeGenerate = csv.MapTypeGenerate, MapDiagonal = csv.MapDiagonal, MapSize = csv.MapSize, Solution = csv.Solution, Time = csv.Time, MaxNodes = csv.MaxNodes, PathLength = csv.PathLength, Crossover = GAFinder.Crossover.GetType().Name, Mutation = GAFinder.Mutate.GetType().Name, Fitness = GAFinder.Fitness.GetType().Name, Selection = GAFinder.Selection.GetType().Name, Generations = GAFinder.Generations.ToString(), }; csvGAFile.Write(csvGA.ToString()); } } } } } } else { var csv = new TextWrapper(); csv = RunStep(csv, i, fileCount, map, h, finder, option.Directory, Path.GetFileName(files[i])); csvFile.Write(csv.ToString()); } csvFile.Flush(); csvGAFile.Flush(); } } } DrawTextProgressBar(fileCount, fileCount); csvFile.Dispose(); csvGAFile.Dispose(); }
public async Task <ActionResult> Create([Bind(Include = "Id,Text")] TextBlobModel textBlobModel) { if (ModelState.IsValid) { var statementProducer = new StatementProducer(new LuisClientFactory("https://eastus2.api.cognitive.microsoft.com/luis/v2.0/apps/79af6370-41bd-4d03-9c7c-5f234eb6049c?subscription-key=784cc32302a84581ab894febc8775393&timezoneOffset=0&verbose=true&q=").Create()); var finder = FinderFactory.CreateFinder(); var urlClassifier = new URLClassification(); textBlobModel.Id = Guid.NewGuid(); textBlobModel.CreatedBy = User.Identity.Name; var statementTasks = Task.WhenAll(statementProducer.GetStatements(textBlobModel)); var statements = await statementTasks; // Generate references for each statement var statementTasks2 = statements .Select(async statement => { if (statement.Classification == StatementClassification.Other) { return(statement); } var referenceTasks = (await finder.FindSuggestions(statement.Text)).Select(async uri => { var bias = (await urlClassifier.ClassifyOutletDescription(uri.Host)); return(new Reference { Id = Guid.NewGuid(), CreatedBy = "System", Link = uri, Tags = new List <string>(), Bias = bias == null ? null : new Bias(bias, Guid.NewGuid()) }); }); var references = await Task.WhenAll(referenceTasks); return(new Statement(statement, references.ToList())); }); var statementsWithReferences = await Task.WhenAll(statementTasks2); textBlobModel.Statements = statementsWithReferences.ToList(); var entityFinder = new EntityFinder(); var entities = await entityFinder.GetEntities(textBlobModel.Text); textBlobModel.Entities = entities .Select(e => new Entity { Id = Guid.NewGuid(), CreatedBy = "Microsoft Entity Linking", Name = entityFinder.ExtractEntityName(e), WikiUrl = entityFinder.ExtractEntityWikiUrlString(e), Matches = entityFinder.ExtractMatches(e) .Select(tuple => new Match { Id = Guid.NewGuid(), Text = tuple.Item1, Offset = tuple.Item2 }) .ToList() }) .ToList(); // Save TextBlob db.TextBlobModels.Add(textBlobModel); await db.SaveChangesAsync(); await FetchPersonas(textBlobModel); return(View(textBlobModel)); } return(View(textBlobModel)); }
public IMap DefineMap(DiagonalMovement diagonal, int width, int height, int seed, int minPathLength) { int _GDC(int a, int b) => (b == 0 || a == 0) ? a | b : _GDC(Min(a, b), Max(a, b) % Min(a, b)); var blocksize = Blocksize > 0 ? Blocksize : _GDC(width, height); var IsAGoodMap = false; IMap ret = null; // finder para valida se o mapa é passavel var aStar = FinderFactory.GetAStarImplementation(); IHeuristic heuristic; heuristic = diagonal == DiagonalMovement.Never ? HeuristicFactory.GetManhattamImplementation() : HeuristicFactory.GetOctileImplementation(); var subgrid = new List <Node>(); while (!IsAGoodMap) { var nodes = new List <Node>(); var _map = new Map(diagonal, width, height); var size = Convert.ToInt32(blocksize * blocksize * (seed / 100M)); var rand = new Random(); while (size > 0) { var p = RandNode(rand, blocksize, blocksize, true); subgrid.Add(p); size--; } for (int i = 0; i < width; i += blocksize) { for (int j = 0; j < height; j += blocksize) { foreach (var item in subgrid) { var x = item.X + i; var y = item.Y + j; if (x < width && y < height) { var node = new Node(x, y, false); GridMap.Add(node); } } } } _map.DefineAllNodes(GridMap); _map.StartNode = RandNode(rand, width, height, false); _map.EndNode = RandNode(rand, width, height, false); if (!_map.ValidMap()) { throw new Exception("Invalid map configuration"); } if (aStar.Find(_map, heuristic)) // verifica se o mapa possui um caminho { var path = _map.GetPath(); if (path.Max(e => e.G) >= minPathLength) // verifica se o caminho sastifaz o tamanho minimo { IsAGoodMap = true; _map.Clear(); ret = _map; } } GridMap = new List <Node>(); subgrid = new List <Node>(); } ret.Clear(); ret.MapType = MapGeneratorEnum.WithPattern; return(ret); }
// GET: Sentences/Details public async Task <IActionResult> Details(Guid Id) { if (!ModelState.IsValid) { return(NotFound()); } var _sent = _context.Sentences .SingleOrDefault(s => (s.Id == Id && s.Type == SentenceType.OBJECTIVE)); if (_sent == null) { return(NotFound()); } var factory = new FinderFactory(_configuration["Authentication:Finder:Key"]); var finder = factory.CreateFinder(); var urlClassifier = new URLClassification(); var referenceTasks = (await finder.FindSuggestions(_sent.Content)) .Select(async uri => { var bias = await urlClassifier.ClassifyOutletDescription(uri.Host); return(new Reference { Id = Guid.NewGuid(), CreatedBy = "System", Link = uri, Tags = new List <string>(), Bias = bias == null ? null : new Bias(bias, Guid.NewGuid()) }); }); var references = await Task.WhenAll(referenceTasks); var entityFinder = new EntityFinder(_configuration["Authentication:Entity:Key"]); var entityList = (await entityFinder.GetEntities(_sent.Content)) .Select(e => new Entity { Id = Guid.NewGuid(), CreatedBy = "Microsoft Entity Linking", Name = entityFinder.ExtractEntityName(e), WikiUrl = entityFinder.ExtractEntityWikiUrlString(e), Matches = entityFinder.ExtractMatches(e) .Select(tuple => new Match { Id = Guid.NewGuid(), Text = tuple.Item1, Offset = tuple.Item2 }) .ToList() }).ToList(); var entityTasks = entityList .Select(async e => { e.Persona = PersonasDBLookups.ByName[e.Name].FirstOrDefault(); if (e.Persona != null) { await e.Persona.FetchRecentStatements(); } return(e); }); var entities = await Task.WhenAll(entityTasks); return(Json(new { References = references, Entities = entities })); }
public LoadCoordinatorFactory(FinderFactory finderFactory) { _finderFactory = finderFactory; }