delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
parser.cpp
1
6
#include "delpi/parser/parser.h"
7
8
#include <fstream>
9
#include <iostream>
10
#include <memory>
11
#include <string>
12
13
#include "delpi/parser/lp/Driver.h"
14
#include "delpi/parser/mps/Driver.h"
15
#include "delpi/util/error.h"
16
17
namespace
delpi
{
18
19
bool
LpSolver::Parse
() {
return
config_
.read_from_stdin() ?
ParseStream
(std::cin) :
ParseFile
(
config_
.filename()); }
20
bool
LpSolver::ParseFile
(
const
std::string& filename) {
21
std::ifstream in(filename.c_str());
22
if
(!in.good())
return
false
;
23
return
ParseStream
(in, filename);
24
}
25
bool
LpSolver::ParseStream
(std::istream& stream,
const
std::string& stream_name) {
26
const
std::unique_ptr parser{
GetDriverInstance
(*
this
)};
27
DELPI_ASSERT(parser,
"Parser not found"
);
28
const
bool
res = parser->ParseStream(stream, stream_name);
29
stats_
.parser_stats = parser->stats();
30
return
res;
31
}
32
bool
LpSolver::ParseString
(
const
std::string&
string
) {
return
GetDriverInstance
(*this)->ParseString(
string
); }
33
34
std::unique_ptr<Driver>
GetDriverInstance
(
LpSolver
& lp_solver) {
35
switch
(lp_solver.config().actual_format()) {
36
case
Config::Format::MPS
:
37
return
std::make_unique<mps::MpsDriver>(lp_solver);
38
case
Config::Format::LP
:
39
return
std::make_unique<lp::LpDriver>(lp_solver);
40
default
:
41
DELPI_UNREACHABLE();
42
}
43
}
44
45
}
// namespace delpi
delpi::Config::Format::LP
@ LP
LP format.
Definition
Config.h:48
delpi::Config::Format::MPS
@ MPS
MPS format.
Definition
Config.h:47
delpi::LpSolver
Facade class that hides the underlying LP solver used by delpi.
Definition
LpSolver.h:60
delpi::LpSolver::config_
Config config_
Configuration to use.
Definition
LpSolver.h:533
delpi::LpSolver::Parse
bool Parse()
Parse the input file or stdin based on the Config parameters.
Definition
parser.cpp:19
delpi::LpSolver::ParseStream
bool ParseStream(std::istream &stream, const std::string &stream_name="(stdin)")
Parse the given stream as input.
Definition
parser.cpp:25
delpi::LpSolver::ParseFile
bool ParseFile(const std::string &filename)
Parse the file with the given filename.
Definition
parser.cpp:20
delpi::LpSolver::stats_
LpStats stats_
Statistics of the solver.
Definition
LpSolver.h:534
delpi::LpSolver::ParseString
bool ParseString(const std::string &string)
Parse the given string as input.
Definition
parser.cpp:32
delpi
Global namespace for the delpi library.
delpi::GetDriverInstance
std::unique_ptr< Driver > GetDriverInstance(LpSolver &lp_solver)
Get the correct driver instance based on the actual format set in the Config.
Definition
parser.cpp:34
delpi
parser
parser.cpp
Generated by
1.17.0