diff --git a/config/CarConfig.h b/config/CarConfig.h index f268d0a..d5bde16 100644 --- a/config/CarConfig.h +++ b/config/CarConfig.h @@ -2,8 +2,8 @@ * @brief This file contains all the constant values for the car class. * * @file CarConfig.h - * @author Mateusz Krakowski - * @date 2023-06-06 + * @authors Mateusz Krakowski, Jakub Marcowski + * @date 2023-06-07 */ #ifndef CARCONFIG_H @@ -11,15 +11,21 @@ class CarConfig { public: - - // Car speed is dependent on the car's torque + // Car speed is dependent on the car's torque static constexpr float CAR_TORQUE = 2000.0f; - - + static constexpr float MAX_JOINT_LENGTH = 0.01f; // Number of vertices in a car's body polygon static constexpr int CAR_VERTICES = 8; + // F = V^2 * k + // k ≈ 1/2 * ρ * A * C_d ≈ 3.4 + // ρ = 1.293 kg/m^3 + // A = ? (let's assume 5 m^2) + // C_d = ? (let's assume 1.05) + // + // F = 3.4 * V^2 + static constexpr float AIR_RES_FACTOR = 3.4f; }; #endif // CARCONFIG_H diff --git a/config/Config.h b/config/Config.h index ec216e5..f1c2546 100644 --- a/config/Config.h +++ b/config/Config.h @@ -3,7 +3,7 @@ * * @file Config.h * @authors Jakub Marcowski, Mateusz Krakowski - * @date 2023-06-06 + * @date 2023-06-07 */ #ifndef CONFIG_H @@ -16,7 +16,7 @@ class Config { // 60 for real time, 120 for fast forward - anything else is undefined behaviour static constexpr int MAX_FPS = 60; - + static constexpr int GROUND_PARTS_RENDERED = 32; // Exporting to file diff --git a/config/EvolutionaryAlgorithmConfig.h b/config/EvolutionaryAlgorithmConfig.h index 145ea7f..8a45eef 100644 --- a/config/EvolutionaryAlgorithmConfig.h +++ b/config/EvolutionaryAlgorithmConfig.h @@ -3,7 +3,7 @@ * * @file EvolutionaryAlgorithmConfig.h * @author Mateusz Krakowski - * @date 2023-06-06 + * @date 2023-06-07 */ #ifndef EVOLUTIONARY_ALGORITHM_CONFIG_H @@ -12,9 +12,11 @@ class EvolutionaryAlgorithmConfig { public: // Evolutionary algorithm parameters - static constexpr int POPULATION_SIZE = 15; + + static constexpr int POPULATION_SIZE = 16; // Boundaries for the chromosomes + static constexpr float MIN_BODY_LENGTH = 1.0f; static constexpr float MAX_BODY_LENGTH = 5.0f; @@ -28,6 +30,7 @@ class EvolutionaryAlgorithmConfig { static constexpr float MAX_WHEEL_DENSITY = 1000.0f; // Population initialization hyper parameters + static constexpr float INITIAL_BODY_LENGTH_MEAN = 3.0f; static constexpr float INITIAL_BODY_LENGTH_VARIANCE = 1.0f; @@ -55,6 +58,7 @@ class EvolutionaryAlgorithmConfig { static constexpr float MUTATION_FACTOR_WHEEL_DENSITY = 20.0f; // Selection hyper parameters + static constexpr int TOURNAMENT_SIZE = 3; // Has to be equal to or lesser than POPULATION_SIZE }; diff --git a/config/MapGenConfig.h b/config/MapGenConfig.h index 6342dae..88cc605 100644 --- a/config/MapGenConfig.h +++ b/config/MapGenConfig.h @@ -3,7 +3,7 @@ * * @file MapGenConfig.h * @author Mateusz Krakowski - * @date 2023-06-06 + * @date 2023-06-07 */ #ifndef MAPGENCONFIG_H @@ -22,10 +22,9 @@ class MapGenConfig { static constexpr float CAR_STARTING_Y = 650.0; // Change the mapgen behaviour here + static constexpr float GROUND_DEGREE_DEVIATION = 12.0f; static constexpr float MAX_GROUND_DEGREE = 50.0f; - - }; #endif // MAPGENCONFIG_H diff --git a/docs/docs_by_doxygen.pdf b/docs/docs_by_doxygen.pdf index 4797e23..1ace08a 100644 Binary files a/docs/docs_by_doxygen.pdf and b/docs/docs_by_doxygen.pdf differ diff --git a/src/Car.cc b/src/Car.cc index c032214..0767a11 100644 --- a/src/Car.cc +++ b/src/Car.cc @@ -4,7 +4,7 @@ * * @file Car.cc * @authors Jakub Marcowski, Mateusz Krakowski - * @date 2023-06-06 + * @date 2023-06-07 */ #include "Car.h" @@ -97,13 +97,13 @@ std::vector createVertices(std::vector lengths) { std::vector angles; angles.reserve(lengths.size()); - for (int i = 0; i < lengths.size(); i++) { + for (int i = 0; i < lengths.size(); ++i) { angles.push_back(360.0f / lengths.size()); } // so that the wheels are set properly (that is - parallel to the ground) float angle = ((180.0f + (angles.back() / 2)) / 180.0f) * Config::PI; - for (int i = 0; i < lengths.size(); i++) { + for (int i = 0; i < lengths.size(); ++i) { vertices.emplace_back(lengths[i] * cos(angle), lengths[i] * sin(angle)); angle += (angles[i] / 180.0f) * Config::PI; } diff --git a/src/GUI.cc b/src/GUI.cc index cf82eac..2fde11f 100644 --- a/src/GUI.cc +++ b/src/GUI.cc @@ -3,7 +3,7 @@ * * @file GUI.cc * @author Jakub Marcowski - * @date 2023-06-06 + * @date 2023-06-07 */ #include "GUI.h" @@ -14,9 +14,6 @@ void renderVelocityPlot(std::vector& cars, bool paused) { if (ImPlot::BeginPlot("Velocity")) { ImPlot::SetupLegend(ImPlotLocation_West, ImPlotLegendFlags_Outside); for (int i = 0; i < cars.size(); ++i) { - char i_str[11]; // 10 digits + null - sprintf(i_str, "%d", i); - if (!paused) { cars[i].getVelX()->push_back(cars[i].getVelX()->back() + 1); cars[i].getVelY()->push_back(cars[i].getVelocity()); @@ -26,7 +23,7 @@ void renderVelocityPlot(std::vector& cars, bool paused) { std::vector v_values_crop = std::vector( cars[i].getVelY()->end() - Config::VELOCITY_ARRAY_SIZE, cars[i].getVelY()->end()); ImPlot::PushStyleColor(ImPlotCol_Line, SFMLColorToImVec4(cars[i].getBodyColor())); - ImPlot::PlotLine(i_str, &(v_axis_crop[0]), &(v_values_crop[0]), + ImPlot::PlotLine(std::to_string(i).c_str(), &(v_axis_crop[0]), &(v_values_crop[0]), Config::VELOCITY_ARRAY_SIZE); ImPlot::PopStyleColor(); } @@ -41,9 +38,6 @@ void renderPositionPlot(std::vector& cars, bool paused) { if (ImPlot::BeginPlot("Position")) { ImPlot::SetupLegend(ImPlotLocation_West, ImPlotLegendFlags_Outside); for (int i = 0; i < cars.size(); ++i) { - char i_str[11]; - sprintf(i_str, "%d", i); - if (!paused) { cars[i].getPosXVec()->push_back(cars[i].getPosXVec()->back() + 1); cars[i].getPosYVec()->push_back(cars[i].getBody()->body->GetPosition().x); @@ -55,7 +49,7 @@ void renderPositionPlot(std::vector& cars, bool paused) { std::vector(cars[i].getPosYVec()->end() - Config::VELOCITY_ARRAY_SIZE, cars[i].getPosYVec()->end()); ImPlot::PushStyleColor(ImPlotCol_Line, SFMLColorToImVec4(cars[i].getBodyColor())); - ImPlot::PlotLine(i_str, &(v_axis_crop[0]), &(v_values_crop[0]), + ImPlot::PlotLine(std::to_string(i).c_str(), &(v_axis_crop[0]), &(v_values_crop[0]), Config::VELOCITY_ARRAY_SIZE); ImPlot::PopStyleColor(); } diff --git a/src/Utility.cc b/src/Utility.cc index 0f32646..9190fe4 100644 --- a/src/Utility.cc +++ b/src/Utility.cc @@ -3,7 +3,7 @@ * * @file Utility.cc * @authors Jakub Marcowski, Mateusz Krakowski - * @date 2023-06-06 + * @date 2023-06-07 */ #include "Utility.h" @@ -17,9 +17,9 @@ void applyAirResistance(Car car) { // // F = 3.4 * V^2 car.getBody()->body->ApplyForceToCenter( - b2Vec2(-1.84 * car.getBody()->body->GetLinearVelocity().x * + b2Vec2(-sqrt(CarConfig::AIR_RES_FACTOR) * car.getBody()->body->GetLinearVelocity().x * abs(car.getBody()->body->GetLinearVelocity().x), - -1.84 * car.getBody()->body->GetLinearVelocity().y * + -sqrt(CarConfig::AIR_RES_FACTOR) * car.getBody()->body->GetLinearVelocity().y * abs(car.getBody()->body->GetLinearVelocity().y)), true); } diff --git a/src/Utility.h b/src/Utility.h index ce97133..28f8852 100644 --- a/src/Utility.h +++ b/src/Utility.h @@ -3,7 +3,7 @@ * * @file Utility.h * @authors Jakub Marcowski, Mateusz Krakowski - * @date 2023-06-06 + * @date 2023-06-07 */ #ifndef UTILITY_H @@ -19,6 +19,7 @@ #include "SFML/Graphics.hpp" #include "EvolutionaryAlgorithm.h" +#include "../config/CarConfig.h" #include "../config/Config.h" #include "../config/MapGenConfig.h" #include "Car.h"