Minor reformating of C++ examples.

This commit is contained in:
Vincent Furnon
2015-07-31 15:35:59 +02:00
parent 278c6e0678
commit bb481a320c
4 changed files with 16 additions and 13 deletions

View File

@@ -201,11 +201,11 @@ class Evaluator {
explicit Evaluator(const std::vector<IntVar*>& vars) : vars_(vars) {}
// Prefer the value with the smallest domain
int64 VarEvaluator(int64 index) { return vars_[index]->Size(); }
int64 VarEvaluator(int64 index) const { return vars_[index]->Size(); }
// Penalize for each time the value appears in a different domain,
// as values have to be unique
int64 ValueEvaluator(int64 id, int64 value) {
int64 ValueEvaluator(int64 id, int64 value) const {
int appearance = 0;
for (int i = 0; i < vars_.size(); ++i) {
@@ -266,8 +266,9 @@ void CostasSoft(const int dim) {
// Here we only consider the elements from 1 to dim.
for (int64 j = dim + 1; j <= 2 * dim; ++j) {
// Penalize if an element occurs more than once.
vars[index] = solver.MakeSemiContinuousExpr(
solver.MakeSum(matrix_count[j], -1), 0, 1)->Var();
vars[index] =
solver.MakeSemiContinuousExpr(solver.MakeSum(matrix_count[j], -1), 0, 1)
->Var();
occurences.push_back(vars[index++]);
}
@@ -290,9 +291,9 @@ void CostasSoft(const int dim) {
// Penalize occurrences of more than one
for (int64 j = 0; j <= 2 * dim; ++j) {
vars[index] =
solver.MakeSemiContinuousExpr(solver.MakeSum(domain_count[j], -1), 0,
dim - i)->Var();
vars[index] = solver.MakeSemiContinuousExpr(
solver.MakeSum(domain_count[j], -1), 0, dim - i)
->Var();
occurences.push_back(vars[index++]);
}

View File

@@ -169,8 +169,9 @@ class StopServiceTimePlusTransition {
transition_time_(transition_time) {}
int64 Compute(RoutingModel::NodeIndex from,
RoutingModel::NodeIndex to) const {
return location_container_.SameLocation(from, to) ? 0
: stop_time_ + transition_time_->Run(from, to);
return location_container_.SameLocation(from, to)
? 0
: stop_time_ + transition_time_->Run(from, to);
}
private:

View File

@@ -25,6 +25,7 @@
#include "constraint_solver/model.pb.h"
#include "util/graph_export.h"
#include "util/string_array.h"
#include "base/status.h"
DEFINE_string(input, "", "Input file of the problem.");
DEFINE_string(output, "", "Output file when doing modifications.");

View File

@@ -121,13 +121,13 @@ int main(int argc, char* argv[]) {
ProblemStatus solve_status = ProblemStatus::INIT;
const char* status_string;
std::string status_string;
double objective_value;
double solving_time_in_sec = 0;
if (FLAGS_mps_solve) {
ScopedWallTime timer(&solving_time_in_sec);
solve_status = solver.Solve(linear_program);
status_string = GetProblemStatusString(solve_status).c_str();
status_string = GetProblemStatusString(solve_status);
objective_value = ToDouble(solver.GetObjectiveValue());
}
@@ -137,7 +137,7 @@ int main(int argc, char* argv[]) {
}
printf("%s,", mps_reader.GetProblemName().c_str());
if (FLAGS_mps_solve) {
printf("%15.15e,%s,%-6.4g,", objective_value, status_string,
printf("%15.15e,%s,%-6.4g,", objective_value, status_string.c_str(),
solving_time_in_sec);
}
printf("%s,%s\n", linear_program.GetProblemStats().c_str(),
@@ -152,7 +152,7 @@ int main(int argc, char* argv[]) {
mps_reader.GetProblemName().c_str());
if (FLAGS_mps_solve) {
printf("%-45s: %15.15e\n", "Objective value", objective_value);
printf("%-45s: %s\n", "Problem status", status_string);
printf("%-45s: %s\n", "Problem status", status_string.c_str());
printf("%-45s: %-6.4g\n", "Solving time", solving_time_in_sec);
}
printf("%s%s", linear_program.GetPrettyProblemStats().c_str(),