Google OR-Tools: ortools/flatzinc/model.h Source File

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef ORTOOLS_FLATZINC_MODEL_H_

15#define ORTOOLS_FLATZINC_MODEL_H_

16

17#include <cstdint>

18#include <map>

19#include <string>

20#include <utility>

21#include <vector>

22

23#include "absl/container/flat_hash_map.h"

24#include "absl/strings/string_view.h"

25#include "absl/types/span.h"

27

29namespace fz {

30

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

51

55 static Domain Interval(int64_t included_min, int64_t included_max);

66

67

69 bool empty() const;

70

71

72 int64_t Min() const;

73

74

75 int64_t Max() const;

76

77

78 int64_t Value() const;

79

80

82

83

84 bool Contains(int64_t value) const;

85 bool OverlapsIntList(const std::vector<int64_t>& vec) const;

88

89

90

96

97

98

99

101

104

105

109

112

115};

116

117

118

119

120struct Variable {

121

122

123

124

125

126

127

128

129

130

131 bool Merge(absl::string_view other_name, const Domain& other_domain,

132 bool other_temporary);

133

135

138

139

140

142

143

144

146

147 private:

149

150 Variable(absl::string_view name_, const Domain& domain_, bool temporary_);

151};

152

153

154

168

180

182

183

185

186

188

189 int64_t Value() const;

190

191

193

194

195

196 bool Contains(int64_t value) const;

197

198 int64_t ValueAt(int pos) const;

199

200

202

203

205

207

208 int Size() const;

209

215};

216

217

218

220 Constraint(absl::string_view t, std::vector<Argument> args,

221 bool strong_propag, bool sym, bool redundant)

228

230

231

233

235

237

238

239

242

243

244

245

246

248

249

250

251

253

254

256

257

259};

260

261

262

263

264

277

282 std::vector<Annotation> args);

290

295

296

297

299

308};

309

310

311

314 Bounds(int64_t min_value_, int64_t max_value_)

319 };

320

321

325

326

327

329 absl::string_view name, std::vector<Bounds> bounds,

331

333

335

339

340

343};

344

346 public:

348 : name_(name), objective_(nullptr), maximize_(true) {}

350

351

352

353

354

356 bool defined, bool set_is_fixed = false);

359

360 void AddConstraint(absl::string_view id, std::vector<Argument> arguments,

361 bool is_domain, bool symmetry, bool redundant);

362 void AddConstraint(absl::string_view id, std::vector<Argument> arguments);

364

365

366

367

371

373

374

375

376 const std::vector<Variable*>& variables() const { return variables_; }

377 const std::vector<Constraint*>& constraints() const { return constraints_; }

379 return search_annotations_;

380 }

381 const std::vector<SolutionOutputSpecs>& output() const { return output_; }

382 bool maximize() const { return maximize_; }

385 return float_objective_variables_;

386 }

388 return float_objective_coefficients_;

389 }

394 float_objective_variables_.push_back(var);

395 float_objective_coefficients_.push_back(coeff);

396 }

398 float_objective_offset_ = offset;

399 }

400

401

403

404 const std::string& name() const { return name_; }

405

406 private:

407 const std::string name_;

408

409

410 std::vector<Variable*> variables_;

411

412

413 std::vector<Constraint*> constraints_;

414

416 bool maximize_;

417 std::vector<Variable*> float_objective_variables_;

418 std::vector<double> float_objective_coefficients_;

419 double float_objective_offset_ = 0.0;

420

421 std::vector<Annotation> search_annotations_;

422 std::vector<SolutionOutputSpecs> output_;

423};

424

425

426

428 public:

430 : model_(model), logger_(logger) {}

432 return constraints_per_variables_[var].size();

433 }

436

437 private:

438 const Model& model_;

440 std::map<std::string, std::vector<Constraint*>> constraints_per_type_;

441 absl::flat_hash_map<const Variable*, std::vector<Constraint*>>

442 constraints_per_variables_;

443};

444

445

447

448}

449}

450

451#endif

Model(absl::string_view name)

Definition model.h:347

int NumVariableOccurrences(Variable *var)

Definition model.h:431

