public double CalculateScore(IMLMethod network) { var pilot = new NeuralRobot((BasicNetwork)network, false, RobotContol.SourceLocation, RobotContol.DestLocation); int score = pilot.ScorePilot(); //RobotContol.Scores.Add(score); return score; }
public void RunNetwork(Guid id) { BasicNetwork network = null; var fn = id.ToString(); var net = DataService.GetCollectionQueryModel<NeuralNetwork>(Query.EQ("_id", id)).FirstOrDefault(); if (net != null) { SourceLocation = new Position(net.StartPosition.X, net.StartPosition.Y); DestLocation = new Position(net.EndPosition.X, net.EndPosition.Y); lock (RobotContol.NetworkLock) { var rawbytes = DataService.OpenFile(id); File.WriteAllBytes(fn, rawbytes); network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(new FileInfo(fn)); } var pilot = new NeuralRobot(network, true, SourceLocation, DestLocation); SourceData.Simulation = pilot.sim; DataContext = SourceData; DrawMap(); SourceData.Simulation.PositionChanged += Simulation_PositionChanged; pilot.ScorePilot(); File.Delete(fn); } DoEvents(); }
private void BuildNetwork(double slat, double slon, double lat, double lon) { BasicNetwork network = null; var nn = Mds.GetCollectionQueryModel<NeuralNetwork>(Query.And(Query.EQ("StartPosition.X", slat), Query.EQ("StartPosition.Y", slon), Query.EQ("EndPosition.X", lat), Query.EQ("EndPosition.Y", lon))) .FirstOrDefault(); var tsk = Mds.GetCollectionQueryModel<RoverTask>( Query.And(Query.EQ("TrainingProperties.StartPosition.StartPosition.X", slat), Query.EQ("TrainingProperties.StartPosition.StartPosition.Y", slon), Query.EQ("TrainingProperties.StartPosition.EndPosition.X", lat), Query.EQ("TrainingProperties.StartPosition.EndPosition.Y", lon))).FirstOrDefault(); if (tsk != null && nn == null) return; if (nn == null && tsk == null) { var t = new TaskMessage { LogReportingLevel = LogLevel.Verbatium, MessageId = Guid.NewGuid(), ScriptType = TaskScriptType.LoadWorker, TaskScript = new RoverWorker().GetType().ToString(), TransmisionDateTime = DateTime.Now, TaskId = Guid.NewGuid() }; var col = Mds.DataBase.GetCollection<RoverTask>("RoverTask"); var task = new RoverTask { Status = (TaskTransport.TaskStatus) TaskStatus.Pending, TaskType = RoverTaskType.Train, Id = t.TaskId, TrainingProperties = new RoverTrainProperties { Id = Guid.NewGuid(), StartPosition = new Position(slat, slon), DestinationPosition = new Position(lat, lon) } }; col.Save(task); var q = new MessageQueue<TaskMessage>(false, _Connection); var x = 0; while (x != 10) { Thread.Sleep(10); DoEvents(); x++; } q.Publish(t); DoEvents(); } else { var fn = nn.Id.ToString(); lock (RobotContol.NetworkLock) { var rawbytes = Mds.OpenFile(nn.Id); File.WriteAllBytes(fn, rawbytes); network = (BasicNetwork) EncogDirectoryPersistence.LoadObject(new FileInfo(fn)); } var pilot = new NeuralRobot(network, true, SourceLocation, DestLocation); SourceData.Simulation = pilot.sim; DataContext = SourceData; DrawMap(); SourceData.Simulation.PositionChanged += Simulation_PositionChanged; pilot.ScorePilot(); File.Delete(fn); } }