delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
Driver.cpp
1
6#include "delpi/parser/Driver.h"
7
8#include <fstream>
9#include <iostream>
10#include <sstream> // IWYU pragma: keep for std::stringstream
11#include <string>
12
13#include "delpi/libs/gmp.h"
14#include "delpi/util/Config.h"
15#include "delpi/util/error.h"
16
17namespace delpi {
18
19Driver::Driver(LpSolver& lp_solver, const std::string& class_name)
20 : lp_solver_{lp_solver}, stats_{lp_solver.config().with_timings(), class_name, "Total time spent in parsing"} {}
21
22bool Driver::ParseStream(std::istream& in, const std::string& sname) {
23 TimerGuard timer_guard(&stats_.m_timer(), stats_.enabled());
24 input_name_ = sname;
25 return ParseStreamCore(in);
26}
27
28bool Driver::ParseString(std::string_view input, const std::string& sname) {
29 TimerGuard timer_guard(&stats_.m_timer(), stats_.enabled());
30 input_name_ = sname;
31 return ParseStringCore(input);
32}
33
34bool Driver::ParseFile(const std::string& filename) {
35 TimerGuard timer_guard(&stats_.m_timer(), stats_.enabled());
36 return ParseFileCore(filename);
37}
38
39void Driver::Error(const std::string& m) { std::cerr << m << std::endl; }
40
42 // Don't consider the time spent solving the LP problem in the time spent parsing.
43 stats_.m_timer().Pause();
44 lp_solver_.Solve();
45 stats_.m_timer().Resume();
46}
47
48void Driver::GetInfo(const std::string& key) const {
49 if (lp_solver_.config().silent()) return;
50 std::cout << "get-info ( " << key << " ): " << lp_solver_.GetInfo(key) << std::endl;
51}
52void Driver::SetInfo(const std::string& key, const std::string& value) { lp_solver_.SetInfo(key, value); }
53void Driver::SetOption(const std::string& key, const std::string& value) { lp_solver_.SetOption(key, value); }
54void Driver::Exit() { DELPI_DEBUG("Exit"); }
55
56} // namespace delpi
virtual bool ParseStreamCore(std::istream &in)=0
Parse the stream.
virtual bool ParseFileCore(const std::string &filename)=0
Parse the input file.
bool ParseString(std::string_view input, const std::string &sname="string stream")
Invoke the scanner and parser on an input string.
Definition Driver.cpp:28
LpSolver & lp_solver_
LP parser that will store the parsed data.
Definition Driver.h:113
Driver(LpSolver &lp_solver, const std::string &class_name="Driver")
construct a new parser driver context
Definition Driver.cpp:19
std::string input_name_
The name of the stream being parsed.
Definition Driver.h:111
virtual bool ParseStringCore(std::string_view input)=0
Parse the string.
static void Error(const std::string &m)
General error handling.
Definition Driver.cpp:39
virtual bool ParseFile(const std::string &filename)
Invoke the scanner and parser on a file.
Definition Driver.cpp:34
void Solve()
Call context_.CheckSat() and print proper output messages to the standard output.
Definition Driver.cpp:41
IterationStats stats_
Statistics for the driver.
Definition Driver.h:115
bool ParseStream(std::istream &in, const std::string &sname="stream input")
Invoke the scanner and parser for a stream.
Definition Driver.cpp:22
Facade class that hides the underlying LP solver used by delpi.
Definition LpSolver.h:60
void SetInfo(const std::string &key, const std::string &value)
Set the information stored under the given key to the given value.
Definition LpSolver.cpp:165
const std::string & GetInfo(const std::string &key) const
Retrieve the information stored under the given key.
Definition LpSolver.cpp:164
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
Definition Timer.h:132
Global namespace for the delpi library.