Package org.optaplanner.core.api.score.constraint.primlong

Examples of org.optaplanner.core.api.score.constraint.primlong.LongConstraintMatchTotal


    }

    @Override
    public Collection<ConstraintMatchTotal> getConstraintMatchTotals() {
        List<Resource> resourceList = cheapTimeSolution.getResourceList();
        LongConstraintMatchTotal resourceCapacityMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "resourceCapacity", 0);
        LongConstraintMatchTotal spinUpDownMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "spinUpDown", 1);
        LongConstraintMatchTotal machineConsumptionMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "machineConsumption", 1);
        LongConstraintMatchTotal taskConsumptionMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "taskConsumption", 1);
        LongConstraintMatchTotal minimizeTaskStartPeriodMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "minimizeTaskStartPeriod", 2);
        for (Machine machine : cheapTimeSolution.getMachineList()) {
            for (int period = 0; period < globalPeriodRangeTo; period++) {
                MachinePeriodPart machinePeriod = machineToMachinePeriodListMap[machine.getIndex()][period];
                for (int i = 0; i < machinePeriod.resourceAvailableList.length; i++) {
                    int resourceAvailable = machinePeriod.resourceAvailableList[i];
                    if (resourceAvailable < 0) {
                        resourceCapacityMatchTotal.addConstraintMatch(
                                Arrays.<Object>asList(machine, period, resourceList.get(i)),
                                resourceAvailable);
                    }
                }
                if (machinePeriod.status == MachinePeriodStatus.SPIN_UP_AND_ACTIVE) {
                    spinUpDownMatchTotal.addConstraintMatch(
                            Arrays.<Object>asList(machine, period),
                            - machine.getSpinUpDownCostMicros());
                }
                if (machinePeriod.status != MachinePeriodStatus.OFF) {
                    machineConsumptionMatchTotal.addConstraintMatch(
                            Arrays.<Object>asList(machine, period),
                            - machinePeriod.machineCostMicros);
                }
            }
        }
        // Individual taskConsumption isn't tracked for performance
        taskConsumptionMatchTotal.addConstraintMatch(Arrays.<Object>asList(),
                mediumScore - spinUpDownMatchTotal.getWeightTotal() - machineConsumptionMatchTotal.getWeightTotal());
        // Individual taskStartPeriod isn't tracked for performance
        // but we mimic it
        for (TaskAssignment taskAssignment : cheapTimeSolution.getTaskAssignmentList()) {
            Integer startPeriod = taskAssignment.getStartPeriod();
            if (startPeriod != null) {
                minimizeTaskStartPeriodMatchTotal.addConstraintMatch(Arrays.<Object>asList(taskAssignment),
                        - startPeriod);
            }

        }
View Full Code Here


    private LongConstraintMatchTotal findLongConstraintMatchTotal(RuleContext kcontext, int scoreLevel) {
        Rule rule = kcontext.getRule();
        String constraintPackage = rule.getPackageName();
        String constraintName = rule.getName();
        List<Object> key = Arrays.<Object>asList(constraintPackage, constraintName, scoreLevel);
        LongConstraintMatchTotal matchTotal = (LongConstraintMatchTotal) constraintMatchTotalMap.get(key);
        if (matchTotal == null) {
            matchTotal = new LongConstraintMatchTotal(constraintPackage, constraintName, scoreLevel);
            constraintMatchTotalMap.put(key, matchTotal);
        }
        return matchTotal;
    }
