A set of benchmarks to compare a new prototype MiniZinc implementation
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3/*
4 * Main authors:
5 * Guido Tack <guido.tack@monash.edu>
6 */
7
8/* This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11
12#ifndef __MINIZINC_FLATTEN_HH__
13#define __MINIZINC_FLATTEN_HH__
14
15#include <minizinc/astexception.hh>
16#include <minizinc/model.hh>
17
18namespace MiniZinc {
19
20/// Exception thrown for errors during flattening
21class FlatteningError : public LocationException {
22public:
23 FlatteningError(EnvI& env, const Location& loc, const std::string& msg);
24 ~FlatteningError(void) throw() {}
25 virtual const char* what(void) const throw() { return "MiniZinc: flattening error"; }
26};
27
28/// Options for the flattener
29struct FlatteningOptions {
30 /// Keep output in resulting flat model
31 bool keepOutputInFzn;
32 /// Verbose output during flattening
33 bool verbose;
34 /// Only use paths for variables introduced by file 0 (the MiniZinc model)
35 bool only_toplevel_paths;
36 /// Construct and collect mzn_paths for expressions and VarDeclI during flattening
37 bool collect_mzn_paths;
38 /// Do not apply domain changes but insert them as constraints (useful for debugging)
39 bool record_domain_changes;
40 /// Only range domains for old linearization. Set from redefs to true if not here
41 bool onlyRangeDomains;
42 /// Allow the use of Half Reifications
43 bool enable_imp;
44 /// Timeout for flattening in milliseconds (0 means no timeout)
45 unsigned long long int timeout;
46 /// Create standard, DZN or JSON output
47 enum OutputMode { OUTPUT_ITEM, OUTPUT_DZN, OUTPUT_JSON } outputMode;
48 /// Output objective value (only for DZN and JSON mode)
49 bool outputObjective;
50 /// Output original output item as string (only for DZN and JSON mode)
51 bool outputOutputItem;
52 /// Default constructor
53 FlatteningOptions(void)
54 : keepOutputInFzn(false),
55 verbose(false),
56 only_toplevel_paths(false),
57 collect_mzn_paths(false),
58 record_domain_changes(false),
59 onlyRangeDomains(false),
60 enable_imp(true),
61 timeout(0),
62 outputMode(OUTPUT_ITEM),
63 outputObjective(false),
64 outputOutputItem(false) {}
65};
66
67class Pass {
68public:
69 Pass(){};
70 virtual Env* run(Env* env, std::ostream& log) = 0;
71 virtual ~Pass(){};
72};
73
74/// Flatten model \a m
75void flatten(Env& m, FlatteningOptions opt = FlatteningOptions());
76
77/// Translate \a m into old FlatZinc syntax
78void oldflatzinc(Env& m);
79
80/// Populate FlatZinc output model
81void populateOutput(Env& e);
82
83/// Statistics on flat models
84struct FlatModelStatistics {
85 /// Number of integer variables
86 int n_int_vars;
87 /// Number of bool variables
88 int n_bool_vars;
89 /// Number of float variables
90 int n_float_vars;
91 /// Number of set variables
92 int n_set_vars;
93 /// Number of bool constraints
94 int n_bool_ct;
95 /// Number of integer constraints
96 int n_int_ct;
97 /// Number of float constraints
98 int n_float_ct;
99 /// Number of set constraints
100 int n_set_ct;
101 /// Number of reified constraints evaluated
102 int n_reif_ct;
103 /// Number of half-reified constraints evaluated
104 int n_imp_ct;
105 /// Number of implications eliminated using path compression
106 int n_imp_del;
107 /// Number of linear expressions eliminated using path compression
108 int n_lin_del;
109 /// Constructor
110 FlatModelStatistics(void)
111 : n_int_vars(0),
112 n_bool_vars(0),
113 n_float_vars(0),
114 n_set_vars(0),
115 n_bool_ct(0),
116 n_int_ct(0),
117 n_float_ct(0),
118 n_set_ct(0),
119 n_reif_ct(0),
120 n_imp_ct(0),
121 n_imp_del(0),
122 n_lin_del(0) {}
123};
124
125/// Compute statistics for flat model in \a m
126FlatModelStatistics statistics(Model* m);
127
128} // namespace MiniZinc
129
130#endif