<commit_before>#include <gecode/driver.hh>
#include <gecode/int.hh>
#include <gecode/minimodel.hh>
#include <gecode/gist.hh>
#include <gecode/search.hh>

#include "dep_selector_to_gecode.h"

#include <iostream>
#include <vector>
//
// T
//

using namespace Gecode;

//
// Version Problem
//
const int VersionProblem::UNRESOLVED_VARIABLE = -1;


VersionProblem::VersionProblem() 
{
}

// Clone constructor; check gecode rules for this...
VersionProblem::VersionProblem(bool share, VersionProblem & s) 
  : Script(share, s)
{
  package_versions.update(*this, share, s.package_versions);
}

// Support for gecode
Space* VersionProblem::copy(bool share) 
{
  return new VersionProblem(share,*this);
}

VersionProblem::~VersionProblem() {
}


int
VersionProblem::AddPackage(int minVersion, int maxVersion, int currentVersion) 
{
  int index = package_version_accumulator.size();
  IntVar version(*this, minVersion, maxVersion);
  package_version_accumulator << version;
  return index;
}

bool 
VersionProblem::AddVersionConstraint(int packageId, int version, 
				     int dependentPackageId, int minDependentVersion, int maxDependentVersion) 

{
  BoolVar pred(*this, 0, 1);
  version_flags << pred;
  // Constrain pred to reify package @ version
  rel(*this, package_version_accumulator[packageId], IRT_EQ, version, pred);
  // Add the predicated version constraints imposed on dependent package
  dom(*this, package_version_accumulator[dependentPackageId], minDependentVersion, maxDependentVersion, pred);
}

void VersionProblem::Finalize() 
{
  package_versions = IntVarArray(*this, package_version_accumulator);
  branch(*this, package_versions, INT_VAR_SIZE_MIN, INT_VAL_MAX);
}

IntVar & VersionProblem::SafeGetVar(int packageId)
{
  IntVar & var = package_versions[packageId];
}

int VersionProblem::GetPackageVersion(int packageId) 
{
  IntVar & var = SafeGetVar(packageId);
  if (1 == var.size()) return var.val();
  return UNRESOLVED_VARIABLE;
}
int VersionProblem::GetAFC(int packageId)
{
  return SafeGetVar(packageId).afc();
}  

int VersionProblem::GetMax(int packageId)
{
  return SafeGetVar(packageId).max();<commit_msg>Fix bad constraint system for dependencies.<commit_after>#include <gecode/driver.hh>
#include <gecode/int.hh>
#include <gecode/minimodel.hh>
#include <gecode/gist.hh>
#include <gecode/search.hh>

#include "dep_selector_to_gecode.h"

#include <iostream>
#include <vector>
//
// T
//

using namespace Gecode;

//
// Version Problem
//
const int VersionProblem::UNRESOLVED_VARIABLE = -1;


VersionProblem::VersionProblem() 
{
}

// Clone constructor; check gecode rules for this...
VersionProblem::VersionProblem(bool share, VersionProblem & s) 
  : Script(share, s)
{
  package_versions.update(*this, share, s.package_versions);
}

// Support for gecode
Space* VersionProblem::copy(bool share) 
{
  return new VersionProblem(share,*this);
}

VersionProblem::~VersionProblem() {
}


int
VersionProblem::AddPackage(int minVersion, int maxVersion, int currentVersion) 
{
  int index = package_version_accumulator.size();
  IntVar version(*this, minVersion, maxVersion);
  package_version_accumulator << version;
  return index;
}

bool 
VersionProblem::AddVersionConstraint(int packageId, int version, 
				     int dependentPackageId, int minDependentVersion, int maxDependentVersion) 

{
  BoolVar version_match(*this, 0, 1);
  BoolVar depend_match(*this, 0, 1);
  //version_flags << version_match;
  // Constrain pred to reify package @ version
  rel(*this, package_version_accumulator[packageId], IRT_EQ, version, version_match);
  // Add the predicated version constraints imposed on dependent package
  dom(*this, package_version_accumulator[dependentPackageId], minDependentVersion, maxDependentVersion, depend_match);
  rel(*this, version_match, BOT_IMP, depend_match, 1);  
}

void VersionProblem::Finalize() 
{
  package_versions = IntVarArray(*this, package_version_accumulator);
  branch(*this, package_versions, INT_VAR_SIZE_MIN, INT_VAL_MAX);
}

IntVar & VersionProblem::SafeGetVar(int packageId)
{
  IntVar & var = package_versions[packageId];
}

int VersionProblem::GetPackageVersion(int packageId) 
{
  IntVar & var = SafeGetVar(packageId);
  if (1 == var.size()) return var.val();
  return UNRESOLVED_VARIABLE;
}
int VersionProblem::GetAFC(int packageId)
{
  return SafeGetVar(packageId).afc();
}  

int VersionProblem::GetMax(int packageId)
{
  return SafeGetVar(packageId).max();
{'fraction_non_alphanumeric': 0.11813869437542354, 'fraction_numerical': 0.002484752654167608, 'mean_word_length': 5.75, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6630180', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1414, 'n_words': 315}