Repository navigation
Expand file tree
/
Copy pathutils.h
More file actions
90 lines (66 loc) · 1.8 KB
/
Copy pathutils.h
File metadata and controls
90 lines (66 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <iostream>
#include <chrono>
#include <mpi.h>
#include <vector>
#include <random>
#include <sstream>
#include <algorithm>
using namespace std;
#define REQ 10
#define ACK 20
#define REL 30
#define REST 0
#define WAIT 10
#define INSECTION 20
#define MIN_INSECTION_TIME_US 1000000
#define MAX_INSECTION_TIME_US 4000000
#define COOLDOWN_TIME_US 3000000 // czas cooldownu dla miasta w mikrosekundach
#define CITY_APPLY_PROB 0.15
struct Message
{
int type;
int timestamp;
int PID;
Message(int tab[3]);
Message(int type, int timestamp, int PID);
};
struct Request
{
int timestamp;
int PID;
bool isActive = true;
Request(int timestamp, int PID);
Request(Message message);
bool IsBetterThan(const Request& other);
bool operator<(const Request& other) const {
if (timestamp == other.timestamp) {
return PID < other.PID;
}
return timestamp < other.timestamp;
}
bool operator==(const Request& other) const {
if (timestamp == other.timestamp && PID == other.PID){
return true;
}
return false;
}
};
struct Cooldown
{
int city;
chrono::steady_clock::time_point endTime;
Cooldown(int city);
bool IsCooldownOver();
};
void Send(Message message, int destination);
void SendBroadcast(Message message, int source, int n);
int Max(int clock, int pckClock);
int GetIndex(vector<Request> &requestVec, Request &element);
int GetOldestActiveIndex(vector<Request> &requestVec, int PID);
chrono::steady_clock::time_point GetRandomInsectionTime();
chrono::steady_clock::time_point GetCooldownTime();
bool GetShouldApplyCity();
void PrintColor(int PID, int Clock, string text);
string AddText(string text, int City);
void ClearRequests(vector<Request> &requestVec, int m);