Compare commits
7 Commits
41797a07b8
...
64d4d6c71c
| Author | SHA1 | Date | |
|---|---|---|---|
| 64d4d6c71c | |||
| cd382540a4 | |||
| e045407993 | |||
| 877ad0ad1a | |||
| 510415982d | |||
| 1b976d4d32 | |||
| 0a8d951cfa |
6
main.cpp
6
main.cpp
@ -8,10 +8,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ALPHA
|
#ifndef ALPHA
|
||||||
#define ALPHA 0.99
|
#define ALPHA 0.9999
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main()
|
||||||
{
|
{
|
||||||
int number_of_items = 0;
|
int number_of_items = 0;
|
||||||
int capacity = 0;
|
int capacity = 0;
|
||||||
@ -23,7 +23,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
sa::solution act = sa::solution::simulated_annealing(capacity, items,
|
sa::solution act = sa::solution::simulated_annealing(capacity, items,
|
||||||
TEMP, ALPHA);
|
TEMP, ALPHA);
|
||||||
|
|
||||||
act.print_sol();
|
act.print_sol();
|
||||||
}
|
}
|
||||||
|
|||||||
14
run.bat
14
run.bat
@ -1,5 +1,15 @@
|
|||||||
|
:: Uso: [set EXEC="caminho/do/executavel.exe"] && [set TEST_FOLDER="caminho/dos/casetests"] && run.bat
|
||||||
@ECHO off
|
@ECHO off
|
||||||
|
|
||||||
for %%g in (test/*) do (
|
if not defined EXEC (
|
||||||
"build/solucao.exe" < test/%%g
|
set EXEC="build/solucao.exe"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not defined TEST_FOLDER (
|
||||||
|
set TEST_FOLDER=test
|
||||||
|
)
|
||||||
|
|
||||||
|
for %%g in (%TEST_FOLDER%/*) do (
|
||||||
|
echo Arquivo de teste: %TEST_FOLDER%/%%g
|
||||||
|
%EXEC% < %TEST_FOLDER%/%%g
|
||||||
)
|
)
|
||||||
13
run.sh
13
run.sh
@ -2,6 +2,15 @@
|
|||||||
|
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
for file in $(find test -type f); do
|
if [[ -z $EXEC ]]; then
|
||||||
build/main.out < $file
|
EXEC="build/main.out"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $TEST_FOLDER ]]; then
|
||||||
|
TEST_FOLDER="test"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in $(find "$TEST_FOLDER" -type f); do
|
||||||
|
echo "Arquivo de teste: $file"
|
||||||
|
"$EXEC" < "$file"
|
||||||
done
|
done
|
||||||
|
|||||||
2
sa.cpp
2
sa.cpp
@ -2,7 +2,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
auto sa::solution::simulated_annealing(int capacity, const std::vector<long long> &items,
|
auto sa::solution::simulated_annealing(int capacity, const std::vector<long long> &items,
|
||||||
const double alpha, double temp)->sa::solution
|
const double alpha, double temp)->sa::solution
|
||||||
{
|
{
|
||||||
sa::solution best(items, capacity);
|
sa::solution best(items, capacity);
|
||||||
best.randomize();
|
best.randomize();
|
||||||
|
|||||||
6
sa.hpp
6
sa.hpp
@ -44,8 +44,8 @@ class solution {
|
|||||||
solution() = default;
|
solution() = default;
|
||||||
|
|
||||||
solution(const std::vector<long long> &items, int capacity): // Gera a solução inicial
|
solution(const std::vector<long long> &items, int capacity): // Gera a solução inicial
|
||||||
items(items), gen(std::random_device()()), capacity(capacity),
|
items(items), gen(std::random_device()()), capacity(capacity),
|
||||||
fitness(calculate_boxes()) {}
|
fitness(calculate_boxes()) {}
|
||||||
|
|
||||||
void setneighbor() { // Gera um vizinho da solução
|
void setneighbor() { // Gera um vizinho da solução
|
||||||
std::uniform_int_distribution<> dist(0, items.size() - 1);
|
std::uniform_int_distribution<> dist(0, items.size() - 1);
|
||||||
@ -93,7 +93,7 @@ class solution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static auto simulated_annealing(int capacity, const std::vector<long long> &items,
|
static auto simulated_annealing(int capacity, const std::vector<long long> &items,
|
||||||
double alpha, double temp)->solution;
|
double alpha, double temp)->solution;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sa
|
} // namespace sa
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user