Program: 143967
Project: 143967
Buggy source:
private LogicIntegrator(AbstractBuilder<?> builder){
  super(builder);
  logicManager=builder.logicManager;
  labels=builder.labels;
  classifiers=builder.classifiers;
  constraints=builder.constraints;
  sampleErrorRatesEstimates=builder.sampleErrorRatesEstimates;
  logProgress=builder.logProgress;
  instanceKeysMap=HashBiMap.create(data.size());
  labelKeysMap=HashBiMap.create(labels.size());
  classifierKeysMap=HashBiMap.create((int)classifiers.stream().count());
  ProbabilisticSoftLogic.Builder pslBuilder=new ProbabilisticSoftLogic.Builder(logicManager);
  final long[] currentInstanceKey={0};
  final long[] currentLabelKey={0};
  final long[] currentClassifierKey={0};
  if (builder.observedData != null)   builder.observedData.stream().map(Integrator.Data.Instance::instanceId).forEach(instance -> {
    if (!instanceKeysMap.containsValue(instance))     instanceKeysMap.put(currentInstanceKey[0]++,instance);
  }
);
  data.stream().map(Integrator.Data.Instance::instanceId).forEach(instance -> {
    if (!instanceKeysMap.containsValue(instance))     instanceKeysMap.put(currentInstanceKey[0]++,instance);
  }
);
  labels.forEach(label -> labelKeysMap.put(currentLabelKey[0]++,label));
  classifiers.forEach(classifier -> classifierKeysMap.put(currentClassifierKey[0]++,classifier));
  if (logProgress)   logger.info("String_Node_Str");
  instanceType=logicManager.addEntityType("String_Node_Str",instanceKeysMap.keySet());
  labelType=logicManager.addEntityType("String_Node_Str",labelKeysMap.keySet());
  classifierType=logicManager.addEntityType("String_Node_Str",classifierKeysMap.keySet());
  if (logProgress)   logger.info("String_Node_Str");
  List<EntityType> argumentTypes=new ArrayList<>(2);
  argumentTypes.add(labelType);
  argumentTypes.add(labelType);
  mutualExclusionPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,true);
  subsumptionPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,true);
  argumentTypes=new ArrayList<>(2);
  argumentTypes.add(instanceType);
  argumentTypes.add(labelType);
  labelPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,false);
  argumentTypes=new ArrayList<>(2);
  argumentTypes.add(labelType);
  argumentTypes.add(labelType);
  equalLabelsPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,true);
  argumentTypes=new ArrayList<>(3);
  argumentTypes.add(instanceType);
  argumentTypes.add(classifierType);
  argumentTypes.add(labelType);
  labelPredictionPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,false);
  argumentTypes=new ArrayList<>(2);
  argumentTypes.add(classifierType);
  argumentTypes.add(labelType);
  errorRatePredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,false);
  if (logProgress)   logger.info("String_Node_Str");
  Variable instanceVariable=new Variable(0,"String_Node_Str",instanceType);
  Variable classifierVariable=new Variable(1,"String_Node_Str",classifierType);
  Variable label1Variable=new Variable(2,"String_Node_Str",labelType);
  Variable label2Variable=new Variable(3,"String_Node_Str",labelType);
  double power=2;
  double weight=1;
  List<Formula> bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(mutualExclusionPredicate,Arrays.asList(label1Variable,label2Variable)));
  bodyFormulas.add(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable)));
  bodyFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label2Variable)));
  bodyFormulas.add(new Negation(new Atom(equalLabelsPredicate,Arrays.asList(label1Variable,label2Variable))));
  List<Formula> headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(subsumptionPredicate,Arrays.asList(label1Variable,label2Variable)));
  bodyFormulas.add(new Negation(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable))));
  bodyFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label2Variable)));
  bodyFormulas.add(new Negation(new Atom(equalLabelsPredicate,Arrays.asList(label1Variable,label2Variable))));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable)));
  bodyFormulas.add(new Negation(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable))));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable)));
  bodyFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Negation(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable))));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Negation(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable))));
  bodyFormulas.add(new Negation(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable))));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Negation(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable))));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Negation(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable))));
  bodyFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  if (logProgress)   logger.info("String_Node_Str");
  labels.forEach(label -> logicManager.addGroundPredicate(equalLabelsPredicate,Arrays.asList(labelKeysMap.inverse().get(label),labelKeysMap.inverse().get(label)),1.0));
  for (  Constraint constraint : constraints) {
    if (constraint instanceof MutualExclusionConstraint) {
      List<Label> labelsList=new ArrayList<>(((MutualExclusionConstraint)constraint).getLabels());
      for (int label1Index=0; label1Index < labelsList.size(); label1Index++)       for (int label2Index=0; label2Index < labelsList.size(); label2Index++)       if (label1Index != label2Index)       logicManager.addGroundPredicate(mutualExclusionPredicate,Arrays.asList(labelKeysMap.inverse().get(labelsList.get(label1Index)),labelKeysMap.inverse().get(labelsList.get(label2Index))),1.0);
    }
 else     if (constraint instanceof SubsumptionConstraint) {
      Label parentLabel=((SubsumptionConstraint)constraint).getParentLabel();
      Label childLabel=((SubsumptionConstraint)constraint).getChildLabel();
      logicManager.addGroundPredicate(subsumptionPredicate,Arrays.asList(labelKeysMap.inverse().get(parentLabel),labelKeysMap.inverse().get(childLabel)),1.0);
    }
  }
  if (builder.observedData != null)   for (  Integrator.Data.ObservedInstance instance : builder.observedData)   logicManager.addOrReplaceGroundPredicate(labelPredicate,Arrays.asList(instanceKeysMap.inverse().get(instance.instanceId()),labelKeysMap.inverse().get(instance.label())),instance.value() ? 1.0 : 0.0);
  if (logProgress) {
    logger.info("String_Node_Str" + data.stream().filter(i -> i.value() >= 0.5).count());
    logger.info("String_Node_Str" + data.stream().filter(i -> i.value() < 0.5).count());
  }
  for (  Integrator.Data.PredictedInstance instance : data) {
    List<GroundPredicate> mutualExclusionRulePredicates=new ArrayList<>(4);
    List<GroundPredicate> subsumptionRulePredicates=new ArrayList<>(4);
    List<GroundPredicate> ensembleRulePredicates=new ArrayList<>(3);
    List<GroundPredicate> majorityVotePriorRulePredicates=new ArrayList<>(2);
    List<Long> assignment=new ArrayList<>(3);
    assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
    assignment.add(classifierKeysMap.inverse().get(instance.classifierId()));
    assignment.add(labelKeysMap.inverse().get(instance.label()));
    if (logicManager.checkIfGroundPredicateExists(labelPredictionPredicate,assignment))     continue;
    GroundPredicate predictionPredicate=logicManager.addGroundPredicate(labelPredictionPredicate,assignment,instance.value());
    mutualExclusionRulePredicates.add(predictionPredicate);
    subsumptionRulePredicates.add(predictionPredicate);
    ensembleRulePredicates.add(predictionPredicate);
    majorityVotePriorRulePredicates.add(predictionPredicate);
    assignment=new ArrayList<>(2);
    assignment.add(classifierKeysMap.inverse().get(instance.classifierId()));
    assignment.add(labelKeysMap.inverse().get(instance.label()));
    GroundPredicate errorPredicate=logicManager.addGroundPredicate(errorRatePredicate,assignment,null);
    mutualExclusionRulePredicates.add(errorPredicate);
    subsumptionRulePredicates.add(errorPredicate);
    ensembleRulePredicates.add(errorPredicate);
    assignment=new ArrayList<>(2);
    assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
    assignment.add(labelKeysMap.inverse().get(instance.label()));
    GroundPredicate integratedLabelPredicate=logicManager.addGroundPredicate(labelPredicate,assignment,null);
    ensembleRulePredicates.add(integratedLabelPredicate);
    majorityVotePriorRulePredicates.add(integratedLabelPredicate);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{true,false,false},2,1);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{true,true,true},2,1);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{false,false,true},2,1);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{false,true,false},2,1);
    pslBuilder.addRule(majorityVotePriorRulePredicates,new boolean[]{true,false},2,1);
    pslBuilder.addRule(majorityVotePriorRulePredicates,new boolean[]{false,true},2,1);
    for (    Constraint constraint : constraints) {
      if (constraint instanceof MutualExclusionConstraint) {
        List<Label> labelsList=new ArrayList<>(((MutualExclusionConstraint)constraint).getLabels());
        if (labelsList.contains(instance.label())) {
          for (          Label label : labelsList.stream().filter(l -> !l.equals(instance.label())).collect(Collectors.toList())) {
            List<GroundPredicate> mutualExclusionRulePredicatesCopy=new ArrayList<>(mutualExclusionRulePredicates);
            assignment=new ArrayList<>(2);
            assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
            assignment.add(labelKeysMap.inverse().get(label));
            mutualExclusionRulePredicatesCopy.add(logicManager.addGroundPredicate(labelPredicate,assignment,null));
            assignment=new ArrayList<>(2);
            assignment.add(labelKeysMap.inverse().get(instance.label()));
            assignment.add(labelKeysMap.inverse().get(label));
            mutualExclusionRulePredicatesCopy.add(logicManager.getGroundPredicate(mutualExclusionPredicate,assignment));
            pslBuilder.addRule(mutualExclusionRulePredicatesCopy,new boolean[]{true,false,true,true},2,1);
          }
        }
      }
 else       if (constraint instanceof SubsumptionConstraint) {
        if (((SubsumptionConstraint)constraint).getParentLabel().equals(instance.label())) {
          Label childLabel=((SubsumptionConstraint)constraint).getChildLabel();
          List<GroundPredicate> subsumptionRulePredicatesCopy=new ArrayList<>(subsumptionRulePredicates);
          assignment=new ArrayList<>(2);
          assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
          assignment.add(labelKeysMap.inverse().get(childLabel));
          subsumptionRulePredicatesCopy.add(logicManager.addGroundPredicate(labelPredicate,assignment,null));
          assignment=new ArrayList<>(2);
          assignment.add(labelKeysMap.inverse().get(instance.label()));
          assignment.add(labelKeysMap.inverse().get(childLabel));
          subsumptionRulePredicatesCopy.add(logicManager.getGroundPredicate(subsumptionPredicate,assignment));
          pslBuilder.addRule(subsumptionRulePredicatesCopy,new boolean[]{false,false,true,true},2,1);
        }
      }
    }
  }
  psl=pslBuilder.build(false);
}