View Full Code Here

        // ignore constraintMatchEnabled, it is always presumed enabled
    }

    @Override
    public Collection<ConstraintMatchTotal> getConstraintMatchTotals() {
        LongConstraintMatchTotal maximumCapacityMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "maximumCapacity", 0);
        LongConstraintMatchTotal serviceConflictMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "serviceConflict", 0);
        LongConstraintMatchTotal serviceLocationSpreadMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "serviceLocationSpread", 0);
        LongConstraintMatchTotal serviceDependencyMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "serviceDependency", 0);
        LongConstraintMatchTotal loadCostMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "loadCost", 1);
        LongConstraintMatchTotal balanceCostMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "balanceCost", 1);
        LongConstraintMatchTotal processMoveCostMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "processMoveCost", 1);
        LongConstraintMatchTotal serviceMoveCostMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "serviceMoveCost", 1);
        LongConstraintMatchTotal machineMoveCostMatchTotal = new LongConstraintMatchTotal(
                CONSTRAINT_PACKAGE, "machineMoveCost", 1);

        for (MrServiceScorePart serviceScorePart : serviceScorePartMap.values()) {
            MrService service = serviceScorePart.service;
            if (service.getLocationSpread() > serviceScorePart.locationBag.size()) {
                serviceLocationSpreadMatchTotal.addConstraintMatch(
                        Arrays.<Object>asList(service),
                        - (service.getLocationSpread() - serviceScorePart.locationBag.size()));
            }
        }
        for (MrMachineScorePart machineScorePart : machineScorePartMap.values()) {
            for (MrMachineCapacityScorePart machineCapacityScorePart : machineScorePart.machineCapacityScorePartList) {
                if (machineCapacityScorePart.maximumAvailable < 0L) {
                    maximumCapacityMatchTotal.addConstraintMatch(
                            Arrays.<Object>asList(machineCapacityScorePart.machineCapacity),
                            machineCapacityScorePart.maximumAvailable);
                }
                if (machineCapacityScorePart.safetyAvailable < 0L) {
                    loadCostMatchTotal.addConstraintMatch(
                            Arrays.<Object>asList(machineCapacityScorePart.machineCapacity),
                            machineCapacityScorePart.safetyAvailable
                                    * machineCapacityScorePart.machineCapacity.getResource().getLoadCostWeight());
                }
            }
            for (MrBalancePenalty balancePenalty : machineReassignment.getBalancePenaltyList()) {
                long originAvailable = machineScorePart.machineCapacityScorePartList
                        .get(balancePenalty.getOriginResource().getIndex()).getBalanceAvailable();
                long targetAvailable = machineScorePart.machineCapacityScorePartList
                        .get(balancePenalty.getTargetResource().getIndex()).getBalanceAvailable();
                if (originAvailable > 0L) {
                    long minimumTargetAvailable = originAvailable * balancePenalty.getMultiplicand();
                    // targetAvailable might be negative, but that's ok (and even avoids score traps)
                    if (targetAvailable < minimumTargetAvailable) {
                        balanceCostMatchTotal.addConstraintMatch(
                                Arrays.<Object>asList(machineScorePart.machine, balancePenalty),
                                - (minimumTargetAvailable - targetAvailable) * balancePenalty.getWeight());
                    }
                }
            }
            for (Map.Entry<MrService, Integer> entry : machineScorePart.serviceBag.entrySet()) {
                int serviceProcessCount = entry.getValue();
                serviceConflictMatchTotal.addConstraintMatch(
                        Arrays.<Object>asList(entry.getKey()),
                        - (serviceProcessCount - 1));

            }
        }
        for (MrProcessAssignment processAssignment : machineReassignment.getProcessAssignmentList()) {
            for (MrService toDependencyService : processAssignment.getService().getToDependencyServiceList()) {
                int toDependencyNeighborhoodProcessCount = serviceScorePartMap.get(toDependencyService)
                        .neighborhoodBag.get(processAssignment.getNeighborhood());
                if (toDependencyNeighborhoodProcessCount == 0) {
                    serviceDependencyMatchTotal.addConstraintMatch(
                            Arrays.<Object>asList(processAssignment, toDependencyService),
                            - 1);
                }
            }
            if (processAssignment.isMoved()) {
                processMoveCostMatchTotal.addConstraintMatch(
                        Arrays.<Object>asList(processAssignment),
                        - (processAssignment.getProcessMoveCost() * globalPenaltyInfo.getProcessMoveCostWeight()));
                machineMoveCostMatchTotal.addConstraintMatch(
                        Arrays.<Object>asList(processAssignment),
                        - (processAssignment.getMachineMoveCost() * globalPenaltyInfo.getMachineMoveCostWeight()));
            }
        }
        for (int i = 0; i < serviceMoveCost; i++) {
View Full Code Here

TOP

Related Classes of org.optaplanner.core.api.score.constraint.primlong.LongConstraintMatchTotal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.