public void linkShadowSources(DescriptorPolicy descriptorPolicy) {
   CustomShadowVariable shadowVariableAnnotation =
       variableMemberAccessor.getAnnotation(CustomShadowVariable.class);
   SolutionDescriptor solutionDescriptor = entityDescriptor.getSolutionDescriptor();
   CustomShadowVariable.Source[] sources = shadowVariableAnnotation.sources();
   sourceVariableDescriptorList = new ArrayList<VariableDescriptor>(sources.length);
   for (CustomShadowVariable.Source source : sources) {
     EntityDescriptor sourceEntityDescriptor;
     Class<?> sourceEntityClass = source.entityClass();
     if (sourceEntityClass.equals(CustomShadowVariable.Source.NullEntityClass.class)) {
       sourceEntityDescriptor = entityDescriptor;
     } else {
       sourceEntityDescriptor = solutionDescriptor.findEntityDescriptor(sourceEntityClass);
       if (sourceEntityDescriptor == null) {
         throw new IllegalArgumentException(
             "The entityClass ("
                 + entityDescriptor.getEntityClass()
                 + ") has a "
                 + CustomShadowVariable.class.getSimpleName()
                 + " annotated property ("
                 + variableMemberAccessor.getName()
                 + ") with a sourceEntityClass ("
                 + sourceEntityClass
                 + ") which is not a valid planning entity.");
       }
     }
     String sourceVariableName = source.variableName();
     VariableDescriptor sourceVariableDescriptor =
         sourceEntityDescriptor.getVariableDescriptor(sourceVariableName);
     if (sourceVariableDescriptor == null) {
       throw new IllegalArgumentException(
           "The entityClass ("
               + entityDescriptor.getEntityClass()
               + ") has a "
               + CustomShadowVariable.class.getSimpleName()
               + " annotated property ("
               + variableMemberAccessor.getName()
               + ") with sourceVariableName ("
               + sourceVariableName
               + ") which is not a valid planning variable on entityClass ("
               + sourceEntityDescriptor.getEntityClass()
               + ").\n"
               + entityDescriptor.buildInvalidVariableNameExceptionMessage(sourceVariableName));
     }
     sourceVariableDescriptor.registerShadowVariableDescriptor(this);
     sourceVariableDescriptorList.add(sourceVariableDescriptor);
   }
 }
예제 #2
0
  public static <Solution_> PartitionChangeMove<Solution_> createMove(
      InnerScoreDirector<Solution_> scoreDirector) {
    SolutionDescriptor<Solution_> solutionDescriptor = scoreDirector.getSolutionDescriptor();
    Solution_ workingSolution = scoreDirector.getWorkingSolution();

    int entityCount = solutionDescriptor.getEntityCount(workingSolution);
    Map<GenuineVariableDescriptor<Solution_>, List<Pair<Object, Object>>> changeMap =
        new LinkedHashMap<>(solutionDescriptor.getEntityDescriptors().size() * 3);
    for (EntityDescriptor<Solution_> entityDescriptor : solutionDescriptor.getEntityDescriptors()) {
      for (GenuineVariableDescriptor<Solution_> variableDescriptor :
          entityDescriptor.getDeclaredGenuineVariableDescriptors()) {
        changeMap.put(variableDescriptor, new ArrayList<>(entityCount));
      }
    }
    for (Iterator<Object> it = solutionDescriptor.extractAllEntitiesIterator(workingSolution);
        it.hasNext(); ) {
      Object entity = it.next();
      EntityDescriptor<Solution_> entityDescriptor =
          solutionDescriptor.findEntityDescriptorOrFail(entity.getClass());
      if (entityDescriptor.isMovable(scoreDirector, entity)) {
        for (GenuineVariableDescriptor<Solution_> variableDescriptor :
            entityDescriptor.getGenuineVariableDescriptors()) {
          Object value = variableDescriptor.getValue(entity);
          changeMap.get(variableDescriptor).add(Pair.of(entity, value));
        }
      }
    }
    return new PartitionChangeMove<>(changeMap);
  }
예제 #3
0
 public Solution cloneSolution(Solution originalSolution) {
   SolutionDescriptor solutionDescriptor = getSolutionDescriptor();
   Solution cloneSolution = solutionDescriptor.getSolutionCloner().cloneSolution(originalSolution);
   if (scoreDirectorFactory.isAssertClonedSolution()) {
     if (!ObjectUtils.equals(originalSolution.getScore(), cloneSolution.getScore())) {
       throw new IllegalStateException(
           "Cloning corruption: "
               + "the original's score ("
               + originalSolution.getScore()
               + ") is different from the clone's score ("
               + cloneSolution.getScore()
               + ").\n"
               + "Check the "
               + SolutionCloner.class.getSimpleName()
               + ".");
     }
     List<Object> originalEntityList = solutionDescriptor.getEntityList(originalSolution);
     Map<Object, Object> originalEntityMap =
         new IdentityHashMap<Object, Object>(originalEntityList.size());
     for (Object originalEntity : originalEntityList) {
       originalEntityMap.put(originalEntity, null);
     }
     for (Object cloneEntity : solutionDescriptor.getEntityList(cloneSolution)) {
       if (originalEntityMap.containsKey(cloneEntity)) {
         throw new IllegalStateException(
             "Cloning corruption: "
                 + "the same entity ("
                 + cloneEntity
                 + ") is present in both the original and the clone.\n"
                 + "So when a planning variable in the original solution changes, "
                 + "the cloned solution will change too.\n"
                 + "Check the "
                 + SolutionCloner.class.getSimpleName()
                 + ".");
       }
     }
   }
   return cloneSolution;
 }
예제 #4
0
 public static EntityDescriptor buildEntityDescriptor() {
   SolutionDescriptor solutionDescriptor = TestdataChainedSolution.buildSolutionDescriptor();
   return solutionDescriptor.getEntityDescriptor(TestdataChainedEntity.class);
 }
 public static SolutionDescriptor buildSolutionDescriptor() {
   return SolutionDescriptor.buildSolutionDescriptor(
       TestdataNullableSolution.class, TestdataNullableEntity.class);
 }
예제 #6
0
 public static PlanningEntityDescriptor buildEntityDescriptor() {
   SolutionDescriptor solutionDescriptor = TestdataMultiEntitySolution.buildSolutionDescriptor();
   return solutionDescriptor.getEntityDescriptor(TestdataHerdEntity.class);
 }
 @Override
 public ScoreDefinition getScoreDefinition() {
   return solutionDescriptor.getScoreDefinition();
 }
예제 #8
0
 public static EntityDescriptor buildEntityDescriptor() {
   SolutionDescriptor solutionDescriptor =
       TestdataEntityCollectionPropertySolution.buildSolutionDescriptor();
   return solutionDescriptor.findEntityDescriptorOrFail(
       TestdataEntityCollectionPropertyEntity.class);
 }