Fixed version (ground truth):
private LogicIntegrator(AbstractBuilder<?> builder){
  super(builder);
  logicManager=builder.logicManager;
  labels=builder.labels;
  classifiers=builder.classifiers;
  constraints=builder.constraints;
  sampleErrorRatesEstimates=builder.sampleErrorRatesEstimates;
  logProgress=builder.logProgress;
  instanceKeysMap=HashBiMap.create(data.size());
  labelKeysMap=HashBiMap.create(labels.size());
  classifierKeysMap=HashBiMap.create((int)classifiers.stream().count());
  ProbabilisticSoftLogic.Builder pslBuilder=new ProbabilisticSoftLogic.Builder(logicManager);
  final long[] currentInstanceKey={0};
  final long[] currentLabelKey={0};
  final long[] currentClassifierKey={0};
  if (builder.observedData != null)   builder.observedData.stream().map(Integrator.Data.Instance::instanceId).forEach(instance -> {
    if (!instanceKeysMap.containsValue(instance))     instanceKeysMap.put(currentInstanceKey[0]++,instance);
  }
);
  data.stream().map(Integrator.Data.Instance::instanceId).forEach(instance -> {
    if (!instanceKeysMap.containsValue(instance))     instanceKeysMap.put(currentInstanceKey[0]++,instance);
  }
);
  labels.forEach(label -> labelKeysMap.put(currentLabelKey[0]++,label));
  classifiers.forEach(classifier -> classifierKeysMap.put(currentClassifierKey[0]++,classifier));
  if (logProgress)   logger.info("String_Node_Str");
  instanceType=logicManager.addEntityType("String_Node_Str",instanceKeysMap.keySet());
  labelType=logicManager.addEntityType("String_Node_Str",labelKeysMap.keySet());
  classifierType=logicManager.addEntityType("String_Node_Str",classifierKeysMap.keySet());
  if (logProgress)   logger.info("String_Node_Str");
  List<EntityType> argumentTypes=new ArrayList<>(2);
  argumentTypes.add(labelType);
  argumentTypes.add(labelType);
  mutualExclusionPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,true);
  subsumptionPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,true);
  argumentTypes=new ArrayList<>(2);
  argumentTypes.add(instanceType);
  argumentTypes.add(labelType);
  labelPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,false);
  argumentTypes=new ArrayList<>(2);
  argumentTypes.add(labelType);
  argumentTypes.add(labelType);
  equalLabelsPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,true);
  argumentTypes=new ArrayList<>(3);
  argumentTypes.add(instanceType);
  argumentTypes.add(classifierType);
  argumentTypes.add(labelType);
  labelPredictionPredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,false);
  argumentTypes=new ArrayList<>(2);
  argumentTypes.add(classifierType);
  argumentTypes.add(labelType);
  errorRatePredicate=logicManager.addPredicate("String_Node_Str",argumentTypes,false);
  if (logProgress)   logger.info("String_Node_Str");
  Variable instanceVariable=new Variable(0,"String_Node_Str",instanceType);
  Variable classifierVariable=new Variable(1,"String_Node_Str",classifierType);
  Variable label1Variable=new Variable(2,"String_Node_Str",labelType);
  Variable label2Variable=new Variable(3,"String_Node_Str",labelType);
  double power=2;
  double weight=1;
  List<Formula> bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(mutualExclusionPredicate,Arrays.asList(label1Variable,label2Variable)));
  bodyFormulas.add(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable)));
  bodyFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label2Variable)));
  bodyFormulas.add(new Negation(new Atom(equalLabelsPredicate,Arrays.asList(label1Variable,label2Variable))));
  List<Formula> headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(subsumptionPredicate,Arrays.asList(label1Variable,label2Variable)));
  bodyFormulas.add(new Negation(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable))));
  bodyFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label2Variable)));
  bodyFormulas.add(new Negation(new Atom(equalLabelsPredicate,Arrays.asList(label1Variable,label2Variable))));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable)));
  bodyFormulas.add(new Negation(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable))));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable)));
  bodyFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Negation(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable))));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Negation(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable))));
  bodyFormulas.add(new Negation(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable))));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Negation(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable))));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  power=2;
  weight=1;
  bodyFormulas=new ArrayList<>();
  bodyFormulas.add(new Negation(new Atom(labelPredictionPredicate,Arrays.asList(instanceVariable,classifierVariable,label1Variable))));
  bodyFormulas.add(new Atom(errorRatePredicate,Arrays.asList(classifierVariable,label1Variable)));
  headFormulas=new ArrayList<>();
  headFormulas.add(new Atom(labelPredicate,Arrays.asList(instanceVariable,label1Variable)));
  pslBuilder.addLogicRule(new ProbabilisticSoftLogic.LogicRule(bodyFormulas,headFormulas,power,weight));
  if (logProgress)   logger.info("String_Node_Str");
  labels.forEach(label -> logicManager.addGroundPredicate(equalLabelsPredicate,Arrays.asList(labelKeysMap.inverse().get(label),labelKeysMap.inverse().get(label)),1.0));
  for (  Constraint constraint : constraints) {
    if (constraint instanceof MutualExclusionConstraint) {
      List<Label> labelsList=new ArrayList<>(((MutualExclusionConstraint)constraint).getLabels());
      for (int label1Index=0; label1Index < labelsList.size(); label1Index++)       for (int label2Index=0; label2Index < labelsList.size(); label2Index++)       if (label1Index != label2Index)       logicManager.addGroundPredicate(mutualExclusionPredicate,Arrays.asList(labelKeysMap.inverse().get(labelsList.get(label1Index)),labelKeysMap.inverse().get(labelsList.get(label2Index))),1.0);
    }
 else     if (constraint instanceof SubsumptionConstraint) {
      Label parentLabel=((SubsumptionConstraint)constraint).getParentLabel();
      Label childLabel=((SubsumptionConstraint)constraint).getChildLabel();
      logicManager.addGroundPredicate(subsumptionPredicate,Arrays.asList(labelKeysMap.inverse().get(parentLabel),labelKeysMap.inverse().get(childLabel)),1.0);
    }
  }
  if (builder.observedData != null)   for (  Integrator.Data.ObservedInstance instance : builder.observedData)   logicManager.addOrReplaceGroundPredicate(labelPredicate,Arrays.asList(instanceKeysMap.inverse().get(instance.instanceId()),labelKeysMap.inverse().get(instance.label())),instance.value() ? 1.0 : 0.0);
  if (logProgress) {
    logger.info("String_Node_Str" + data.stream().filter(i -> i.value() >= 0.5).count());
    logger.info("String_Node_Str" + data.stream().filter(i -> i.value() < 0.5).count());
  }
  for (  Integrator.Data.PredictedInstance instance : data) {
    List<GroundPredicate> mutualExclusionRulePredicates=new ArrayList<>(4);
    List<GroundPredicate> subsumptionRulePredicates=new ArrayList<>(4);
    List<GroundPredicate> ensembleRulePredicates=new ArrayList<>(3);
    List<GroundPredicate> majorityVotePriorRulePredicates=new ArrayList<>(2);
    List<Long> assignment=new ArrayList<>(3);
    assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
    assignment.add(classifierKeysMap.inverse().get(instance.classifierId()));
    assignment.add(labelKeysMap.inverse().get(instance.label()));
    if (logicManager.checkIfGroundPredicateExists(labelPredictionPredicate,assignment))     continue;
    GroundPredicate predictionPredicate=logicManager.addGroundPredicate(labelPredictionPredicate,assignment,instance.value());
    mutualExclusionRulePredicates.add(predictionPredicate);
    subsumptionRulePredicates.add(predictionPredicate);
    ensembleRulePredicates.add(predictionPredicate);
    majorityVotePriorRulePredicates.add(predictionPredicate);
    assignment=new ArrayList<>(2);
    assignment.add(classifierKeysMap.inverse().get(instance.classifierId()));
    assignment.add(labelKeysMap.inverse().get(instance.label()));
    GroundPredicate errorPredicate=logicManager.addGroundPredicate(errorRatePredicate,assignment,null);
    mutualExclusionRulePredicates.add(errorPredicate);
    subsumptionRulePredicates.add(errorPredicate);
    ensembleRulePredicates.add(errorPredicate);
    assignment=new ArrayList<>(2);
    assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
    assignment.add(labelKeysMap.inverse().get(instance.label()));
    GroundPredicate integratedLabelPredicate=logicManager.addGroundPredicate(labelPredicate,assignment,null);
    ensembleRulePredicates.add(integratedLabelPredicate);
    majorityVotePriorRulePredicates.add(integratedLabelPredicate);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{true,false,false},2,1);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{true,true,true},2,1);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{false,false,true},2,1);
    pslBuilder.addRule(ensembleRulePredicates,new boolean[]{false,true,false},2,1);
    pslBuilder.addRule(majorityVotePriorRulePredicates,new boolean[]{true,false},2,1);
    pslBuilder.addRule(majorityVotePriorRulePredicates,new boolean[]{false,true},2,1);
    for (    Constraint constraint : constraints) {
      if (constraint instanceof MutualExclusionConstraint) {
        List<Label> labelsList=new ArrayList<>(((MutualExclusionConstraint)constraint).getLabels());
        if (labelsList.contains(instance.label())) {
          for (          Label label : labelsList.stream().filter(l -> !l.equals(instance.label())).collect(Collectors.toList())) {
            List<GroundPredicate> mutualExclusionRulePredicatesCopy=new ArrayList<>(mutualExclusionRulePredicates);
            assignment=new ArrayList<>(2);
            assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
            assignment.add(labelKeysMap.inverse().get(label));
            if (logicManager.checkIfGroundPredicateExists(labelPredicate,assignment))             mutualExclusionRulePredicatesCopy.add(logicManager.getGroundPredicate(labelPredicate,assignment));
 else             mutualExclusionRulePredicatesCopy.add(logicManager.addGroundPredicate(labelPredicate,assignment,null));
            assignment=new ArrayList<>(2);
            assignment.add(labelKeysMap.inverse().get(instance.label()));
            assignment.add(labelKeysMap.inverse().get(label));
            mutualExclusionRulePredicatesCopy.add(logicManager.getGroundPredicate(mutualExclusionPredicate,assignment));
            pslBuilder.addRule(mutualExclusionRulePredicatesCopy,new boolean[]{true,false,true,true},2,1);
          }
        }
      }
 else       if (constraint instanceof SubsumptionConstraint) {
        if (((SubsumptionConstraint)constraint).getParentLabel().equals(instance.label())) {
          Label childLabel=((SubsumptionConstraint)constraint).getChildLabel();
          List<GroundPredicate> subsumptionRulePredicatesCopy=new ArrayList<>(subsumptionRulePredicates);
          assignment=new ArrayList<>(2);
          assignment.add(instanceKeysMap.inverse().get(instance.instanceId()));
          assignment.add(labelKeysMap.inverse().get(childLabel));
          if (logicManager.checkIfGroundPredicateExists(labelPredicate,assignment))           subsumptionRulePredicatesCopy.add(logicManager.getGroundPredicate(labelPredicate,assignment));
 else           subsumptionRulePredicatesCopy.add(logicManager.addGroundPredicate(labelPredicate,assignment,null));
          assignment=new ArrayList<>(2);
          assignment.add(labelKeysMap.inverse().get(instance.label()));
          assignment.add(labelKeysMap.inverse().get(childLabel));
          subsumptionRulePredicatesCopy.add(logicManager.getGroundPredicate(subsumptionPredicate,assignment));
          pslBuilder.addRule(subsumptionRulePredicatesCopy,new boolean[]{false,false,true,true},2,1);
        }
      }
    }
  }
  psl=pslBuilder.build(false);
}