本文整理汇总了Java中org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore类的典型用法代码示例。如果您正苦于以下问题:Java HardSoftScore类的具体用法?Java HardSoftScore怎么用?Java HardSoftScore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HardSoftScore类属于org.optaplanner.core.api.score.buildin.hardsoft包,在下文中一共展示了HardSoftScore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateScore
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
public Score calculateScore(ProblemDefinition problemDefinition, int initScore) {
Set<Employee> employees = problemDefinition.getEmployees();
Set<Task> tasks = problemDefinition.getTasks();
Set<Task> assignedTasks = new HashSet<Task>();
int hardScore = 0;
int softScore = 0;
for (Employee employee : employees) {
if (employee.getTask() == null) {
softScore++; //unassigned employee
} else {
assignedTasks.add(employee.getTask());
if ((!employee.canDeliver(employee.getTask()))) {
softScore++; //skill mismatch
}
}
}
int unassignedTasks = tasks.size() - assignedTasks.size();
hardScore += 5 * unassignedTasks; // tasks left unassigned
HardSoftScore hardSoftScore = HardSoftScore.valueOf(initScore, -hardScore, -softScore);
return hardSoftScore;
}
示例2: validateIsAPlanningScore
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
@Test
public void validateIsAPlanningScore() {
DataObject dataObject = new DataObjectImpl("test",
"PlanningSolution");
dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class)));
ObjectProperty objectProperty = new ObjectPropertyImpl("score",
HardSoftScore.class.getName(),
false);
objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningScore.class)));
objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Generated.class)));
Collection<ValidationMessage> result = deleteValidator.validate(dataObject,
objectProperty);
assertEquals(1,
result.size());
assertTrue(result.iterator().next() instanceof PlanningScoreToBeDeletedMessage);
}
示例3: scoreHolderTypeNotRecognized
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
@Test
public void scoreHolderTypeNotRecognized() {
Path dataObjectPath = PathFactory.newPath("Test.java",
"file:///dataObjects");
when(ioService.readAllString(Paths.convert(dataObjectPath))).thenReturn("testResult");
DataObject originalDataObject = createDataObject(HardSoftScore.class);
GenerationResult generationResult = new GenerationResult();
generationResult.setDataObject(originalDataObject);
when(dataModelerService.loadDataObject(any(),
anyString(),
any())).thenReturn(generationResult);
when(scoreHolderUtils.extractScoreTypeFqn(originalDataObject)).thenReturn(HardSoftScore.class.getName());
when(scoreHolderUtils.getScoreHolderTypeFqn(HardSoftScore.class.getName())).thenReturn(HardSoftScoreHolder.class.getName());
when(assetsUsageService.getAssetUsages(HardSoftScoreHolder.class.getName(),
ResourceType.JAVA, dataObjectPath)).thenReturn(Arrays.asList(mock(Path.class)));
DataObject updatedDataObject = createDataObject(SimpleScore.class);
when(scoreHolderUtils.extractScoreTypeFqn(updatedDataObject)).thenReturn("UnknownScoreClassName");
when(scoreHolderUtils.getScoreHolderTypeFqn("UnknownScoreClassName")).thenReturn(null);
}
示例4: recomputeScore
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
@Override
public ScoreResult recomputeScore(String cluster, Result oldResult) {
ClusterOptimizer clusterOptimizer;
clusterOptimizer = clusterOptimizers.get(cluster);
if (clusterOptimizer == null) {
log.error(String.format("Cluster %s does not exist", cluster));
return null;
}
ScoreResult scoreResult = new ScoreResult();
HardSoftScore score = clusterOptimizer.computeScore(oldResult);
scoreResult.setHardScore(score.getHardScore());
scoreResult.setSoftScore(score.getSoftScore());
return scoreResult;
}
示例5: testStartPinnedVm
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test whether a pinned to host VM can be started
*/
@Test
public void testStartPinnedVm() {
TestOptimizer optimizer = new TestOptimizer(EnumSet.noneOf(ClusterFeatures.class));
Host host = optimizer.createHost("H1", 1000000000L);
VM vm = optimizer.createVm("VM-A", 10000000L);
vm.getPlacementPolicy().setHost(host);
vm.getPlacementPolicy().setAffinity("pinned");
HardSoftScore result = optimizer
.startVm(vm)
.addMigration(vm, host)
.enablePolicyUnit(PolicyUnit.PIN_TO_HOST_FILTER)
.score();
assertEquals(0, result.getHardScore());
}
示例6: testStartPinnedVmOnWrongHost
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test whether a pinned to host VM can be started on different host
*/
@Test
public void testStartPinnedVmOnWrongHost() {
TestOptimizer optimizer = new TestOptimizer(EnumSet.noneOf(ClusterFeatures.class));
Host host = optimizer.createHost("H1", 1000000000L);
Host host2 = optimizer.createHost("H2", 1000000000L);
VM vm = optimizer.createVm("VM-A", 10000000L);
vm.getPlacementPolicy().setHost(host);
vm.getPlacementPolicy().setAffinity("pinned");
HardSoftScore result = optimizer
.startVm(vm)
.addMigration(vm, host2)
.enablePolicyUnit(PolicyUnit.PIN_TO_HOST_FILTER)
.score();
assertNotEquals(0, result.getHardScore());
}
示例7: testMigratePinnedVm
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test whether a pinned to host VM can't be migrated
*/
@Test
public void testMigratePinnedVm() {
TestOptimizer optimizer = new TestOptimizer(EnumSet.noneOf(ClusterFeatures.class));
Host host1 = optimizer.createHost("H1", 1000000000L);
Host host2 = optimizer.createHost("H2", 1000000000L);
VM vm = optimizer.createVm("VM-A", 10000000L);
vm.getPlacementPolicy().setHost(host1);
vm.getPlacementPolicy().setAffinity("pinned");
vm.setHost(host1);
HardSoftScore result = optimizer
.addMigration(vm, host2)
.enablePolicyUnit(PolicyUnit.PIN_TO_HOST_FILTER)
.score();
assertNotEquals(0, result.getHardScore());
}
示例8: testStartHugeVm
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test whether a VM can't be started when it does not fit
*/
@Test
public void testStartHugeVm() {
TestOptimizer optimizer = new TestOptimizer(EnumSet.noneOf(ClusterFeatures.class));
Host host = optimizer.createHost("H1", 1000L);
VM vm = optimizer.createVm("VM-A", 10000000L);
HardSoftScore result = optimizer
.startVm(vm)
.addMigration(vm, host)
.enablePolicyUnit(PolicyUnit.MEMORY_FILTER)
.score();
assertNotEquals(0, result.getHardScore());
}
示例9: testUnexpectedStart
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test whether a VM in Down state can't be started without user's request
*/
@Test
public void testUnexpectedStart() {
TestOptimizer optimizer = new TestOptimizer(EnumSet.noneOf(ClusterFeatures.class));
Host host1 = optimizer.createHost("H1", 1000000000L);
Host host2 = optimizer.createHost("H2", 1000000000L);
VM vm1 = optimizer.createVm("VM-A", 10000000L);
vm1.setHost(host1);
vm1.setStatus(new Status());
vm1.getStatus().setState("UP");
VM vm2 = optimizer.createVm("VM-B", 10000000L);
vm2.setStatus(new Status());
vm2.getStatus().setState("DOWN");
HardSoftScore result = optimizer
.addMigration(vm2, host2)
.score();
assertNotEquals(0, result.getHardScore());
}
示例10: testHERulesWithoutHE
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test HE rules for NPEs.
*/
@Test
public void testHERulesWithoutHE() {
TestOptimizer optimizer = new TestOptimizer(EnumSet.noneOf(ClusterFeatures.class));
Host host1 = optimizer.createHost("H1", 1000000000L);
Host host2 = optimizer.createHost("H2", 1000000000L);
VM vm1 = optimizer.createVm("VM-A", 10000000L);
vm1.setHost(host1);
vm1.setStatus(new Status());
vm1.getStatus().setState("UP");
vm1.setOrigin("hostedEngine");
HardSoftScore result = optimizer
.enablePolicyUnit(PolicyUnit.HOSTED_ENGINE_FILTER)
.enablePolicyUnit(PolicyUnit.HOSTED_ENGINE_WEIGHT)
.addMigration(vm1, host2)
.score();
// destination host is not HE enabled
assertNotEquals(0, result.getHardScore());
// -1 for a single performed migration
assertEquals(-1, result.getSoftScore());
}
示例11: testNotEnoughCores
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
/**
* Test whether VM can be run on host with enough cores and
* cannot be run on host with not enough cores
*/
@Test
public void testNotEnoughCores(){
TestOptimizer optimizer = new TestOptimizer();
Host host = optimizer.createHost("H1", 1000000000L);
host.getCpu().getTopology().setSockets(1);
host.getCpu().getTopology().setCores(2);
VM vm = optimizer.createVm("VM-A", 10000000L);
vm.getCpu().getTopology().setSockets(1);
vm.getCpu().getTopology().setCores(2);
optimizer.enablePolicyUnit(PolicyUnit.CPU_FILTER)
.startVm(vm)
.addMigration(vm,host);
HardSoftScore r1 = optimizer.score();
vm.getCpu().getTopology().setCores(4);
HardSoftScore r2 = optimizer.score();
assertEquals(0, r1.getHardScore());
assertNotEquals(0, r2.getHardScore());
}
示例12: plan
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
public List<ShiftAssignment> plan() {
SolverFactory<Solution> solverFactory = SolverFactory.createFromXmlResource("planner/EmployeeRosteringSolverConfig.xml");
Solver solver = solverFactory.buildSolver();
EmployeeRoster employeeRoster = new EmployeeRoster();
employeeRoster.setCode("TEST");
employeeRoster.setSkillList(employeeRepository.listSkills());
employeeRoster.setShiftTypeList(shiftRepository.listShiftTypes());
employeeRoster.setShiftTypeSkillRequirementList(generateShiftTypeSkillRequirements());
employeeRoster.setPatternList(patternsRepository.listAll());
employeeRoster.setContractList(contractRepository.listAll());
employeeRoster.setContractLineList(generateContractLines());
employeeRoster.setPatternContractLineList(generateContractPatternList());
employeeRoster.setEmployeeList(employeeRepository.listAll());
employeeRoster.setSkillProficiencyList(generateSkillProficiency());
employeeRoster.setShiftDateList(shiftRepository.listShiftDates());
employeeRoster.setShiftList(shiftRepository.listShifts());
employeeRoster.setDayOffRequestList(employeeRepository.listDayOffRequests());
employeeRoster.setDayOnRequestList(employeeRepository.listDayOnRequests());
employeeRoster.setShiftOffRequestList(employeeRepository.listShiftOffRequests());
employeeRoster.setShiftOnRequestList(employeeRepository.listShiftOnRequests());
employeeRoster.setEmployeeRosterParametrization(generateEmployeeRosterInfo());
employeeRoster.setShiftAssignmentList(generateAssigments());
employeeRoster = (EmployeeRoster) solver.solve(employeeRoster);
final HardSoftScore score = employeeRoster.getScore();
for (ShiftAssignment shiftAssignment : employeeRoster.getShiftAssignmentList()) {
shiftRepository.createShiftAssignment(shiftAssignment.getShift(), shiftAssignment.getEmployee());
}
messageService.informUser(String.format("'%s' score ", score.toString()));
return shiftRepository.listShiftAssignments();
}
示例13: configure
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
@Override
protected void configure() {
type(LocalDate.class).serializer(LocalDateJsonSerializer.class).deserializer(LocalDateJsonDeserializer.class);
type(LocalDateTime.class).serializer(LocalDateTimeJsonSerializer.class).deserializer(
LocalDateTimeJsonDeserializer.class);
type(HardSoftScore.class).serializer(HardSoftScoreJsonSerializer.class).deserializer(
HardSoftScoreJsonDeserializer.class);
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:9,代码来源:OptaShiftRosteringGwtJacksonConfiguration.java
示例14: planningSolutionSettings
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
@Test
public void planningSolutionSettings() {
PlannerDataObjectFieldEditor fieldEditor = createFieldEditor();
//first configure the DataObject as a PlanningSolution
DataObject dataObject = context.getDataObject();
dataObject.addAnnotation(new AnnotationImpl(context.getAnnotationDefinition(PlanningSolution.class.getName())));
dataObject.addProperty("score",
HardSoftScore.class.getName());
ObjectProperty field1 = dataObject.getProperty("field1");
//emulates the selection of field1
context.setObjectProperty(field1);
//The domain editors typically reacts upon DataModelerContext changes.
//when the context changes the editor will typically be reloaded.
fieldEditor.onContextChange(context);
when(view.getValueRangeProviderValue()).thenReturn(true);
when(view.getValueRangeProviderIdValue()).thenReturn("valueRangeProviderIdValue");
//emulate the user input
fieldEditor.onValueRangeProviderChange();
fieldEditor.onValueRangeProviderIdChange();
assertNotNull(field1.getAnnotation(ValueRangeProvider.class.getName()));
assertEquals("valueRangeProviderIdValue",
AnnotationValueHandler.getStringValue(field1,
ValueRangeProvider.class.getName(),
"id"));
}
示例15: getFieldMetadataMatchingField
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; //导入依赖的package包/类
@Test
public void getFieldMetadataMatchingField() {
Annotation planningScoreAnnotation = new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningScore.class));
ObjectProperty matchingField = new ObjectPropertyImpl("matchingField",
HardSoftScore.class.getName(),
false);
matchingField.addAnnotation(planningScoreAnnotation);
Optional<FieldMetadata> fieldMetadata = fieldMetadataProvider.getFieldMetadata(matchingField);
assertTrue(fieldMetadata.isPresent());
}