-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolverManager.h
100 lines (73 loc) · 2.72 KB
/
SolverManager.h
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
91
92
93
94
95
96
97
98
99
100
/*
Copyright (c) Dan Liew 2012
This file is part of NSolv.
NSolv 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.
NSolv 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 NSolv. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef SOLVERMANAGER_H_
#define SOLVERMANAGER_H_
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include "Solver.h"
#include <unistd.h>
#include <time.h>
#include <queue>
#include <sys/select.h>
#include <semaphore.h>
class SolverManager
{
public:
SolverManager(const std::string& _inputFile, double _timeOut, bool _loggingMode);
~SolverManager();
void addSolver(const std::string& name, const std::string& cmdLineArgs, bool inputOnStdin);
void addSolver(const std::string& name, bool inputOnStdin);
bool invokeSolvers();
size_t getNumberOfSolvers();
private:
std::vector<Solver*> solvers;
std::map<pid_t,Solver*> pidToSolverMap;
std::string inputFile;
const std::string empty;
timespec timeout;
timespec startTime;
timespec originalTimeout;
std::map<int,Solver*> fdToSolverMap;
fd_set lookingToRead;
int largestFileDescriptor;
bool loggingMode;
std::ofstream loggingFile;
sem_t* solverSynchronisingSemaphore;
std::string solverSyncName;
bool timeoutEnabled();
/*Adjust timeout so that is OriginalTimeout - (currentTime - startTime)
* This is needed because if a solver finishes and it has a useless answer we should
* wait for the next available solver but only for the remaining time left from what the
* user originally asked for.
*/
void adjustRemainingTime();
//Configures "lookingToRead" to be set up for the solvers in "fdToSolverMap"
void setupFileDescriptorSet();
Solver* getSolverFromFileDescriptorSet();
void removeSolverFromFileDescriptorSet(Solver* s);
void listSolversToLog();
void printSolverHeaderToLog();
void printSolverAnswerToLog(Solver::Result result, const std::string& name);
void printUnfinishedSolversToLog();
};
//helper function a -b
struct timespec subtract(struct timespec a, struct timespec b);
double toDouble(struct timespec t);
bool operator==(struct timespec a, struct timespec b);
bool operator>(struct timespec a, struct timespec b);
bool operator>=(struct timespec a, struct timespec b);
#endif /* SOLVERMANAGER_H_ */