ModelStatistics(const Model &model, SolverLogger *logger)

Definition model.h:429

void PrintStatistics() const

bool maximize() const

Definition model.h:382

void AddConstraint(absl::string_view id, std::vector< Argument > arguments, bool is_domain, bool symmetry, bool redundant)

const std::vector< double > & float_objective_coefficients() const

Definition model.h:387

void AddFloatingPointObjectiveTerm(Variable *var, double coeff)

Definition model.h:393

const std::vector< Variable * > & float_objective_variables() const

Definition model.h:384

Model(absl::string_view name)

Definition model.h:347

const std::vector< Constraint * > & constraints() const

Definition model.h:377

void SetObjective(Variable *obj)

Definition model.h:391

void SetFloatingPointObjectiveOffset(double offset)

Definition model.h:397

const std::vector< SolutionOutputSpecs > & output() const

Definition model.h:381

const std::vector< Variable * > & variables() const

Definition model.h:376

Variable * AddVariable(absl::string_view name, const Domain &domain, bool defined, bool set_is_fixed=false)

Variable * AddFloatConstant(double value)

std::string DebugString() const

void AddOutput(SolutionOutputSpecs output)

void Maximize(Variable *obj, std::vector< Annotation > search_annotations)

double float_objective_offset() const

Definition model.h:390

void Satisfy(std::vector< Annotation > search_annotations)

const std::string & name() const

Definition model.h:404

const std::vector< Annotation > & search_annotations() const

Definition model.h:378

Variable * objective() const

Definition model.h:383

void ClearObjective()

Definition model.h:392

bool IsInconsistent() const

void Minimize(Variable *obj, std::vector< Annotation > search_annotations)

Variable * AddConstant(int64_t value)

void FlattenAnnotations(const Annotation &ann, std::vector< Annotation > *out)

Constraint(absl::string_view t, std::vector< Argument > args, bool strong_propag, bool sym, bool redundant)

Definition model.h:220

std::vector< int64_t > values

Definition model.h:106

static Annotation String(absl::string_view str)

static Annotation FunctionCall(absl::string_view id)

void AppendAllVariables(std::vector< Variable * > *vars) const

Type type

Definition model.h:300

std::string id

Definition model.h:303

static Annotation FunctionCallWithArguments(absl::string_view id, std::vector< Annotation > args)

static Annotation Empty()

static Annotation AnnotationList(std::vector< Annotation > list)

static Annotation IntegerList(const std::vector< int64_t > &values)

static Annotation VarRefArray(std::vector< Variable * > variables)

static Annotation Identifier(absl::string_view id)

std::vector< Variable * > variables

Definition model.h:305

int64_t interval_max

Definition model.h:302

std::vector< int64_t > values

Definition model.h:306

Type

Definition model.h:266

@ INT_LIST

Definition model.h:271

@ ANNOTATION_LIST

Definition model.h:267

@ INT_VALUE

Definition model.h:270

@ VAR_REF_ARRAY

Definition model.h:274

@ INTERVAL

Definition model.h:272

@ FUNCTION_CALL

Definition model.h:269

@ STRING_VALUE

Definition model.h:275

@ VAR_REF

Definition model.h:273

@ IDENTIFIER

Definition model.h:268

bool IsFunctionCallWithIdentifier(absl::string_view identifier) const

Definition model.h:292

static Annotation VarRef(Variable *var)

static Annotation IntegerValue(int64_t value)

static Annotation Interval(int64_t interval_min, int64_t interval_max)

std::vector< Annotation > annotations

Definition model.h:304

int64_t interval_min

Definition model.h:301

std::string string_value

Definition model.h:307

std::string DebugString() const

std::vector< Variable * > variables

Definition model.h:212

static Argument FloatList(std::vector< double > floats)

static Argument FloatValue(double value)

std::vector< Domain > domains

Definition model.h:213

bool HasOneValueAt(int pos) const

Variable * VarAt(int pos) const

std::string DebugString() const

bool IsArrayOfValues() const

static Argument VoidArgument()

static Argument IntegerValue(int64_t value)

int64_t ValueAt(int pos) const

static Argument Interval(int64_t imin, int64_t imax)

