<commit_before>// Copyright 2010 Google
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance 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 "base/integral_types.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/stringprintf.h"
#include "constraint_solver/constraint_solveri.h"

#if defined(_MSC_VER)
#pragma warning(disable : 4351 4355 4804 4805)
#endif

namespace operations_research {

// ----- Interval Var -----

const int64 IntervalVar::kMinValidValue = kint64min >> 2;
const int64 IntervalVar::kMaxValidValue = kint64max >> 2;

// ----- MirrorIntervalVar -----

class MirrorIntervalVar : public IntervalVar {
 public:
  MirrorIntervalVar(Solver* const s, IntervalVar* const t)
      : IntervalVar(s, "Mirror<" + t->name() + ">"), t_(t) {}
  virtual ~MirrorIntervalVar() {}

  // These methods query, set and watch the start position of the
  // interval var.
  virtual int64 StartMin() const { return -t_->EndMax(); }
  virtual int64 StartMax() const { return -t_->EndMin(); }
  virtual void SetStartMin(int64 m) { t_->SetEndMax(-m); }
  virtual void SetStartMax(int64 m) { t_->SetEndMin(-m); }
  virtual void SetStartRange(int64 mi, int64 ma) { t_->SetEndRange(-ma, -mi); }
  virtual void WhenStartRange(Demon* const d) { t_->WhenEndRange(d); }
  virtual void WhenStartBound(Demon* const d) { t_->WhenEndBound(d); }

  // These methods query, set and watch the duration of the interval var.
  virtual int64 DurationMin() const { return t_->DurationMin(); }
  virtual int64 DurationMax() const { return t_->DurationMax(); }
  virtual void SetDurationMin(int64 m) { t_->SetDurationMin(m); }
  virtual void SetDurationMax(int64 m) { t_->SetDurationMax(m); }
  virtual void SetDurationRange(int64 mi, int64 ma) {
    t_->SetDurationRange(mi, ma);
  }
  virtual void WhenDurationRange(Demon* const d) { t_->WhenDurationRange(d); }
  virtual void WhenDurationBound(Demon* const d) { t_->WhenDurationBound(d); }

  // These methods query, set and watch the end position of the interval var.
  virtual int64 EndMin() const { return -t_->StartMax(); }
  virtual int64 EndMax() const { return -t_->StartMin(); }
  virtual void SetEndMin(int64 m) { t_->SetStartMax(-m); }
  virtual void SetEndMax(int64 m) { t_->SetStartMin(-m); }
  virtual void SetEndRange(int64 mi, int64 ma) { t_->SetStartRange(-ma, -mi); }
  virtual void WhenEndRange(Demon* const d) { t_->WhenStartRange(d); }
  virtual void WhenEndBound(Demon* const d) { t_->WhenStartBound(d); }

  // These methods query, set and watches the performed status of the
  // interval var.
  virtual bool MustBePerformed() const { return t_->MustBePerformed(); }
  virtual bool MayBePerformed() const { return t_->MayBePerformed(); }
  virtual void SetPerformed(bool val) { t_->SetPerformed(val); }
  virtual void WhenPerformedBound(Demon* const d) { t_->WhenPerformedBound(d); }

