<commit_before>// Copyright 2010-2013 Google
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in comÏpliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS% IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "flatzinc2/presolve.h"

#include <algorithm>

#include "base/map_util.h"
#include "base/strutil.h"

DECLARE_bool(fz_logging);
DECLARE_bool(fz_verbose);

namespace operations_research {

// For the author's reference, here is an indicative list of presolve rules
// that
// should eventually be implemented.
//
// Presolve rule:
//   - table_int -> intersect variables domains with tuple set.
//
// TODO(user):
//   - store dependency graph of constraints -> variable to speed up presolve.
//   - use the same dependency graph to speed up variable substitution.
//   - add more check when presolving out a variable or a constraint.

// ----- Presolve rules -----

// Note on documentation
//
// In order to document presolve rules, we will use the following naming
// convention:
//   - x, x1, xi, y, y1, yi denote integer variables
//   - b, b1, bi denote boolean variables
//   - c, c1, ci denote integer constants
//   - t, t1, ti denote boolean constants
//   - => x after a constraint denotes the target variable of this constraint.
// Arguments are listed in order.

// Propagates cast constraint.
// Input : bool2int(b, x) => x
// Action: replace all instances of x by b in the model.
// Output: inactive constraint.
bool FzPresolver::PresolveBool2Int(FzConstraint* ct) {
  ct->MarkAsInactive();
  MarkVariablesAsEquivalent(ct->Arg(0).Var(), ct->Arg(1).Var());
  return true;
}

// Presolve equality constraint: int_eq
//
// Rule 1:
// Input : int_eq(x, 0) && x == y - z (stored in difference_map_).
// Output: int_eq(y, z)
//
// Rule 2:
// Input : int_eq(x, c)
// Action: Reduce domain of x to {c}<commit_msg>bool2int presolve now supports constants<commit_after>// Copyright 2010-2013 Google
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in comÏpliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS% IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "flatzinc2/presolve.h"

#include <algorithm>

#include "base/map_util.h"
#include "base/strutil.h"

DECLARE_bool(fz_logging);
DECLARE_bool(fz_verbose);

namespace operations_research {

// For the author's reference, here is an indicative list of presolve rules
// that
// should eventually be implemented.
//
// Presolve rule:
//   - table_int -> intersect variables domains with tuple set.
//
// TODO(user):
//   - store dependency graph of constraints -> variable to speed up presolve.
//   - use the same dependency graph to speed up variable substitution.
//   - add more check when presolving out a variable or a constraint.

// ----- Presolve rules -----

// Note on documentation
//
// In order to document presolve rules, we will use the following naming
// convention:
//   - x, x1, xi, y, y1, yi denote integer variables
//   - b, b1, bi denote boolean variables
//   - c, c1, ci denote integer constants
//   - t, t1, ti denote boolean constants
//   - => x after a constraint denotes the target variable of this constraint.
// Arguments are listed in order.

// Propagates cast constraint.
// Input : bool2int(b, x) => x
// Action: replace all instances of x by b in the model.
// Output: inactive constraint.
bool FzPresolver::PresolveBool2Int(FzConstraint* ct) {
  if (ct->Arg(0).HasOneValue() || ct->Arg(1).HasOneValue()) {
    FZVLOG << "Change bound bool2int into int_eq";
    ct->type = "int_eq";
    return true;
  } else {
    ct->MarkAsInactive();
    MarkVariablesAsEquivalent(ct->Arg(0).Var(), ct->Arg(1).Var());
    return true;
  }
}

// Presolve equality constraint: int_eq
//
// Rule 1:
// Input : int_eq(x, 0) && x == y - z (stored in difference_map_).
// Output: int_eq(y, z)
//
// Rule 2:
// Input : int_eq(x, c)
// Action: Reduce domain of x to {c}
{'fraction_non_alphanumeric': 0.12196693150096628, 'fraction_numerical': 0.011595447713120034, 'mean_word_length': 3.1850853548966755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2980021', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1364, 'n_words': 561}