Make FAP a header only library

This commit is contained in:
Corentin Le Molgat
2018-11-23 08:52:59 +01:00
parent 20d9bc0e50
commit 60fa2fb271
9 changed files with 581 additions and 697 deletions

View File

@@ -20,9 +20,11 @@
#define OR_TOOLS_EXAMPLES_FAP_MODEL_PRINTER_H_
#include <map>
#include <string>
#include <vector>
#include "examples/cpp/fap_parser.h"
#include "ortools/base/stringprintf.h"
namespace operations_research {
@@ -47,5 +49,70 @@ class FapModelPrinter {
DISALLOW_COPY_AND_ASSIGN(FapModelPrinter);
};
FapModelPrinter::FapModelPrinter(const std::map<int, FapVariable>& variables,
const std::vector<FapConstraint>& constraints,
const std::string& objective,
const std::vector<int>& values)
: variables_(variables),
constraints_(constraints),
objective_(objective),
values_(values) {}
FapModelPrinter::~FapModelPrinter() {}
void FapModelPrinter::PrintFapVariables() {
LOG(INFO) << "Variable File:";
for (const auto& it : variables_) {
std::string domain = "{";
for (const int value : it.second.domain) {
StringAppendF(&domain, "%d ", value);
}
domain.append("}");
std::string hard = " ";
if (it.second.hard) {
hard = " hard";
}
LOG(INFO) << "Variable " << StringPrintf("%3d: ", it.first)
<< StringPrintf("(degree: %2d) ", it.second.degree)
<< StringPrintf("%3d", it.second.domain_index)
<< StringPrintf("%3d", it.second.initial_position)
<< StringPrintf("%3d", it.second.mobility_index)
<< StringPrintf("%8d", it.second.mobility_cost)
<< StringPrintf(" (%2d) ", it.second.domain_size) << domain
<< hard;
}
}
void FapModelPrinter::PrintFapConstraints() {
LOG(INFO) << "Constraint File:";
for (const FapConstraint& ct : constraints_) {
std::string hard = " ";
if (ct.hard) {
hard = " hard";
}
LOG(INFO) << StringPrintf("%3d ", ct.variable1)
<< StringPrintf("%3d ", ct.variable2) << ct.type << " "
<< ct.operation << " " << StringPrintf("%3d", ct.value)
<< StringPrintf("%3d", ct.weight_index)
<< StringPrintf("%8d", ct.weight_cost) << hard;
}
}
void FapModelPrinter::PrintFapObjective() {
LOG(INFO) << "Objective: " << objective_;
}
void FapModelPrinter::PrintFapValues() {
LOG(INFO) << StringPrintf("Values(%d): ", static_cast<int>(values_.size()));
std::string domain = " ";
for (const int value : values_) {
StringAppendF(&domain, "%d ", value);
}
LOG(INFO) << domain;
}
} // namespace operations_research
#endif // OR_TOOLS_EXAMPLES_FAP_MODEL_PRINTER_H_