 private:
  IntervalVar* const t_;
  DISALLOW_COPY_AND_ASSIGN(MirrorIntervalVar);
};

IntervalVar* Solver::MakeMirrorInterval(IntervalVar* const t) {
  return RevAlloc(new MirrorIntervalVar(this, t));
}

// An IntervalVar that passes all function calls to an underlying interval
// variable as long as it is not prohibited, and that interprets prohibited
// intervals as intervals of duration 0 that must be executed between
// [kMinValidValue and kMaxValidValue].
//
// Such interval variables have a very similar behavior to others.
// Invariants such as StartMin() + DurationMin() <= EndMin() that are maintained
// for traditional interval variables are maintained for instances of
// AlwaysPerformedIntervalVarWrapper. However, there is no monotonicity of the
// values returned by the start/end getters. For example, during a given
// propagation, three successive calls to StartMin could return,
// in this order, 1, 2, and kMinValidValue.
//
// This class exists so that we can easily implement the
// IntervalVarRelaxedMax and IntervalVarRelaxedMin classes below.
class AlwaysPerformedIntervalVarWrapper : public IntervalVar {
 public:
  explicit AlwaysPerformedIntervalVarWrapper(IntervalVar* const t)
      : IntervalVar(t->solver(),
                    StrCat("AlwaysPerformed<", t->name(), ">")),
        t_(t) {}
  virtual ~AlwaysPerformedIntervalVarWrapper() {}
  virtual int64 StartMin() const {
    return MayUnderlyingBePerformed()? t_->StartMin() : kMinValidValue;
  }
  virtual int64 StartMax() const {
    return MayUnderlyingBePerformed() ? t_->StartMax() : kMaxValidValue;
  }
  virtual void SetStartMin(int64 m) { t_->SetStartMin(m); }
  virtual void SetStartMax(int64 m) { t_->SetStartMax(m); }
  virtual void SetStartRange(int64 mi, int64 ma) { t_->SetStartRange(mi, ma); }
  virtual void WhenStartRange(Demon* const d) { t_->WhenStartRange(d); }
  virtual void WhenStartBound(Demon* const d) { t_->WhenStartBound(d); }
  virtual int64 DurationMin() const {
    return MayUnderlyingBePerformed() ? t_->DurationMin() : 0LL;
  }
  virtual int64 DurationMax() const {
    return MayUnderlyingBePerformed() ? t_->DurationMax() : 0LL;
  }
  virtual void SetDurationMin(int64 m) { t_->SetDurationMin(m); }
  virtual void SetDurationMax(int64 m) { t_->SetDurationMax(m); }
  virtual void SetDurationRange(int64 mi, int64 ma) {
    t_->SetDurationRange(mi, ma);
  }
  virtual void WhenDurationRange(Demon* const d) { t_->WhenDurationRange(d); }
  virtual void WhenDurationBound(Demon* const d) { t_->WhenDurationBound(d); }
  virtual int64 EndMin() const {
    return MayUnderlyingBePerformed() ? t_->EndMin() : kMinValidValue;
  }
  virtual int64 EndMax() const {
    return MayUnderlyingBePerformed() ? t_->EndMax() : kMaxValidValue;<commit_msg>fix compilation<commit_after>// Copyright 2010 Google
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance 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 "base/integral_types.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/stringprintf.h"
#include "constraint_solver/constraint_solveri.h"

#if defined(_MSC_VER)
#pragma warning(disable : 4351 4355 4804 4805)
#endif

namespace operations_research {

// ----- Interval Var -----

const int64 IntervalVar::kMinValidValue = kint64min >> 2;
const int64 IntervalVar::kMaxValidValue = kint64max >> 2;

// ----- MirrorIntervalVar -----

class MirrorIntervalVar : public IntervalVar {
 public:
  MirrorIntervalVar(Solver* const s, IntervalVar* const t)
      : IntervalVar(s, "Mirror<" + t->name() + ">"), t_(t) {}
  virtual ~MirrorIntervalVar() {}

  // These methods query, set and watch the start position of the
  // interval var.
  virtual int64 StartMin() const { return -t_->EndMax(); }
  virtual int64 StartMax() const { return -t_->EndMin(); }
  virtual void SetStartMin(int64 m) { t_->SetEndMax(-m); }
  virtual void SetStartMax(int64 m) { t_->SetEndMin(-m); }
  virtual void SetStartRange(int64 mi, int64 ma) { t_->SetEndRange(-ma, -mi); }
  virtual void WhenStartRange(Demon* const d) { t_->WhenEndRange(d); }
  virtual void WhenStartBound(Demon* const d) { t_->WhenEndBound(d); }

  // These methods query, set and watch the duration of the interval var.
  virtual int64 DurationMin() const { return t_->DurationMin(); }
  virtual int64 DurationMax() const { return t_->DurationMax(); }
  virtual void SetDurationMin(int64 m) { t_->SetDurationMin(m); }
  virtual void SetDurationMax(int64 m) { t_->SetDurationMax(m); }
  virtual void SetDurationRange(int64 mi, int64 ma) {
    t_->SetDurationRange(mi, ma);
  }
  virtual void WhenDurationRange(Demon* const d) { t_->WhenDurationRange(d); }
  virtual void WhenDurationBound(Demon* const d) { t_->WhenDurationBound(d); }

  // These methods query, set and watch the end position of the interval var.
  virtual int64 EndMin() const { return -t_->StartMax(); }
  virtual int64 EndMax() const { return -t_->StartMin(); }
  virtual void SetEndMin(int64 m) { t_->SetStartMax(-m); }
  virtual void SetEndMax(int64 m) { t_->SetStartMin(-m); }
  virtual void SetEndRange(int64 mi, int64 ma) { t_->SetStartRange(-ma, -mi); }
  virtual void WhenEndRange(Demon* const d) { t_->WhenStartRange(d); }
  virtual void WhenEndBound(Demon* const d) { t_->WhenStartBound(d); }

  // These methods query, set and watches the performed status of the
  // interval var.
  virtual bool MustBePerformed() const { return t_->MustBePerformed(); }
  virtual bool MayBePerformed() const { return t_->MayBePerformed(); }
  virtual void SetPerformed(bool val) { t_->SetPerformed(val); }
  virtual void WhenPerformedBound(Demon* const d) { t_->WhenPerformedBound(d); }

 private:
  IntervalVar* const t_;
  DISALLOW_COPY_AND_ASSIGN(MirrorIntervalVar);
};

IntervalVar* Solver::MakeMirrorInterval(IntervalVar* const t) {
  return RevAlloc(new MirrorIntervalVar(this, t));
}

// An IntervalVar that passes all function calls to an underlying interval
// variable as long as it is not prohibited, and that interprets prohibited
// intervals as intervals of duration 0 that must be executed between
// [kMinValidValue and kMaxValidValue].
//
// Such interval variables have a very similar behavior to others.
// Invariants such as StartMin() + DurationMin() <= EndMin() that are maintained
// for traditional interval variables are maintained for instances of
// AlwaysPerformedIntervalVarWrapper. However, there is no monotonicity of the
// values returned by the start/end getters. For example, during a given
// propagation, three successive calls to StartMin could return,
// in this order, 1, 2, and kMinValidValue.
//
// This class exists so that we can easily implement the
// IntervalVarRelaxedMax and IntervalVarRelaxedMin classes below.
class AlwaysPerformedIntervalVarWrapper : public IntervalVar {
 public:
  explicit AlwaysPerformedIntervalVarWrapper(IntervalVar* const t)
      : IntervalVar(t->solver(),
                    StringPrintf("AlwaysPerformed<%s>", t->name().c_str())),
        t_(t) {}
  virtual ~AlwaysPerformedIntervalVarWrapper() {}
  virtual int64 StartMin() const {
    return MayUnderlyingBePerformed()? t_->StartMin() : kMinValidValue;
  }
  virtual int64 StartMax() const {
    return MayUnderlyingBePerformed() ? t_->StartMax() : kMaxValidValue;
  }
  virtual void SetStartMin(int64 m) { t_->SetStartMin(m); }
  virtual void SetStartMax(int64 m) { t_->SetStartMax(m); }
  virtual void SetStartRange(int64 mi, int64 ma) { t_->SetStartRange(mi, ma); }
  virtual void WhenStartRange(Demon* const d) { t_->WhenStartRange(d); }
  virtual void WhenStartBound(Demon* const d) { t_->WhenStartBound(d); }
  virtual int64 DurationMin() const {
    return MayUnderlyingBePerformed() ? t_->DurationMin() : 0LL;
  }
  virtual int64 DurationMax() const {
    return MayUnderlyingBePerformed() ? t_->DurationMax() : 0LL;
  }
  virtual void SetDurationMin(int64 m) { t_->SetDurationMin(m); }
  virtual void SetDurationMax(int64 m) { t_->SetDurationMax(m); }
  virtual void SetDurationRange(int64 mi, int64 ma) {
    t_->SetDurationRange(mi, ma);
  }
  virtual void WhenDurationRange(Demon* const d) { t_->WhenDurationRange(d); }
  virtual void WhenDurationBound(Demon* const d) { t_->WhenDurationBound(d); }
  virtual int64 EndMin() const {
    return MayUnderlyingBePerformed() ? t_->EndMin() : kMinValidValue;
  }
  virtual int64 EndMax() const {
    return MayUnderlyingBePerformed() ? t_->EndMax() : kMaxValidValue;
{'fraction_non_alphanumeric': 0.11772921459086427, 'fraction_numerical': 0.01692408807098258, 'mean_word_length': 4.376766784452297, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 103, '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': '3840509', 'n_tokens_mistral': 3792, 'n_tokens_neox': 3604, 'n_words': 1166}