Commit ab01c16d authored by Bruno Meyer's avatar Bruno Meyer 😢

Copy files from original project

parent 13a9aeb5
binario.txt
output.txt
current.yaml
CMakeCache.txt
cmake_install.cmake
CMakeFiles
ensalador
schedules.yaml
rooms.yaml
Makefile
\ No newline at end of file
# Common variables.
cmake_minimum_required (VERSION 2.8)
project (munkres-cpp)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -ggdb3 -DDEBUG")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include )
#include_directories( ${PROJECT_SOURCE_DIR}/src )
# Example
add_executable (ensalador src/main.cpp src/database.cpp src/ensalador.cpp src/rooms.cpp)
target_link_libraries (ensalador munkres yaml-cpp)
install (TARGETS ensalador DESTINATION bin)
This diff is collapsed.
This diff is collapsed.
# Common variables.
add_subdirectory (tools/generator)
add_subdirectory (tests)
# Common variable.
include_directories (${PROJECT_SOURCE_DIR}/benchmarks/tools/generator)
# Benchmark based on the Google benchmark Framework.
ExternalProject_Add (
benchmark
GIT_REPOSITORY "https://github.com/google/benchmark.git"
CMAKE_ARGS "-DBENCHMARK_ENABLE_TESTING=OFF;-DCMAKE_BUILD_TYPE=Release"
SOURCE_DIR "${PROJECT_BINARY_DIR}/benchmark"
BINARY_DIR "${PROJECT_BINARY_DIR}/benchmark"
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set_target_properties (benchmark PROPERTIES EXCLUDE_FROM_ALL TRUE)
set (GBENCHMARK_FOUND true)
set (GBENCHMARK_INCLUDE_DIR "${PROJECT_BINARY_DIR}/benchmark/include")
set (GBENCHMARK_LIBRARY "${PROJECT_BINARY_DIR}/benchmark/src/libbenchmark.a")
set (MunkresCppBenchmarkGoogle_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main_google.cpp)
add_executable (munkresbenchmark_google.bin EXCLUDE_FROM_ALL ${MunkresCppBenchmarkGoogle_SOURCES})
include_directories (${GBENCHMARK_INCLUDE_DIR})
target_link_libraries (munkresbenchmark_google.bin munkres ${GBENCHMARK_LIBRARY} pthread)
add_dependencies (munkresbenchmark_google.bin benchmark)
# Benchmark based on the hayai Framework.
ExternalProject_Add (
hayai
GIT_REPOSITORY "https://github.com/nickbruun/hayai.git"
SOURCE_DIR "${PROJECT_BINARY_DIR}/hayai"
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set_target_properties (hayai PROPERTIES EXCLUDE_FROM_ALL TRUE)
set (HAYAI_FOUND true)
set (HAYAI_INCLUDE_DIR "${PROJECT_BINARY_DIR}/hayai/src")
set (MunkresCppBenchmarkHayai_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main_hayai.cpp)
add_executable (munkresbenchmark_hayai.bin EXCLUDE_FROM_ALL ${MunkresCppBenchmarkHayai_SOURCES})
include_directories (${HAYAI_INCLUDE_DIR})
target_link_libraries (munkresbenchmark_hayai.bin munkres)
add_dependencies (munkresbenchmark_hayai.bin hayai)
# Benchmark based on the Celero Framework.
ExternalProject_Add (
Celero
GIT_REPOSITORY "https://github.com/DigitalInBlue/Celero.git"
CMAKE_ARGS "-DCELERO_ENABLE_EXPERIMENTS=OFF;-DCMAKE_BUILD_TYPE=Release"
SOURCE_DIR "${PROJECT_BINARY_DIR}/Celero"
BINARY_DIR "${PROJECT_BINARY_DIR}/CeleroBuild"
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set_target_properties (Celero PROPERTIES EXCLUDE_FROM_ALL TRUE)
set (CELERO_FOUND true)
set (CELERO_INCLUDE_DIR "${PROJECT_BINARY_DIR}/Celero/include")
set (CELERO_LIBRARY "${PROJECT_BINARY_DIR}/CeleroBuild/libcelero.so")
set (MunkresCppBenchmarkCelero_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main_celero.cpp)
add_executable (munkresbenchmark_celero.bin EXCLUDE_FROM_ALL ${MunkresCppBenchmarkCelero_SOURCES})
include_directories (${CELERO_INCLUDE_DIR})
target_link_libraries (munkresbenchmark_celero.bin munkres ${CELERO_LIBRARY})
add_dependencies (munkresbenchmark_celero.bin Celero)
# Benchmark based on the RDTSC.
set (MunkresCppBenchmarkRdtsc_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main_rdtsc.cpp)
add_executable (munkresbenchmark_rdtsc.bin EXCLUDE_FROM_ALL ${MunkresCppBenchmarkRdtsc_SOURCES})
target_link_libraries (munkresbenchmark_rdtsc.bin munkres)
# Test for generate profiler (gprof) data.
set (MunkresCppBenchmarkGprof_SOURCES
${PROJECT_SOURCE_DIR}/src/munkres.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main_gprof.cpp
)
add_executable (munkresbenchmark_gprof.bin EXCLUDE_FROM_ALL ${MunkresCppBenchmarkGprof_SOURCES})
set_target_properties (munkresbenchmark_gprof.bin PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -pg" LINK_FLAGS "-pg")
# Prevent launch tests before will be generated test data set.
set (BenchmarkDataSet ${PROJECT_BINARY_DIR}/matrices.txt)
add_custom_command (
OUTPUT ${BenchmarkDataSet}
COMMAND cd ${PROJECT_BINARY_DIR} && ./benchmarks/tools/generator/matrixgenerator.bin 20
)
add_custom_target (generate_benchmark_dataset DEPENDS ${BenchmarkDataSet})
add_dependencies (generate_benchmark_dataset matrixgenerator.bin)
add_dependencies (munkresbenchmark_google.bin generate_benchmark_dataset)
add_dependencies (munkresbenchmark_hayai.bin generate_benchmark_dataset)
add_dependencies (munkresbenchmark_celero.bin generate_benchmark_dataset)
add_dependencies (munkresbenchmark_rdtsc.bin generate_benchmark_dataset)
add_dependencies (munkresbenchmark_gprof.bin generate_benchmark_dataset)
add_custom_target (benchmarks)
add_dependencies (
benchmarks
munkresbenchmark_google.bin
munkresbenchmark_celero.bin
munkresbenchmark_hayai.bin
munkresbenchmark_rdtsc.bin
munkresbenchmark_gprof.bin
matrixgenerator.bin
)
#include <celero/Celero.h>
#include <vector>
#include "matrixutils.h"
#include "munkres.h"
std::vector <Matrix <double> *> matrices;
size_t i {0};
class MunkresFixture : public celero::TestFixture
{
public:
void setUp (int64_t) override
{
matrix = * matrices [i];
}
Munkres munkres;
Matrix <double> matrix;
};
BASELINE_F (Munkres, Solve, MunkresFixture, 5000, 1)
{
munkres.solve (matrix);
}
BENCHMARK_F (Munkres, Solve, MunkresFixture, 5000, 1)
{
munkres.solve (matrix);
}
// Main function.
int main (int argc, char * argv [])
{
read <double> (matrices);
for (const auto x : matrices) {
celero::Run (argc, argv);
++i;
}
}
#include <benchmark/benchmark.h>
//#include <gtest/gtest.h>
#include <vector>
#include "matrixutils.h"
#include "munkres.h"
std::vector <Matrix <double> *> matrices;
constexpr int maxReasonableDataSetCount {100};
static void BM_solve (benchmark::State & state)
{
state.PauseTiming ();
if (state.range_x () < matrices.size () ) {
Munkres munkres;
while (state.KeepRunning () ) {
auto matrix = * matrices [state.range_x ()];
state.ResumeTiming ();
munkres.solve (matrix);
state.PauseTiming ();
}
}
}
BENCHMARK (BM_solve)->DenseRange (0, maxReasonableDataSetCount);
// Main function.
int main (int argc, char * argv [])
{
read <double> (matrices);
benchmark::Initialize (& argc, const_cast <const char **> (argv) );
benchmark::RunSpecifiedBenchmarks ();
}
#include <vector>
#include "matrixutils.h"
#include "munkres.h"
// Main function.
int main (int argc, char * argv [])
{
std::vector <Matrix <double> *> matrices;
read <double> (matrices);
for (size_t i = 0; i < matrices.size (); ++i) {
std::cout << "Test case " << i + 1 << " from " << matrices.size () << std::endl;
Munkres munkres;
auto matrix = * matrices [i];
munkres.solve (matrix);
}
}
#include <hayai.hpp>
#include <vector>
#include "matrixutils.h"
#include "munkres.h"
std::vector <Matrix <double> *> matrices;
size_t i {0};
class MunkresFixture : public ::hayai::Fixture
{
public:
void SetUp () override
{
matrix = * matrices [i];
}
Munkres munkres;
Matrix <double> matrix;
};
BENCHMARK_F (MunkresFixture, Solve, 5000, 1)
{
munkres.solve (matrix);
}
// Main function.
int main (int argc, char * argv [])
{
read <double> (matrices);
hayai::ConsoleOutputter consoleOutputter;
hayai::Benchmarker::AddOutputter (consoleOutputter);
for (const auto x : matrices) {
hayai::Benchmarker::RunAllTests ();
++i;
}
}
//#include <gtest/gtest.h>
#include <vector>
#include <limits>
#include <string>
#include "matrixutils.h"
#include "munkres.h"
// Main function.
int main (int argc, char * argv [])
{
std::vector <Matrix <double> *> matrices;
read <double> (matrices);
size_t iterations = 1000;
size_t runs = 10;
if (3 == argc) {
runs = std::stoi (argv [1]);
iterations = std::stoi (argv [2]);
}
std::cout << "Prepare to launch " << runs << " runs with " << iterations << " iterations each." << std::endl;
for (size_t i = 0; i < matrices.size (); ++i) {
std::cout << "Test case " << i + 1 << " from " << matrices.size () << std::endl;
uint64_t rdtscMin = std::numeric_limits <uint64_t>::max ();
for (size_t j = 0; j < runs; ++j) {
uint64_t rdtscMinRun = std::numeric_limits <uint64_t>::max ();
for (size_t k = 0; k < iterations; ++k) {
Munkres munkres;
auto matrix = * matrices [i];
uint64_t rdtsc = __rdtsc ();
munkres.solve (matrix);
rdtsc = __rdtsc () - rdtsc;
rdtscMinRun = std::min (rdtscMinRun, rdtsc);
}
std::cout << "Run " << std::setw (4) << j << ": " << rdtscMinRun << std::endl;
rdtscMin = std::min (rdtscMin, rdtscMinRun);
}
std::cout << "The best: " << rdtscMin << std::endl;
}
}
# Data generator.
set (MunkresCppMatrixGenerator_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
include_directories (${PROJECT_SOURCE_DIR}/benchmarks/tools/generator)
add_executable (matrixgenerator.bin EXCLUDE_FROM_ALL ${MunkresCppMatrixGenerator_SOURCES})
#include <cstdlib>
#include "matrixutils.h"
#include <string>
int main (int argc, char * argv [])
{
std::vector <Matrix <double> *> matrices;
for (int i = 1; i < argc; ++i) {
const size_t size = std::stoi (argv [i]);
Matrix <double> * matrix = new Matrix <double>;
* matrix = generate_random_matrix <double> (size, size);
matrices.push_back (matrix);
}
write <double> (matrices);
return EXIT_SUCCESS;
}
#if !defined(_MATRIX_UTILS_H_)
#define _MATRIX_UTILS_H_
#include "matrix.h"
#include <fstream>
#include <random>
#include <limits>
#include <iostream>
#include <iomanip>
const std::string fileName = "matrices.txt";
template <class T>
std::ostream & operator << (std::ostream & os, const Matrix <T> & m)
{
const std::string indent (" ");
os << "Matrix (" << & m << ") of " << m.rows () << "x" << m.columns () << std::endl;
for (unsigned int row = 0; row < m.rows (); ++row) {
os << indent;
for (unsigned int col = 0; col < m.columns (); ++col) {
os << std::setw (4) << std::setfill (' ') << m (row, col) << " ";
}
os << std::endl;
}
return os;
}
template <class T>
std::istream & operator >> (std::istream & is, Matrix <T> & m)
{
std::string marker;
is >> marker;
if ("Matrix" == marker) {
std::string unused;
std::string size;
is >> unused;
is >> unused;
is >> size;
const size_t delimiter = size.find ("x");
if (std::string::npos != delimiter) {
const size_t rows = stoi (size.substr (0, delimiter) );
const size_t columns = stoi (size.substr (delimiter + 1) );
if (rows && columns) {
m.resize (rows, columns);
for (size_t row = 0; row < rows; ++row) {
for (size_t col = 0; col < columns; ++col) {
is >> m (row, col);
}
}
}
}
}
return is;
}
template <typename T>
bool write (const std::vector <Matrix <T> *> & matrices)
{
std::fstream os;
os.open (fileName, std::fstream::out/* | std::fstream::binary*/);
for (size_t i = 0; i < matrices.size (); ++i) {
os << * matrices [i];
}
os.close ();
return true;
}
template <typename T>
bool read (std::vector <Matrix <T> *> & matrices)
{
std::fstream is;
is.open (fileName, std::fstream::in/* | std::fstream::binary*/);
Matrix <T> * matrix = new Matrix <T>;
while (is >> * matrix) {
matrices.push_back (matrix);
matrix = new Matrix <T>;
}
delete matrix;
is.close ();
return true;
}
template <typename T>
Matrix<double> generate_random_matrix (const size_t nrows, const size_t ncols)
{
Matrix<T> matrix(nrows, ncols);
// Prepare random generator.
std::default_random_engine generator;
std::uniform_real_distribution<double> distribution (0.0, std::numeric_limits<double>::max () );
// Initialize matrix with random values.
for ( size_t row = 0 ; row < matrix.rows() ; row++ ) {
for ( size_t col = 0 ; col < matrix.columns() ; col++ ) {
matrix(row,col) = distribution (generator);
}
}
return matrix;
}
#endif /* !defined(_MATRIX_UTILS_H_) */
This source diff could not be displayed because it is too large. You can view the blob instead.
const async = require('async');
const { exec } = require('child_process');
const fs = require('fs');
const yaml = require('js-yaml');
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
class EnsaladorPart{
/**
* @param {String} name The name of the part (does not affect the flow)
* @param {String} operation Operation used on ensalador binary
* run "./ensalador" to se the options
* @param {Object} option (Optional) Specify the options of "operation"
*/
constructor(name, operation, option){
this.name = name;
this.operation = operation;
this.option = option;
}
optionToString(){
// If there is no option, add an empty string
if(this.option == {} || this.option == undefined) return "";
// Otherwise, parse the Object to an json without quotes and spacement
// equal to 1. The spacement is necessary because the ensalador binary
// break
return "\""+JSON.stringify(this.option,null,1).replaceAll("\"","")+"\"";
}
toStringCommand(){
return this.operation.toString()+" "+ this.optionToString();
}
}
class Ensalador{
/**
* @param {EnsaladorPart[]} parts Pipeline of ensalador binary execution
*/
constructor(parts){
this.parts = parts;
this.command = './ensalador';
this.create_log = false;
}
/**
* Execute the ensalador binary with the parts specified on constructor
*/
execute(cb){
// Create the functions that will be called on async.waterfall
// waterfall loses the context of this instance, then we use
// .bind feature to attach the actual context
var partsExec = this.parts.map(part =>{
return async.apply(this.executePart.bind(this), part);
});
async.waterfall(
partsExec,
function(err) {
var doc = yaml.safeLoad(fs.readFileSync('current.yaml', 'utf8'));
cb(err, doc.schedules);
}
);
}
// Execute an specific part of Ensalador
executePart(part, cb){
this.runProcessSystem(
this.command+" "+part.toStringCommand(),
cb
);
}
// Run an command on system as a different process
runProcessSystem(command, cb){
exec(command, (error, stdout, stderr) => {
if (error){
if(this.create_log) console.error(`exec error: ${error}`);
return;
}
if(this.create_log) console.log(`stdout: ${stdout}`);
if(this.create_log) console.log(`stderr: ${stderr}`);
cb();
});
}
}
// Heuristics used to set the order of scheduler
parts = [
new EnsaladorPart("Open", "open"),
new EnsaladorPart("CT", "exec",{day: [2,3,4,5,6,7], block: ["ct"]}),
new EnsaladorPart("EQ", "exec",{day: [2,3,4,5,6,7], block: ["eq"]}),
new EnsaladorPart("PD", "exec",{day: [2,3,4,5,6,7], block: ["pd"]}),
new EnsaladorPart("PK PL", "exec",{day: [2,3,4,5,6,7], block: ["pk","pl"]}),
new EnsaladorPart("PQ", "exec",{day: [2,3,4,5,6,7], block: ["pq"]}),
new EnsaladorPart("PF", "exec",{day: [2,3,4,5,6,7], block: ["pf"]}),
new EnsaladorPart("PH", "exec",{day: [2,3,4,5,6,7], block: ["ph"]}),
new EnsaladorPart("Final", "exec",{day: [2,3,4,5,6,7]}),
new EnsaladorPart("Close", "close")
];
e = new Ensalador(parts);
e.execute((err,schedules) => {
if (err) throw err;
console.log(schedules);
});
// na hora de fazer as reservas não pode deixar o cara pedi uma reserva se o cara ja pediu outra no mesmo horario
\ No newline at end of file
#!/bin/bash
./ensalador open || return 1
echo "CT"
./ensalador exec "{day: [2,3,4,5,6,7], block: [ct]}"
echo "EQ"
./ensalador exec "{day: [2,3,4,5,6,7], block: [eq]}"
echo "PD"
./ensalador exec "{day: [2,3,4,5,6,7], block: [pd]}"
echo "PK PL"
./ensalador exec "{day: [2,3,4,5,6,7], block: [pk,pl]}"
echo "PQ"
./ensalador exec "{day: [2,3,4,5,6,7], block: [pq]}"
echo "PF"
./ensalador exec "{day: [2,3,4,5,6,7], block: [pf]}"
echo "PH"
./ensalador exec "{day: [2,3,4,5,6,7], block: [ph]}"
./ensalador exec "{day: [2,3,4,5,6,7]}"
./ensalador close
./Relacoes.sh output.txt
/*================================ LICENSE ====================================
# Copyright (C) 2017 - Centro de Computação Cientifica e Software Livre (C3SL)
# Clarissa Pereira <cdp13@inf.ufpr.br>
# Daniela Ivanchechen
# Felipe Bombardelli <felipebombardelli@gmail.com>
# Rafael Castilho <rsc15@inf.ufpr.br>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------*/
/*=====================================================================================*/
struct Database {//makes the classroom assignment all classes needed
Rooms rooms;
Turmas schedules;
TurmasIndex index;//map containing the assignements for each class
std::string db_current;
std::string db_schedules_origin;
YAML::Node yaml_rooms;
YAML::Node yaml_schedules;
double max_dist;
double factor_dist;
double factor_free;
Database(){}
Database(std::string rooms_file, std::string schedules_file, std::string db_current){
this->db_current = db_current;
this->loadRooms( rooms_file );
this->db_schedules_origin = schedules_file;
}
void loadOrigin(){
this->loadSchedules( db_schedules_origin );
}
void loadCurrent(){
this->loadSchedules( db_current );
}
inline void setFactors(double dist, double free, double max){
this->factor_dist = dist;
this->factor_free = free;
this->max_dist = max;
}