public World(IEnumerable <State> states, Bounds bounds, INeighborhood neighborhood, RuleSet <State> rules) { Cells = states.Select((st, i) => new Cell <State>(st, IndexToPosition(i))); Bounds = bounds; Neighborhood = neighborhood; Rules = rules; }
public World(IEnumerable <Cell <State> > cells, Bounds bounds, INeighborhood neighborhood, RuleSet <State> rules) { Cells = cells; Bounds = bounds; Neighborhood = neighborhood; Rules = rules; }
public LocalSearch(int _data_size, INeighborhood <T> _neighborhood, IComparer <T> _comparer, Random _random) { neighborhood = _neighborhood; comparer = _comparer; random = _random; }
private IContainer addActiveTransportToNeighborhood(INeighborhood neighborhood, ITransport transport, TransporterMoleculeContainer transporterMolecule, string transportedMoleculeName, IBuildConfiguration buildConfiguration) { return(_moleculePropertiesContainerTask.NeighborhoodMoleculeTransportContainerFor(neighborhood, transportedMoleculeName, transporterMolecule, transport.Name, buildConfiguration) .WithChild(transport)); }
private ITransport mapFrom(ITransportBuilder transportBuilder, INeighborhood neighborhood, string moleculeName, IBuildConfiguration buildConfiguration) { var transport = _transportMapper.MapFrom(transportBuilder, buildConfiguration); transport.SourceAmount = neighborhood.GetNeighborSatisfying(transportBuilder.SourceCriteria).GetSingleChildByName <IMoleculeAmount>(moleculeName); transport.TargetAmount = neighborhood.GetNeighborSatisfying(transportBuilder.TargetCriteria).GetSingleChildByName <IMoleculeAmount>(moleculeName); return(transport); }
private void resolveNeighbors(IModel cloneModel, INeighborhood sourceNeighborhood, INeighborhood cloneNeighborhood) { var firstNeighborPath = _objectPathFactory.CreateAbsoluteObjectPath(sourceNeighborhood.FirstNeighbor); var secondNeighborPath = _objectPathFactory.CreateAbsoluteObjectPath(sourceNeighborhood.SecondNeighbor); cloneNeighborhood.FirstNeighbor = firstNeighborPath.Resolve <IContainer>(cloneModel.Root); cloneNeighborhood.SecondNeighbor = secondNeighborPath.Resolve <IContainer>(cloneModel.Root); }
private void finalizeTransportsInNeighborhood(IModel cloneModel, INeighborhood sourceNeighborhood, INeighborhood cloneNeighborhood) { finalizeTransportsInMoleculeParentContainer(cloneModel, sourceNeighborhood, cloneNeighborhood); foreach (var sourceMoleculeContainer in sourceNeighborhood.GetChildren <IContainer>()) { var cloneMoleculeContainer = cloneNeighborhood.GetSingleChildByName <IContainer>(sourceMoleculeContainer.Name); finalizeTransportsInMoleculeParentContainer(cloneModel, sourceMoleculeContainer, cloneMoleculeContainer); } }
private AssignmentTwoResultList <GraphGenome> MultiStartLocalSearch(INeighborhood <GraphGenome> neighborhood) { //we moeten nog iets met ExperimentAmount doen... //for(int i = 0; i < ExperimentAmount; ++i) AssignmentTwoResultList <GraphGenome> results = new AssignmentTwoResultList <GraphGenome>("$MLS_{" + neighborhood.Name + "}$"); for (int j = 0; j < threads.Length; j++) { elapsedMilisecondsThreads[j] = new List <AssignmentTwoResults <GraphGenome> >(); int k = j; int seed = main_random_source.Next(); int amount = OptimaAmount / threads.Length; Thread T = new Thread(() => searchThread(k, amount, seed, neighborhood)); threads[j] = T; } Stopwatch sw = new Stopwatch(); sw.Start(); foreach (Thread T in threads) { T.Start(); } while (this.threadsAreRunning()) { ; } sw.Stop(); GraphGenome optimum = null; for (int j = 0; j < threads.Length; j++) { if (optimum == null || optimum.Fitness > solutionsThreads[j].Fitness) { optimum = solutionsThreads[j]; } } //List<AssignmentTwoResults> results = new List<AssignmentTwoResults>(); foreach (List <AssignmentTwoResults <GraphGenome> > L in elapsedMilisecondsThreads) { results.AddRange(L); } //Console.WriteLine("Best solution found: {0} in an average of {1} ms", optimum.Fitness, cpu_ticks.Average()); Console.WriteLine("Best solution found: {0} in an average of ... ms", optimum.Fitness); //, results.Sum() / OptimaAmount); Console.WriteLine("Total time: {0} sec", sw.ElapsedMilliseconds / 1000f); optimum.ToImage(String.Format("results/MLS[{0}]-{1}.bmp", neighborhood.Name, optimum.Fitness), 3000, 3000); return(results); }
protected override void Context() { base.Context(); _individual = new Individual(); var neighborhoods = A.Fake <IContainer>().WithName(Constants.NEIGHBORHOODS); _neighborhood1 = A.Fake <INeighborhood>(); _neighborhood2 = A.Fake <INeighborhood>(); A.CallTo(() => neighborhoods.GetChildren <INeighborhood>()).Returns(new[] { _neighborhood1, _neighborhood2 }); _individual.Add(neighborhoods); }
public IContainer NeighborhoodMoleculeContainerFor(INeighborhood neighborhood, string moleculeName) { var moleculeContainer = neighborhood.GetSingleChildByName <IContainer>(moleculeName); if (moleculeContainer == null) { throw new MissingMoleculeContainerException(moleculeName); } return(moleculeContainer); }
public void TestSerializationEmptyNeighborhood() { //Neighborhood x1 = new Neighborhood().WithName("otto"); Does not help, because ObjectBaseFactory is used in Deserialization Neighborhood x1 = CreateObject <Neighborhood>().WithName("Nele"); Assert.IsNull(x1.FirstNeighbor); Assert.IsNull(x1.SecondNeighbor); INeighborhood x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualNeighborhood(x2, x1); }
private void searchThread(int pID, int max, int seed, INeighborhood <GraphGenome> neighborhood, bool silent = false) { Console.WriteLine("Thread {0} started...", pID); Random random = new Random(seed); // TODO: Resultaten (dus CPU computational time) opslaan in bestand. LocalSearch <GraphGenome> local_search = new LocalSearch <GraphGenome>(500, neighborhood, new GraphComparer <GraphGenome>(), random); // Dit wil ik eigenlijk static doen, maar dan komen we in de knoei met data_size. GraphGenome graph = new GraphGenome(500); graph.CreateGraph("Graph500.txt"); GraphGenome optimum = null; for (int i = 0; i < ExperimentAmount; ++i) { AssignmentTwoResults <GraphGenome> inner_results = new AssignmentTwoResults <GraphGenome>(); for (int j = 0; j < max; j++) { graph = new GraphGenome(500); graph.Generate(ref random); Stopwatch sw = Stopwatch.StartNew(); GraphGenome inner_optimum = local_search.Search(graph); sw.Stop(); inner_results.Add(inner_optimum, sw.ElapsedTicks); if (!silent) { Console.WriteLine("Found {0} in {1} ticks or {2}ms. ({3}/{4}), pID: {5}", inner_optimum.Fitness, sw.ElapsedTicks, sw.ElapsedMilliseconds, j, max, pID); } if (optimum == null || optimum.Fitness >= inner_optimum.Fitness) { optimum = inner_optimum; } } lock (solutionsThreads) { solutionsThreads[pID] = optimum; } lock (elapsedMilisecondsThreads) { elapsedMilisecondsThreads[pID].Add(inner_results); } } }
private void reportFor(INeighborhood neighborhood) { _report.AppendFormat("Neighborhood: {0}", neighborhood.Name); _report.AppendLine(); _report.AppendFormat("\t1st neighbor: {0}", _objectPathFactory.CreateAbsoluteObjectPath(neighborhood.FirstNeighbor)); _report.AppendLine(); _report.AppendFormat("\t2nd neighbor: {0}", _objectPathFactory.CreateAbsoluteObjectPath(neighborhood.SecondNeighbor)); _report.AppendLine(); reportDescription(neighborhood); _report.AppendLine(); }
public IContainer NeighborhoodMoleculeTransportContainerFor(INeighborhood neighborhood, string transportedMoleculeName, TransporterMoleculeContainer transporterMolecule, string transportName, IBuildConfiguration buildConfiguration) { var moleculeContainer = NeighborhoodMoleculeContainerFor(neighborhood, transportedMoleculeName); var transportContainer = moleculeContainer.EntityAt <IContainer>(transporterMolecule.TransportName); if (transportContainer != null) { return(transportContainer); } return(_containerTask.CreateOrRetrieveSubContainerByName(moleculeContainer, transporterMolecule.TransportName) .WithChildren(allLocalParametersFrom(transporterMolecule, buildConfiguration))); }
public void TestSimpleModelContainer() { Model x1 = CreateObject <Model>().WithName("Monica"); x1.Root = CreateObject <Container>().WithName("Root"); IContainer c1 = CreateObject <Container>().WithName("Conrad"); IContainer c2 = CreateObject <Container>().WithName("Carla"); x1.Root.Add(c1); x1.Root.Add(c2); x1.Neighborhoods = CreateObject <Container>().WithName(Constants.NEIGHBORHOODS); INeighborhood n12 = CreateObject <Neighborhood>().WithName("Nina").WithFirstNeighbor(c1).WithSecondNeighbor(c2); x1.Neighborhoods.Add(n12); Model x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualModel(x1, x2); }
public BothNeighborsSatisfyingCriteriaException(INeighborhood neighborhood) : base(Error.BothNeighborsSatisfying(neighborhood.Name)) { }
protected override void Context() { _neighborhood = A.Fake <INeighborhood>(); }
private bool neighborhoodIsEndosomalClearance(INeighborhood neighborhood) { //name of neighborhood is for instance "SmallIntestine_end_SmallIntestine_ecl" return(Regex.Matches(neighborhood.Name, @"(.*)_end_\1_ecl").Count > 0); }
private IContainer addPassiveTransportToNeighborhood(INeighborhood neighborhood, string moleculeName, ITransport transport) { return(_moleculePropertiesContainerTask.NeighborhoodMoleculeContainerFor(neighborhood, moleculeName) .WithChild(transport)); }
private AssignmentTwoResultList <GraphGenome> GeneticLocalSearch(INeighborhood <GraphGenome> neighborhood) { AssignmentTwoResultList <GraphGenome> results = new AssignmentTwoResultList <GraphGenome>("$GLS_{" + neighborhood.Name + "}$"); GraphGenome graph = new GraphGenome(500); graph.CreateGraph("Graph500.txt"); GraphGenome optimum = null; for (int i = 0; i < ExperimentAmount; ++i) { AssignmentTwoResults <GraphGenome> res = new AssignmentTwoResults <GraphGenome>(); int population_size = 50; int data_size = 500; LocalSearch <GraphGenome> local_search = new LocalSearch <GraphGenome>(data_size, neighborhood, new GraphComparer <GraphGenome>(), main_random_source); LocalSearchProcreator <GraphGenome> lsp = new LocalSearchProcreator <GraphGenome>( new UniformSymmetricCrossover <GraphGenome>(main_random_source), local_search, main_random_source, res); GeneticAlgorithm <GraphGenome> ga = new GeneticAlgorithm <GraphGenome>( data_size, lsp, new DefaultSelector <GraphGenome>( new GraphComparer <GraphGenome>()), new LocalSearchPopulationGenerator <GraphGenome>(main_random_source, local_search), new Goal(100, 0), main_random_source, "GLS"); InnerResult ir = ga.start(population_size, OptimaAmount / (population_size / 2)); // Eventueel nog een keer uitvoeren om tot 2500 optima te komen. while (res.Count < OptimaAmount) { ir = ga.start(population_size, OptimaAmount / (population_size / 2)); } // Als we er teveel hebben gekregen door de GLS run meerdere keren uit te voeren, // pak enkel hoeveel we nodig hebben. res = res.TakeFirstN(OptimaAmount); results.Add(res); if (optimum == null || res.BestResult.Optimum.Fitness < optimum.Fitness) { optimum = new GraphGenome(res.BestResult.Optimum.Data, res.BestResult.Optimum.Fitness); } } // We maken iedere keer population_size / 2 optima. // We willen OptimaAmount optima. Dus we gaan OptimaAmount / (population_size / 2) generaties uitvoeren. //IteratedLocalSearch(); optimum.ToImage(String.Format("results/GLS[{0}]-{1}.bmp", neighborhood.Name, optimum.Fitness), 3000, 3000); return(results); }
private AssignmentTwoResultList <GraphGenome> IteratedLocalSearch(INeighborhood <GraphGenome> neighborhood, bool silent = false) { LocalSearch <GraphGenome> local_search = new LocalSearch <GraphGenome>(500, neighborhood, new GraphComparer <GraphGenome>(), main_random_source); IMutation <GraphGenome> pertubation = new ILSPertubation <GraphGenome>(main_random_source); GraphGenome graph = new GraphGenome(500); graph.CreateGraph("Graph500.txt"); GraphGenome optimum = null; List <long> elapsedMilisecondsList = new List <long>(); AssignmentTwoResultList <GraphGenome> results = new AssignmentTwoResultList <GraphGenome>("$ILS_{" + neighborhood.Name + "}$"); for (int i = 0; i < ExperimentAmount; ++i) { AssignmentTwoResults <GraphGenome> res = new AssignmentTwoResults <GraphGenome>(); for (int j = 0; j < OptimaAmount; j++) { if (optimum == null) { graph = new GraphGenome(500); graph.Generate(ref main_random_source); } else { graph = pertubation.Mutate(optimum); } Stopwatch sw = Stopwatch.StartNew(); GraphGenome inner_optimum = local_search.Search(graph); sw.Stop(); elapsedMilisecondsList.Add(sw.ElapsedMilliseconds); res.Add(inner_optimum, sw.ElapsedTicks); if (!silent) { Console.WriteLine("Found {0} in {1} ticks or {2}ms. ({3}/{4})", inner_optimum.Fitness, sw.ElapsedTicks, sw.ElapsedMilliseconds, j, OptimaAmount); } if (optimum == null || optimum.Fitness >= inner_optimum.Fitness) { optimum = inner_optimum; } optimum.FunctionEvaluations = 0; } results.Add(res); } //Console.WriteLine("Best solution found: {0} in an average of {1} ms", optimum.Fitness, cpu_ticks.Average()); Console.WriteLine("Best solution found: {0} in an average of {1} ms", optimum.Fitness, elapsedMilisecondsList.Sum() / OptimaAmount); //Console.WriteLine("Total time: {0} sec", sw.ElapsedMilliseconds / 1000f); optimum.ToImage(String.Format("results/ILS[{0}]-{1}.bmp", neighborhood.Name, optimum.Fitness), 3000, 3000); //Console.ReadLine(); return(results); }
protected override void Because() { _neighborhood = sut.MapFrom(_neighborhoodBuilder, _model, _buildConfiguration, _moleculeNames, _moleculeNames); }
public World(IEnumerable <Cell <State> > cells, Bounds bounds, INeighborhood neighborhood) { Cells = cells; Bounds = bounds; Neighborhood = neighborhood; }