Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include <Windows.h>
- #include <chrono>
- #include <stdio.h>
- #include <thread>
- using namespace std;
- //refers to departments
- //Company/*/Region/*/Factory/*/Department/*/0input type/1output type/2typeprodfactor/3typeconsfactor/4Number of workers/5Price of bought resources/6Stockpiled EResources/7Avaivable Resources/8active?/9size in 1000ppl
- //refers to factories
- //Company/*/Region/*/Factory/*/0Money/1-100Input avaivable type/101-200Output availvable type
- //refers to pricing
- //type/price
- const int Companies = 2;
- const int Regions = 250;
- const int Factories = 5;
- const int Departments = 10000;
- const int Additional = 10;
- const int Additional2 = 5;
- int b = 0;
- float FactoryDB[Companies][Regions][Factories][Additional2];
- float DepartmentDB[Companies][Regions][Factories][Departments][Additional];
- int Initialize_DB() {
- for (int i = 0; i < Companies; ++i) {
- for (int j = 0; j < Regions; ++j) {
- for (int k = 0; k < Factories; ++k) {
- for (int l = 0; l < Departments; ++l) {
- for (int m = 0; m < Additional - 1; ++m) {
- DepartmentDB[i][j][k][l][m] = rand() % 100;
- if (DepartmentDB[i][j][k][l][1] == 0) {
- DepartmentDB[i][j][k][l][1] = 1;
- }
- if (DepartmentDB[i][j][k][l][4] > 5) {
- DepartmentDB[i][j][k][l][4] = 5;
- }
- if (DepartmentDB[i][j][k][l][3] < .1) {
- DepartmentDB[i][j][k][l][3] = .1;
- }
- DepartmentDB[i][j][k][l][8] = rand() % 1;
- }
- }
- }
- }
- }
- return 0;
- }
- long int counted = 0;
- //int typeprodfactor, int typeconsfactor//Modifies the production and consumption of resources
- int Produce(int compf, int regf, int factoryf, int departmentf, float typeprodfactor, float typeconsfactor) {
- DepartmentDB[compf][regf][factoryf][departmentf][6] = DepartmentDB[compf][regf][factoryf][departmentf][6] + DepartmentDB[compf][regf][factoryf][departmentf][4] * typeprodfactor;
- DepartmentDB[compf][regf][factoryf][departmentf][7] = DepartmentDB[compf][regf][factoryf][departmentf][7] - DepartmentDB[compf][regf][factoryf][departmentf][4] * typeconsfactor;
- return 0;
- }
- int mainProducer() {
- for (int i = 0; i < Companies; ++i) {
- for (int j = 0; j < Regions; ++j) {
- for (int k = 0; k < Factories; ++k) {
- for (int l = 0; l < Departments; ++l) {
- if (DepartmentDB[i][j][k][l][8] == 1) {
- if (DepartmentDB[i][j][k][l][7] >= DepartmentDB[i][j][k][l][4] * DepartmentDB[i][j][k][l][3]) {
- Produce(i, j, k, l, DepartmentDB[i][j][k][l][2], DepartmentDB[i][j][k][l][3]);
- }
- }
- }
- }
- }
- }
- ++counted;
- return 0;
- }
- float interfactorytransport(int compf, int regf, int factoryf, int departmentf) {
- if (DepartmentDB[compf][regf][factoryf][departmentf][6] > 0) {
- int outputtype = DepartmentDB[compf][regf][factoryf][departmentf][1];
- FactoryDB[compf][regf][factoryf][outputtype + 100] = FactoryDB[compf][regf][factoryf][outputtype + 100] + DepartmentDB[compf][regf][factoryf][departmentf][6];
- DepartmentDB[compf][regf][factoryf][departmentf][6] = 0;
- }
- float DB[2];
- int inputtype = DepartmentDB[compf][regf][factoryf][departmentf][0];
- if (FactoryDB[compf][regf][factoryf][inputtype] > 0) {
- DepartmentDB[compf][regf][factoryf][departmentf][7] = DepartmentDB[compf][regf][factoryf][departmentf][7] + FactoryDB[compf][regf][factoryf][inputtype];
- FactoryDB[compf][regf][factoryf][inputtype] = 0;
- }
- return 0;
- }
- int mainTransporter() {
- for (int i = 0; i < Companies; ++i) {
- for (int j = 0; j < Regions; ++j) {
- for (int k = 0; k < Factories; ++k) {
- for (int l = 0; l < Departments; ++l) {
- interfactorytransport(i, j, k, l);
- }
- }
- }
- }
- return 0;
- }
- int wait = 5;
- int main(void)
- {
- int AvailvableResources = 1;
- Initialize_DB();
- while (true) {
- auto start = std::chrono::system_clock::now();
- thread first(mainProducer);
- if (wait > 50000) {
- thread second(mainTransporter);
- second.join();
- wait = 0;
- }
- first.join();
- //++wait;
- auto end = std::chrono::system_clock::now();
- auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
- cout << elapsed.count() << '\n';
- }
- cin >> AvailvableResources;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment