155 lines
2.7 KiB
C++
155 lines
2.7 KiB
C++
|
#define _CRT_SECURE_NO_WARNINGS
|
|||
|
#include <iostream>
|
|||
|
#include <vector>
|
|||
|
#include <algorithm>
|
|||
|
#include <cstring>
|
|||
|
#include <cctype>
|
|||
|
#include <string>
|
|||
|
#include <cmath>
|
|||
|
#include <set>
|
|||
|
#include <map>
|
|||
|
#include <ctime>
|
|||
|
#include <chrono>
|
|||
|
#include <fstream>
|
|||
|
#include <iomanip>
|
|||
|
#include <queue>
|
|||
|
using namespace std;
|
|||
|
#define endl '\n'
|
|||
|
#define endll cout << endl
|
|||
|
#define LL_MAX 2223372036854775807
|
|||
|
typedef long long ll;
|
|||
|
|
|||
|
int ALL_TIME = 100;
|
|||
|
|
|||
|
struct Laba {
|
|||
|
public:
|
|||
|
struct potok
|
|||
|
{
|
|||
|
double need;
|
|||
|
vector<double> coords;
|
|||
|
potok()
|
|||
|
{
|
|||
|
need = rand() % 20 + 1;
|
|||
|
}
|
|||
|
double add(double t)
|
|||
|
{
|
|||
|
if (t >= need)
|
|||
|
{
|
|||
|
coords.push_back(need);
|
|||
|
int otv = need;
|
|||
|
need = 0;
|
|||
|
return otv;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
coords.push_back(t);
|
|||
|
need -= t;
|
|||
|
return t;
|
|||
|
}
|
|||
|
}
|
|||
|
bool full()
|
|||
|
{
|
|||
|
if (need == 0)
|
|||
|
return true;
|
|||
|
return false;
|
|||
|
}
|
|||
|
};
|
|||
|
struct process
|
|||
|
{
|
|||
|
public:
|
|||
|
vector<potok> Worker;
|
|||
|
int count_potok = 0;
|
|||
|
process()
|
|||
|
{
|
|||
|
count_potok = rand() % 5 + 1;
|
|||
|
for (int i = 0; i < count_potok; i++)
|
|||
|
{
|
|||
|
Worker.emplace_back();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
vector<process> proc;
|
|||
|
int count_proc;
|
|||
|
int count_all_potok = 0;
|
|||
|
int potok_max;
|
|||
|
double kvant;
|
|||
|
int timer = 0;
|
|||
|
int count_kvant;
|
|||
|
Laba()
|
|||
|
{
|
|||
|
count_kvant = 0;
|
|||
|
count_proc = 5;
|
|||
|
for (int i = 0; i < count_proc; i++)
|
|||
|
{
|
|||
|
proc.emplace_back();
|
|||
|
count_all_potok += proc[i].count_potok;
|
|||
|
}
|
|||
|
potok_max = count_all_potok;
|
|||
|
}
|
|||
|
bool Kvant_time()
|
|||
|
{
|
|||
|
kvant = 30;
|
|||
|
count_all_potok = potok_max;
|
|||
|
for (int i = 0; i < count_proc; i++)
|
|||
|
{
|
|||
|
for (int j = 0; j < proc[i].count_potok; j++)
|
|||
|
{
|
|||
|
if (proc[i].Worker[j].full())
|
|||
|
count_all_potok--;
|
|||
|
}
|
|||
|
}
|
|||
|
if (count_all_potok == 0)
|
|||
|
return 0;
|
|||
|
count_kvant++;
|
|||
|
double time = (double)kvant / (double)count_all_potok;
|
|||
|
for (int i = 0; i < count_proc && kvant > 0; i++)
|
|||
|
{
|
|||
|
for (int j = 0; j < proc[i].count_potok && kvant > 0; j++)
|
|||
|
{
|
|||
|
time = (double)kvant / (double)count_all_potok;
|
|||
|
if (proc[i].Worker[j].full())
|
|||
|
continue;
|
|||
|
count_all_potok--;
|
|||
|
double m = proc[i].Worker[j].add(time);
|
|||
|
kvant -= m;
|
|||
|
//cout << m << " ";
|
|||
|
}
|
|||
|
}
|
|||
|
return 1;
|
|||
|
}
|
|||
|
void Paint()
|
|||
|
{
|
|||
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
|
|||
|
for (int i = 0; i < count_proc; i++)
|
|||
|
{
|
|||
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " << i + 1 << endl << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
|
|||
|
for (int j = 0; j < count_kvant; j++)
|
|||
|
cout << j + 1<< "\t";
|
|||
|
endll;
|
|||
|
for (int j = 0; j < proc[i].count_potok; j++)
|
|||
|
{
|
|||
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> " << j + 1 << endl;
|
|||
|
for (int k = 0; k < proc[i].Worker[j].coords.size(); k++)
|
|||
|
{
|
|||
|
cout << proc[i].Worker[j].coords[k] << "\t";
|
|||
|
}
|
|||
|
endll;
|
|||
|
}
|
|||
|
endll;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
srand(time(NULL));
|
|||
|
setlocale(LC_ALL, "Russian");
|
|||
|
cout.precision(3);
|
|||
|
Laba l;
|
|||
|
while (l.Kvant_time()) {}
|
|||
|
l.Paint();
|
|||
|
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|