Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests and improve executor shutdown documentation
- Loading branch information
Showing
3 changed files
with
219 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...rc/test/java/org/optaplanner/core/impl/partitionedsearch/TestdataSolutionPartitioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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. | ||
*/ | ||
package org.optaplanner.core.impl.partitionedsearch; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.optaplanner.core.impl.partitionedsearch.partitioner.SolutionPartitioner; | ||
import org.optaplanner.core.impl.score.director.ScoreDirector; | ||
import org.optaplanner.core.impl.testdata.domain.TestdataEntity; | ||
import org.optaplanner.core.impl.testdata.domain.TestdataSolution; | ||
|
||
public class TestdataSolutionPartitioner implements SolutionPartitioner<TestdataSolution> { | ||
|
||
/** | ||
* {@link PartitionedSearchPhaseConfig#solutionPartitionerCustomProperties Custom property}. | ||
*/ | ||
private int partSize = 1; | ||
|
||
public void setPartSize(int partSize) { | ||
this.partSize = partSize; | ||
} | ||
|
||
@Override | ||
public List<TestdataSolution> splitWorkingSolution(ScoreDirector<TestdataSolution> scoreDirector, | ||
Integer runnablePartThreadLimit) { | ||
TestdataSolution workingSolution = scoreDirector.getWorkingSolution(); | ||
List<TestdataEntity> allEntities = workingSolution.getEntityList(); | ||
if (allEntities.size() % partSize > 0) { | ||
throw new IllegalStateException("This partitioner can only make equally sized partitions."); | ||
} | ||
List<TestdataSolution> partitions = new ArrayList<>(); | ||
for (int i = 0; i < allEntities.size() / partSize; i++) { | ||
List<TestdataEntity> partitionEntitites | ||
= new ArrayList<>(allEntities.subList(i * partSize, (i + 1) * partSize)); | ||
TestdataSolution partition = new TestdataSolution(); | ||
partition.setEntityList(partitionEntitites); | ||
partition.setValueList(workingSolution.getValueList()); | ||
partitions.add(partition); | ||
} | ||
return partitions; | ||
} | ||
|
||
} |