static Argument FromDomain(const Domain &domain)

static Argument IntegerList(std::vector< int64_t > values)

static Argument VarRef(Variable *var)

static Argument FloatInterval(double lb, double ub)

std::vector< double > floats

Definition model.h:214

bool Contains(int64_t value) const

static Argument DomainList(std::vector< Domain > domains)

static Argument VarRefArray(std::vector< Variable * > vars)

Type type

Definition model.h:210

Type

Definition model.h:156

@ VAR_REF_ARRAY

Definition model.h:165

@ VAR_REF

Definition model.h:164

@ INT_INTERVAL

Definition model.h:158

@ DOMAIN_LIST

Definition model.h:160

@ FLOAT_LIST

Definition model.h:163

@ INT_LIST

Definition model.h:159

@ FLOAT_INTERVAL

Definition model.h:162

@ VOID_ARGUMENT

Definition model.h:166

@ INT_VALUE

Definition model.h:157

@ FLOAT_VALUE

Definition model.h:161

std::vector< int64_t > values

Definition model.h:211

bool is_symmetric_breaking

Definition model.h:255

std::string DebugString() const

void RemoveArg(int arg_pos)

Constraint(absl::string_view t, std::vector< Argument > args, bool strong_propag, bool sym, bool redundant)

Definition model.h:220

bool active

Definition model.h:252

bool is_redundant

Definition model.h:258

std::vector< Argument > arguments

Definition model.h:241

std::string type

Definition model.h:240

bool strong_propagation

Definition model.h:247

static Domain AllFloats()

bool IntersectWithSingleton(int64_t value)

static Domain IntegerList(std::vector< int64_t > values)

bool OverlapsDomain(const Domain &other) const

static Domain IntegerValue(int64_t value)

std::string DebugString() const

bool is_interval

Definition model.h:107

static Domain FloatValue(double value)

bool IntersectWithInterval(int64_t interval_min, int64_t interval_max)

bool IntersectWithDomain(const Domain &domain)

bool SetEmptyFloatDomain()

bool is_a_set

Definition model.h:110

static Domain EmptyDomain()

bool IntersectWithFloatDomain(const Domain &domain)

bool RemoveValue(int64_t value)

static Domain FloatInterval(double lb, double ub)

std::vector< int64_t > values

Definition model.h:106

bool display_as_boolean

Definition model.h:108

bool is_float

Definition model.h:113

static Domain SetOfBoolean()

static Domain Interval(int64_t included_min, int64_t included_max)

static Domain SetOfAllInt64()

static Domain SetOfInterval(int64_t included_min, int64_t included_max)

bool Contains(int64_t value) const

bool OverlapsIntInterval(int64_t lb, int64_t ub) const

std::vector< double > float_values

Definition model.h:114

static Domain SetOfIntegerList(std::vector< int64_t > values)

static Domain SetOfIntegerValue(int64_t value)

bool IntersectWithListOfIntegers(absl::Span< const int64_t > integers)

bool OverlapsIntList(const std::vector< int64_t > &vec) const

bool is_fixed_set

Definition model.h:111

int64_t max_value

Definition model.h:318

std::string DebugString() const

Bounds(int64_t min_value_, int64_t max_value_)

Definition model.h:314

int64_t min_value

Definition model.h:317

std::string name

Definition model.h:336

bool display_as_boolean

Definition model.h:342

std::vector< Variable * > flat_variables

Definition model.h:338

static SolutionOutputSpecs MultiDimensionalArray(absl::string_view name, std::vector< Bounds > bounds, std::vector< Variable * > flat_variables, bool display_as_boolean)

std::string DebugString() const

Variable * variable

Definition model.h:337

static SolutionOutputSpecs VoidOutput()

static SolutionOutputSpecs SingleVariable(absl::string_view name, Variable *variable, bool display_as_boolean)

std::vector< Bounds > bounds

Definition model.h:341

friend class Model

Definition model.h:148

std::string name

Definition model.h:136

bool active

Definition model.h:145

Domain domain

Definition model.h:137

bool temporary

Definition model.h:141

bool Merge(absl::string_view other_name, const Domain &other_domain, bool other_temporary)

std::string DebugString() const