public Genetic(int numGenerations, int popSize, int mutationRate, int mutationFactor, Navigation nav, int numParents, int maxSteps) { numGenerations_ = numGenerations; popSize_ = popSize; numParents_ = Math.Min(numParents, popSize_); maxSteps_ = maxSteps; mutationRate_ = mutationRate; mutationFactor_ = mutationFactor; nav_ = nav; // Create the initial population pop_ = new List<Organism>(popSize_); for (int i = 0; i < popSize_; i++) { pop_.Add(new Organism(mutationFactor_)); } curGen_ = 0; curOrg_ = 0; curStep_ = 0; changedOrg_ = true; }
// This function is called from the motion planner. It is // used to check for collisions between an edge between // nodes n1 and n2, and a wall segment. // The function uses an iterative approach by moving along // the edge a "safe" distance, defined to be the shortest distance // to the wall segment, until the end of the edge is reached or // a collision occurs. public bool CollisionFound(Navigation.Node n1, Navigation.Node n2, double tol) { // Check that within boundaries if (n2.x > maxWorkspaceX || n2.x < minWorkspaceX || n2.y > maxWorkspaceY || n2.y < minWorkspaceY) return true; // Check for collision with walls double theta = Math.Atan2(n2.y - n1.y, n2.x - n1.x); double edgeSize = Math.Sqrt(Math.Pow(n2.y - n1.y, 2) + Math.Pow(n2.x - n1.x, 2)); double sinTheta = Math.Sin(theta); double cosTheta = Math.Cos(theta); // Loop through segments for (int segment = 0; segment < numMapSegments; segment++) { double distTravelledOnEdge = 0; double ex = n1.x, ey = n1.y; double distToSegment; while (distTravelledOnEdge - tol < edgeSize) { distToSegment = GetWallDistance(ex, ey, segment, tol, n2.x, n2.y); if (distToSegment - tol < 0.05) return true; ex += cosTheta * distToSegment; ey += sinTheta * distToSegment; distTravelledOnEdge += distToSegment; } } return false; }
public JaguarCtrl() { simulatedJaguar = new AxDDrRobotSentinel_Simulator(); navigation = new Navigation(this); drRobotConnect = new DrRobotRobotConnection(this); drRobotConnect.connectRobot(); robotCfg = drRobotConnect.robotConfig; jaguarSetting = (RobotConfig.RobotConfigTableRow)robotCfg.RobotConfigTable.Rows[0]; InitializeComponent(); // Setup graphics for simulation SetStyle(ControlStyles.OptimizedDoubleBuffer, false); this.Paint += new System.Windows.Forms.PaintEventHandler(this.JaguarCtrl_Paint); panelGE.Visible = false; mapResolution = trackBarZoom.Value * zoomConstant; // Start Simulated Sensor Update Thread runSensorThread = true; sensorThread = new Thread(runSensorLoop); sensorThread.Start(); }