2024-04-01 00:01:49 -04:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2024 Brett Terpstra
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FINALPROJECT_RUNNER_STATES_H
|
|
|
|
#define FINALPROJECT_RUNNER_STATES_H
|
|
|
|
|
|
|
|
#include <blt/std/types.h>
|
2024-04-03 02:04:21 -04:00
|
|
|
#include "blt/std/logging.h"
|
2024-04-01 00:01:49 -04:00
|
|
|
|
|
|
|
// use a state-machine to control what phase of the pyramid search we are in.
|
|
|
|
enum class state_t : blt::u8
|
|
|
|
{
|
|
|
|
// NAME,
|
|
|
|
RUN_GENERATIONS,
|
|
|
|
CHILD_EVALUATION,
|
|
|
|
PRUNE,
|
2024-04-01 09:50:07 -04:00
|
|
|
IDLE,
|
2024-04-01 00:01:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class packet_id : blt::u8
|
|
|
|
{
|
|
|
|
// NAME, DIRECTION PAYLOAD
|
2024-04-03 02:04:21 -04:00
|
|
|
EXECUTE_RUN,// Server -> Client numOfGens, Number of runs to execute
|
|
|
|
CHILD_FIT, // Client -> Server fitness, Fitness of Child
|
|
|
|
PRUNE, // Server -> Client NONE, Child should terminate
|
|
|
|
EXEC_TIME, // Client -> Server timer, wall time in ms
|
|
|
|
CPU_TIME, // Client -> Server timer, cpu time in ms
|
|
|
|
CPU_CYCLES, // Client -> Server timer, number of cpu cycles used
|
|
|
|
MEM_USAGE, // Client -> Server timer, memory usage
|
2024-04-01 11:02:44 -04:00
|
|
|
// avg fitness, best fitness, avg tree size
|
2024-04-02 01:58:34 -04:00
|
|
|
// unused
|
2024-04-03 02:04:21 -04:00
|
|
|
AVG_FIT, // Client -> Server Average Fitness, gen #
|
|
|
|
BEST_FIT,// Client -> Server Best fitness, gen #
|
|
|
|
AVG_TREE,// Client -> Server Avg Tree Size, gen #
|
|
|
|
};
|
|
|
|
|
|
|
|
struct memory_snapshot
|
|
|
|
{
|
|
|
|
blt::u64 memory;
|
|
|
|
blt::u64 timeSinceStart;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct process_info_t
|
|
|
|
{
|
|
|
|
blt::u64 wall_time = 0;
|
|
|
|
blt::u64 cpu_time = 0;
|
|
|
|
blt::u64 cpu_cycles = 0;
|
|
|
|
std::vector<memory_snapshot> snapshots;
|
|
|
|
|
|
|
|
process_info_t& operator+=(const process_info_t& info)
|
|
|
|
{
|
|
|
|
if (info.snapshots.size() == snapshots.size())
|
|
|
|
{
|
|
|
|
for (const auto& v : blt::enumerate(info.snapshots))
|
|
|
|
{
|
|
|
|
snapshots[v.first].memory += v.second.memory;
|
|
|
|
snapshots[v.first].timeSinceStart += v.second.timeSinceStart;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
BLT_WARN("Hey maybe you should fix your stupid program!");
|
|
|
|
wall_time += info.wall_time;
|
|
|
|
cpu_time += info.cpu_time;
|
|
|
|
cpu_cycles += info.cpu_cycles;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
process_info_t& operator/=(int i)
|
|
|
|
{
|
2024-04-03 02:06:00 -04:00
|
|
|
for (auto& v : snapshots)
|
2024-04-03 02:04:21 -04:00
|
|
|
{
|
2024-04-03 02:06:00 -04:00
|
|
|
v.memory /= i;
|
|
|
|
v.timeSinceStart /= i;
|
2024-04-03 02:04:21 -04:00
|
|
|
}
|
|
|
|
wall_time /= i;
|
|
|
|
cpu_time /= i;
|
|
|
|
cpu_cycles /= i;
|
2024-04-03 02:06:00 -04:00
|
|
|
|
|
|
|
return *this;
|
2024-04-03 02:04:21 -04:00
|
|
|
}
|
2024-04-01 00:01:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct packet_t
|
|
|
|
{
|
|
|
|
state_t state;
|
|
|
|
packet_id id;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
double fitness;
|
2024-04-03 02:04:21 -04:00
|
|
|
blt::u64 timer;
|
|
|
|
memory_snapshot snapshot;
|
|
|
|
blt::i32 numOfGens;
|
2024-04-01 00:01:49 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-03 02:04:21 -04:00
|
|
|
#endif//FINALPROJECT_RUNNER_STATES_H
|