You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a scenario where I need to allocate jobs to resources and determine the number of jobs in each resource.
I defined a class Allocation that generates a list of Allocation objects by taking the Cartesian product of the jobs and resources. Allocation has a planning variable allocatedQty, which is the quantity of jobs a resource should handle. This variable's value (which I define as quantityRange) ranges from 0 to the quantity of jobs. The code snippet for the Allocation class is as follows:
@PlanningEntity
public class Allocation extends AbstractPersistable {
@PlanningId
private Long id;
private Job job;
private Resource resource;
@PlanningVariable(valueRangeProviderRefs = {"qtyRange"})
private Integer allocatedQty;
@ValueRangeProvider(id = "qtyRange")
private List<Integer> quantityRange;
public Allocation() {
}
public Allocation(Long id, String code, Job job, Resource resource) {
this.id = id;
this.job = job;
this.resource = resource;
this.createQuantityRange();
}
// create the quantity range
private void createQuantityRange() {
int lowBound = 0;
int upBound = this.job.getQuantity();
this.quantityRange = IntStream.rangeClosed(lowBound, upBound)
.boxed()
.collect(Collectors.toList());
}
.
.
.
}
I have only two constraints: "Ensure that the sum of the quantities of a job allocated to each resource equals the quantity of jobs" - method name "jobQuantityAlignment".
And another constraint is "Make the quantities of a job allocated to each resource as balanced as possible" - method name "resourceQuantityBalance".
The code for these two constraints is as follows:
For instance, there are 2 jobs, Job A with quantity 10, and Job B with quantity 20.
And there are 3 resources: Resource 1, Resource 2, Resource 3, and Resource 4.
For Job A, the resources that can be allocated are Resource 1 and Resource 2.
For Job B, the available resources are Resource 3 and Resource 4. This will result in four allocations:
Allocation A1 - from Job A and Resource 1, with a quantity range of 0 to 10
Allocation A2 - from Job A and Resource 2, with a quantity range of 0 to 10
Allocation B3 - from Job B and Resource 3, with a quantity range of 0 to 20
Allocation B4 - from Job B and Resource 4, with a quantity range of 0 to 20
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, everyone!
I have a scenario where I need to allocate jobs to resources and determine the number of jobs in each resource.
I defined a class
Allocationthat generates a list ofAllocationobjects by taking the Cartesian product of the jobs and resources.Allocationhas a planning variableallocatedQty, which is the quantity of jobs a resource should handle. This variable's value (which I define asquantityRange) ranges from 0 to the quantity of jobs. The code snippet for theAllocationclass is as follows:I have only two constraints: "Ensure that the sum of the quantities of a job allocated to each resource equals the quantity of jobs" - method name "jobQuantityAlignment".
And another constraint is "Make the quantities of a job allocated to each resource as balanced as possible" - method name "resourceQuantityBalance".
The code for these two constraints is as follows:
For instance, there are 2 jobs, Job A with quantity 10, and Job B with quantity 20.
And there are 3 resources: Resource 1, Resource 2, Resource 3, and Resource 4.
For Job A, the resources that can be allocated are Resource 1 and Resource 2.
For Job B, the available resources are Resource 3 and Resource 4. This will result in four allocations:
Allocation A1 - from Job A and Resource 1, with a quantity range of 0 to 10
Allocation A2 - from Job A and Resource 2, with a quantity range of 0 to 10
Allocation B3 - from Job B and Resource 3, with a quantity range of 0 to 20
Allocation B4 - from Job B and Resource 4, with a quantity range of 0 to 20
My desired solution is:
Allocation A1: 5
Allocation A2: 5
Allocation B3: 10
Allocation B4: 10
But now, the solution is:
Allocation A1: 10
Allocation A2: 0
Allocation B3: 20
Allocation B4: 0
The log looks like this:
Why is this? The resourceQuantityBalance score has been consistently difficult to optimize.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions