Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cost Opimization #29

Merged
merged 17 commits into from
Aug 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Config file can be changed without rebuilding, allowing for iterative…
… testing
walkeri committed Aug 15, 2018
commit c06960c54f42bfd7e28fcdda6b720e33e7b919a0
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ message(WARNING ${LIBRARIES})

# Add the sources to the executables
add_library(Routes STATIC ${HS}
${SOURCES})
${SOURCES} src/routes-lib/configure/configure.cpp src/routes-lib/configure/configure.h)

IF (WIN32)

@@ -80,7 +80,7 @@ FILE(GLOB_RECURSE HS ${CMAKE_SOURCE_DIR}/src/routes-exec/*.h*)
FILE(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/routes-exec/*.cpp)

add_executable(Routes-Exec ${HS}
${SOURCES})
${SOURCES} src/routes-lib/configure/configure.cpp src/routes-lib/configure/configure.h)

add_dependencies(Routes-Exec Routes)

@@ -112,7 +112,7 @@ FILE(GLOB_RECURSE HS ${CMAKE_SOURCE_DIR}/src/routes-server/*.h*)
FILE(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/routes-server/*.cpp)

add_executable(Routes-Server ${HS}
${SOURCES})
${SOURCES} src/routes-lib/configure/configure.cpp src/routes-lib/configure/configure.h)

add_dependencies(Routes-Server Routes)

@@ -146,7 +146,7 @@ FILE(GLOB_RECURSE HS ${CMAKE_SOURCE_DIR}/src/routes-tests/*.h*)
FILE(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/routes-tests/*.cpp)

add_executable(Routes-Tests ${HS}
${SOURCES})
${SOURCES} src/routes-lib/configure/configure.cpp src/routes-lib/configure/configure.h)

add_dependencies(Routes-Tests Routes)

17 changes: 17 additions & 0 deletions params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"reload": 0,

"routes": {
"population-size": 1000,
"num-generations": 300
},

"population": {
"initial-sigma-divisor": 10.0,
"initial-sigma-xy": 2500.0,
"step-dampening": 0.75,
"alpha": 1.5,
"num-sample-threads": 10,
"num-route-workers": 100
}
}
77 changes: 77 additions & 0 deletions src/routes-lib/configure/configure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Created by isaac on 8/14/18.
//

#include "configure.h"

Configuration Configure::_config;

Configure::Configure() {

loadConfig();

}

void Configure::loadConfig() {


boost::property_tree::ptree root;

boost::property_tree::read_json(FILE_PATH, root);

// if 0, then reload, if 1 then don't
int reload = root.get<int>("reload", 0);

int population_size = root.get<int>("routes.population-size", 0);
int num_generations = root.get<int>("routes.num-generations", 0);
float initial_sigma_divisor = root.get<float>("population.initial-sigma-divisor", 0);
float initial_sigma_xy = root.get<float>("population.initial-sigma-xy", 0);
float step_dampening = root.get<float>("population.step-dampening", 0);
float alpha = root.get<float>("population.alpha", 0);
int num_sample_threads = root.get<int>("population.num-sample-threads", 0);
int num_route_workers = root.get<int>("population.num-route-workers", 0);

_config = {reload, population_size, num_generations,
initial_sigma_divisor, initial_sigma_xy,
step_dampening, alpha, num_sample_threads, num_route_workers};



}

int Configure::getReload() {
return _config.reload;
}

int Configure::getPopulationSize() {
return _config.population_size;
}

int Configure::getNumGenerations() {
return _config.num_generations;
}

float Configure::getInitialSigmaDivisor() {
return _config.initial_sigma_divisor;
}

float Configure::getInitialSigmaXY() {
return _config.initial_sigma_xy;
}

float Configure::getStepDampening() {
return _config.step_dampening;
}

float Configure::getAlpha() {
return _config.alpha;
}

int Configure::getNumSampleThreads() {
return _config.num_sample_threads;
}

int Configure::getNumRouteWorkers() {
return _config.num_route_workers;
}

176 changes: 176 additions & 0 deletions src/routes-lib/configure/configure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//
// Created by isaac on 8/14/18.
//

#ifndef ROUTES_CONFIGURE_H
#define ROUTES_CONFIGURE_H

#ifdef _MSC_VER
#include <boost/config/compiler/visualc.hpp>
#endif
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <cassert>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>

#define FILE_PATH "../params.json"


#endif //ROUTES_CONFIGURE_H

/**
* A struct for representing the parameter information.
*/
struct Configuration {

/**
* This is 0 if the data should be reloaded, and 1 if not
*/
int reload;

/**
* The default size of the population for calculating a route
*/
int population_size;

/**
* The default number of generations that the population should be bred
*/
int num_generations;

/**
* This value is used to help calculate the initial step size of the population.
* and the Z sigma is the max elevation delta / INITIAL_SIGMA_DIVISOR.
*/
float initial_sigma_divisor;

/**
* This serves as the initial value for the X and Y of all the points for sigma.
* We use 5km as a pretty tight bounding around the straight line (initial mean)
*/
float initial_sigma_xy;

/**
* Represents the dampening parameter for the step size. This value should be close to 1
*/
float step_dampening;

/**
* The interval multiplier for the square root of _genome_size * 3 for the indicator function.
*/
float alpha;

/**
* The number of threads that are used to sample from the multivariate normal distribution
*/
int num_sample_threads;

/**
* The number of divisions that the route is split up into for evaluation on the GPU
*/
int num_route_workers;


};

class Configure {

public:

/**
* Construct the configuration for this run.
*/
Configure();

/**
* Gets the reload flag
*
* @return
* returns the reload flag
*/
int getReload();

/**
* Gets the population size
*
* @return
* returns the population size
*
*/
int getPopulationSize();

/**
* Gets the number of generations
*
* @return
* returns the number of generations
*/
int getNumGenerations();

/**
* Gets the initial Sigma Divisor for calculating the step size
*
* @return
* returns the initial sigma divisor
*/
float getInitialSigmaDivisor();

/**
* Gets the initial sigma for calculating the initial X and Y values for sigma
*
* @return
* returns the initial sigma xy
*/
float getInitialSigmaXY();

/**
* Gets the dampening parameter for step size
*
* @return
* returns the step dampening parameter
*/
static float getStepDampening();

/**
* Gets the interval multiplier for the indicator function
*
* @return
* returns alpha
*/
float getAlpha();

/**
* Gets the number of threads for sampling the multivariate normal distribution
*
* @return
* returns the number of sample threads
*/
int getNumSampleThreads();

/**
* Gets the number of workers for GPU eval
*
* @return
* returns the number of route workers
*/
int getNumRouteWorkers();

private:

/**
* Loads the params json file
*/
void loadConfig();

/**
* The loaded configuration
*/
static Configuration _config;

};


Loading