added license, readme updated, CFLA+ renamed to CFLA2

parent 84384d1c
MIT License
Copyright (c) 2020 ECS Centre for Machine Intelligence
Copyright (c) 2020 Luca Capezzuto
ECS Centre for Machine Intelligence
University of Southampton, UK
Permission is hereby granted, free of charge, to any person obtaining a copy
......@@ -19,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
SOFTWARE.
......@@ -5,8 +5,10 @@
| [Luca Capezzuto](https://lcpz.gitlab.io) | [MIT](https://opensource.org/licenses/MIT) |
Algorithms for solving the Coalition Formation with Spatial and Temporal
constraints Problem ([CFSTP](https://eprints.soton.ac.uk/268497/)) and
extensions.
constraints Problem ([CFSTP](https://eprints.soton.ac.uk/268497/)).
Reference paper: [Anytime and Efficient Coalition Formation with
Spatial and Temporal Constraints](https://easychair.org/publications/preprint/m7hT).
## Dependencies
......@@ -24,8 +26,8 @@ extensions.
## To-do list
- [ ] Test with [RoboCupRescue simulator](https://github.com/roborescue/rcrs-adf-sample)
- [ ] Test with [RMASBench](https://github.com/RMASBench)
- [ ] CCF implementation is unnecessarily quadratic on the number of agents: fix it
- [ ] Merge with [RoboCupRescue simulator](https://github.com/roborescue/rcrs-adf-sample)
- [ ] Test with [MASPlanes](https://github.com/MASPlanes/MASPlanes)
- [ ] Integrate the [XCSP parser](https://github.com/xcsp3team/XCSP3-Java-Tools) (for DCOPs)
- [ ] Use [BURLAP](https://github.com/jmacglashan/burlap)'s [`GridWorld`](https://github.com/jmacglashan/burlap_examples/blob/master/src/main/java/edu/brown/cs/burlap/tutorials/HelloGridWorld.java) for GUI representation (see this [tutorial](http://burlap.cs.brown.edu/tutorials/hgw/p1.html))
......
......@@ -5,96 +5,96 @@ avg(completed tasks, agent travel time, task completion time, problem completion
EDF = (16.17% ± [2.50, 3.16], 27.16 ± [5.97, 7.62], 19.12 ± [3.06, 3.02], 597.58 ± [15.58, 2.42], 0.40 ms ± [0.18, 9.29])
CFLA = (27.24% ± [1.91, 2.09], 31.67 ± [4.32, 6.06], 11.66 ± [1.11, 1.03], 529.41 ± [33.41, 32.59], 340.23 ms ± [43.07, 244.57])
CFLAP = (23.68% ± [2.68, 2.98], 14.87 ± [2.33, 2.78], 14.40 ± [1.82, 1.64], 555.61 ± [20.61, 20.39], 130.04 ms ± [25.32, 110.47])
CFLA2 = (23.68% ± [2.68, 2.98], 14.87 ± [2.33, 2.78], 14.40 ± [1.82, 1.64], 555.61 ± [20.61, 20.39], 130.04 ms ± [25.32, 110.47])
CCF = (9.41% ± [8.74, 5.26], 8.12 ± [5.12, 2.68], 20.54 ± [9.54, 6.21], 413.24 ± [399.24, 186.76], 0.76 ms ± [0.73, 5.53])
[4 agents]
EDF = (32.34% ± [3.34, 4.33], 28.29 ± [4.35, 4.72], 19.08 ± [1.96, 2.20], 584.18 ± [41.18, 15.82], 0.58 ms ± [0.21, 9.61])
CFLA = (42.01% ± [4.01, 3.99], 32.14 ± [4.36, 3.57], 13.56 ± [1.00, 0.97], 485.54 ± [38.54, 35.46], 498.08 ms ± [63.31, 275.43])
CFLAP = (43.76% ± [3.76, 4.24], 17.64 ± [2.98, 2.71], 15.36 ± [1.08, 1.27], 558.50 ± [22.50, 23.50], 244.22 ms ± [40.93, 108.39])
CFLA2 = (43.76% ± [3.76, 4.24], 17.64 ± [2.98, 2.71], 15.36 ± [1.08, 1.27], 558.50 ± [22.50, 23.50], 244.22 ms ± [40.93, 108.39])
CCF = (26.37% ± [6.04, 2.63], 8.94 ± [2.02, 2.38], 20.80 ± [2.28, 2.13], 596.76 ± [141.76, 3.24], 0.96 ms ± [0.22, 6.91])
[6 agents]
EDF = (46.11% ± [4.11, 5.22], 29.00 ± [2.78, 3.19], 19.44 ± [1.77, 1.93], 544.97 ± [36.97, 40.03], 0.68 ms ± [0.29, 13.30])
CFLA = (51.24% ± [4.24, 4.10], 32.34 ± [3.69, 4.26], 14.43 ± [1.00, 1.08], 431.69 ± [48.69, 48.31], 595.21 ms ± [76.53, 335.17])
CFLAP = (60.55% ± [5.22, 3.45], 19.96 ± [2.43, 2.91], 16.38 ± [0.81, 1.23], 557.41 ± [17.41, 18.59], 331.84 ms ± [59.75, 133.31])
CFLA2 = (60.55% ± [5.22, 3.45], 19.96 ± [2.43, 2.91], 16.38 ± [0.81, 1.23], 557.41 ± [17.41, 18.59], 331.84 ms ± [59.75, 133.31])
CCF = (39.33% ± [3.99, 3.67], 9.09 ± [2.00, 2.63], 20.87 ± [1.86, 1.79], 598.37 ± [10.37, 1.63], 1.09 ms ± [0.20, 7.55])
[8 agents]
EDF = (57.24% ± [5.91, 4.76], 29.61 ± [3.08, 3.27], 19.34 ± [1.74, 2.22], 494.33 ± [44.33, 44.67], 1.17 ms ± [0.46, 17.88])
CFLA = (57.94% ± [4.94, 4.06], 32.62 ± [3.19, 3.43], 14.74 ± [1.22, 1.10], 387.05 ± [42.05, 36.95], 748.13 ms ± [89.53, 958.35])
CFLAP = (74.30% ± [5.63, 3.70], 22.26 ± [2.05, 1.95], 17.39 ± [0.99, 1.48], 546.98 ± [30.98, 24.02], 443.34 ms ± [77.25, 251.47])
CFLA2 = (74.30% ± [5.63, 3.70], 22.26 ± [2.05, 1.95], 17.39 ± [0.99, 1.48], 546.98 ± [30.98, 24.02], 443.34 ms ± [77.25, 251.47])
CCF = (52.25% ± [4.59, 3.75], 9.39 ± [1.57, 1.62], 20.58 ± [1.65, 2.68], 597.87 ± [9.87, 2.13], 1.40 ms ± [0.24, 9.34])
[10 agents]
EDF = (65.33% ± [7.33, 4.67], 29.93 ± [2.82, 3.97], 19.43 ± [1.30, 1.57], 450.70 ± [28.70, 51.30], 1.28 ms ± [0.55, 19.12])
CFLA = (61.87% ± [3.87, 4.80], 32.59 ± [2.96, 3.11], 14.99 ± [1.22, 0.98], 348.50 ± [30.50, 32.50], 795.12 ms ± [86.83, 803.97])
CFLAP = (83.59% ± [5.25, 4.75], 25.13 ± [3.62, 4.27], 18.71 ± [1.27, 1.34], 530.36 ± [28.36, 24.64], 497.96 ms ± [63.53, 114.35])
CFLA2 = (83.59% ± [5.25, 4.75], 25.13 ± [3.62, 4.27], 18.71 ± [1.27, 1.34], 530.36 ± [28.36, 24.64], 497.96 ms ± [63.53, 114.35])
CCF = (63.88% ± [5.88, 5.78], 9.93 ± [1.48, 2.52], 20.63 ± [1.73, 1.49], 597.71 ± [12.71, 2.29], 1.58 ms ± [0.25, 11.29])
[12 agents]
EDF = (72.56% ± [8.23, 5.11], 30.24 ± [4.00, 2.47], 19.24 ± [1.62, 1.69], 413.43 ± [32.43, 38.57], 0.92 ms ± [0.33, 15.08])
CFLA = (65.14% ± [4.14, 7.52], 32.95 ± [3.18, 3.17], 15.11 ± [1.03, 1.14], 321.85 ± [36.85, 35.15], 802.53 ms ± [83.63, 494.50])
CFLAP = (87.43% ± [5.76, 4.24], 29.14 ± [4.97, 3.44], 19.36 ± [1.28, 1.40], 482.37 ± [43.37, 36.63], 497.20 ms ± [73.55, 177.36])
CFLA2 = (87.43% ± [5.76, 4.24], 29.14 ± [4.97, 3.44], 19.36 ± [1.28, 1.40], 482.37 ± [43.37, 36.63], 497.20 ms ± [73.55, 177.36])
CCF = (74.73% ± [4.06, 4.27], 10.38 ± [1.28, 1.62], 20.58 ± [1.37, 1.41], 594.26 ± [39.26, 5.74], 1.89 ms ± [0.32, 10.25])
[14 agents]
EDF = (77.64% ± [4.97, 5.69], 30.68 ± [2.39, 2.90], 18.90 ± [1.79, 1.26], 379.78 ± [22.78, 38.22], 1.06 ms ± [0.47, 13.69])
CFLA = (67.11% ± [5.44, 4.22], 33.06 ± [3.16, 2.63], 15.05 ± [1.10, 1.22], 297.78 ± [30.78, 32.22], 825.84 ms ± [88.52, 320.01])
CFLAP = (87.94% ± [5.60, 4.40], 31.00 ± [2.76, 2.66], 19.24 ± [1.34, 1.11], 422.85 ± [35.85, 34.15], 527.77 ms ± [69.73, 150.93])
CFLA2 = (87.94% ± [5.60, 4.40], 31.00 ± [2.76, 2.66], 19.24 ± [1.34, 1.11], 422.85 ± [35.85, 34.15], 527.77 ms ± [69.73, 150.93])
CCF = (82.38% ± [5.05, 4.28], 11.56 ± [1.47, 1.48], 20.40 ± [1.27, 1.30], 575.90 ± [55.90, 24.10], 2.00 ms ± [0.40, 10.11])
[16 agents]
EDF = (83.25% ± [5.92, 4.75], 30.88 ± [2.68, 3.12], 18.66 ± [1.96, 1.58], 351.10 ± [19.10, 28.90], 1.81 ms ± [0.76, 23.48])
CFLA = (68.77% ± [4.10, 5.23], 32.86 ± [2.67, 2.83], 15.01 ± [1.06, 1.40], 283.41 ± [30.41, 33.59], 974.44 ms ± [75.39, 611.26])
CFLAP = (89.10% ± [4.10, 5.23], 31.43 ± [3.70, 3.93], 18.95 ± [1.51, 1.47], 378.02 ± [30.02, 27.98], 606.13 ms ± [76.32, 117.88])
CFLA2 = (89.10% ± [4.10, 5.23], 31.43 ± [3.70, 3.93], 18.95 ± [1.51, 1.47], 378.02 ± [30.02, 27.98], 606.13 ms ± [76.32, 117.88])
CCF = (86.94% ± [7.94, 5.39], 12.92 ± [2.28, 2.10], 20.39 ± [1.14, 1.41], 538.82 ± [47.82, 60.18], 2.33 ms ± [0.56, 12.45])
[18 agents]
EDF = (88.09% ± [7.75, 5.58], 30.64 ± [2.40, 2.34], 18.33 ± [1.42, 1.29], 336.11 ± [20.11, 25.89], 2.04 ms ± [0.74, 26.48])
CFLA = (69.73% ± [6.07, 5.60], 32.54 ± [3.83, 4.71], 15.10 ± [0.80, 0.93], 272.95 ± [26.95, 25.05], 983.11 ms ± [115.05, 1010])
CFLAP = (89.10% ± [4.10, 3.90], 31.43 ± [2.02, 3.68], 18.55 ± [1.37, 1.58], 340.05 ± [21.05, 34.95], 603.53 ms ± [71.15, 123.62])
CFLA2 = (89.10% ± [4.10, 3.90], 31.43 ± [2.02, 3.68], 18.55 ± [1.37, 1.58], 340.05 ± [21.05, 34.95], 603.53 ms ± [71.15, 123.62])
CCF = (89.49% ± [6.15, 5.51], 13.41 ± [2.39, 3.06], 20.43 ± [1.46, 1.29], 495.89 ± [62.89, 50.11], 2.31 ms ± [0.32, 11.26])
[20 agents]
EDF = (91.68% ± [12.01, 4.66], 30.80 ± [3.55, 2.53], 17.77 ± [1.49, 1.80], 319.14 ± [15.14, 32.86], 2.39 ms ± [0.87, 22.96])
CFLA = (70.67% ± [7.00, 5.00], 32.83 ± [2.46, 2.77], 15.03 ± [1.17, 1.40], 262.85 ± [20.85, 23.15], 1013.92 ms ± [127.97, 1099])
CFLAP = (89.34% ± [7.67, 3.66], 31.57 ± [4.07, 3.50], 17.81 ± [1.86, 1.63], 312.13 ± [26.13, 23.87], 632.03 ms ± [127.34, 193])
CFLA2 = (89.34% ± [7.67, 3.66], 31.57 ± [4.07, 3.50], 17.81 ± [1.86, 1.63], 312.13 ± [26.13, 23.87], 632.03 ms ± [127.34, 193])
CCF = (91.99% ± [6.32, 4.01], 13.98 ± [2.91, 4.33], 20.40 ± [1.20, 1.26], 464.27 ± [53.27, 59.73], 2.25 ms ± [0.33, 13.09])
[25 agents]
EDF = (95.01% ± [6.34, 3.66], 30.75 ± [2.73, 2.78], 16.08 ± [1.25, 1.43], 301.00 ± [0.00, 0.00], 4.19 ms ± [1.16, 33.02])
CFLA = (71.35% ± [4.68, 5.65], 32.66 ± [3.10, 3.09], 14.87 ± [1.00, 0.82], 247.43 ± [15.43, 18.57], 1126.58 ms ± [134.66, 918])
CFLAP = (89.30% ± [3.96, 4.37], 31.65 ± [3.55, 3.73], 16.18 ± [1.07, 1.07], 290.80 ± [12.80, 14.20], 694.99 ms ± [99.13, 206.38])
CFLA2 = (89.30% ± [3.96, 4.37], 31.65 ± [3.55, 3.73], 16.18 ± [1.07, 1.07], 290.80 ± [12.80, 14.20], 694.99 ms ± [99.13, 206.38])
CCF = (95.18% ± [5.51, 3.15], 14.40 ± [2.52, 3.82], 20.34 ± [1.28, 1.39], 389.64 ± [41.64, 42.36], 2.35 ms ± [0.37, 13.85])
[30 agents]
EDF = (95.79% ± [6.79, 3.88], 30.28 ± [3.11, 2.87], 15.68 ± [1.15, 0.79], 301.00 ± [0.00, 0.00], 5.89 ms ± [1.09, 40.53])
CFLA = (70.97% ± [5.97, 4.70], 32.50 ± [3.89, 3.20], 14.74 ± [1.07, 0.85], 239.41 ± [15.41, 16.59], 1213.45 ms ± [131.16, 581])
CFLAP = (88.94% ± [4.27, 3.73], 31.59 ± [2.72, 3.36], 15.83 ± [0.88, 0.87], 288.71 ± [16.71, 14.29], 741.73 ms ± [81.26, 133.78])
CFLA2 = (88.94% ± [4.27, 3.73], 31.59 ± [2.72, 3.36], 15.83 ± [0.88, 0.87], 288.71 ± [16.71, 14.29], 741.73 ms ± [81.26, 133.78])
CCF = (96.19% ± [5.19, 2.81], 15.05 ± [2.89, 3.90], 20.33 ± [0.96, 0.93], 335.58 ± [32.58, 38.42], 2.78 ms ± [0.48, 12.69])
[35 agents]
EDF = (96.51% ± [8.18, 3.16], 30.40 ± [2.95, 2.72], 15.56 ± [1.13, 0.98], 301.00 ± [0.00, 0.00], 7.28 ms ± [1.19, 47.24])
CFLA = (71.19% ± [4.53, 5.14], 32.25 ± [2.50, 2.63], 14.64 ± [0.74, 0.92], 238.89 ± [14.89, 19.11], 1299.69 ms ± [214.81, 1700])
CFLAP = (89.46% ± [4.46, 4.21], 31.66 ± [2.64, 2.67], 15.73 ± [1.17, 0.91], 290.39 ± [14.39, 15.61], 776.76 ms ± [80.26, 172.91])
CFLA2 = (89.46% ± [4.46, 4.21], 31.66 ± [2.64, 2.67], 15.73 ± [1.17, 0.91], 290.39 ± [14.39, 15.61], 776.76 ms ± [80.26, 172.91])
CCF = (97.29% ± [4.62, 2.71], 15.15 ± [3.37, 4.39], 20.30 ± [1.33, 1.45], 293.62 ± [35.62, 35.38], 2.83 ms ± [0.58, 15.19])
[40 agents]
EDF = (96.71% ± [8.04, 3.29], 30.53 ± [2.24, 3.02], 15.51 ± [0.94, 0.95], 300.99 ± [0.99, 0.01], 5.29 ms ± [0.85, 31.01])
CFLA = (70.79% ± [5.46, 5.54], 32.34 ± [3.20, 2.79], 14.67 ± [1.11, 1.22], 237.97 ± [14.97, 16.03], 1244.93 ms ± [161.44, 1290])
CFLAP = (89.27% ± [4.27, 2.73], 31.66 ± [3.23, 2.98], 15.72 ± [0.95, 0.93], 289.10 ± [14.10, 10.90], 749.60 ms ± [96.39, 447.54])
CFLA2 = (89.27% ± [4.27, 2.73], 31.66 ± [3.23, 2.98], 15.72 ± [0.95, 0.93], 289.10 ± [14.10, 10.90], 749.60 ms ± [96.39, 447.54])
CCF = (98.15% ± [2.48, 1.85], 15.69 ± [4.12, 3.83], 20.30 ± [1.09, 1.24], 263.76 ± [24.76, 29.24], 2.76 ms ± [0.49, 16.61])
package exceptions;
public class NotPositiveWorkloadException extends Exception {
public class NegativeWorkloadException extends Exception {
private static final long serialVersionUID = 1L;
public NotPositiveWorkloadException(String msg) {
public NegativeWorkloadException(String msg) {
super(msg);
}
......
package model;
import exceptions.NegativeDeadlineException;
import exceptions.NotPositiveWorkloadException;
import exceptions.NegativeWorkloadException;
/**
* A Coalition Formation with Spatial and Temporal constraints Problem (CFSTP).
......@@ -43,7 +43,7 @@ public abstract class CFSTP {
if (demands[i][0] < 0)
throw new NegativeDeadlineException(String.format("task %d has deadline = %d", i, demands[i][0]));
if (demands[i][1] <= 0)
throw new NotPositiveWorkloadException(String.format("task %d has workload = %d", i, demands[i][1]));
throw new NegativeWorkloadException(String.format("task %d has workload = %d", i, demands[i][1]));
if (demands[i][0] > maxTaskDeadline)
maxTaskDeadline = demands[i][0];
......@@ -56,7 +56,7 @@ public abstract class CFSTP {
minTaskWorkload = demands[i][1];
}
} catch (NegativeDeadlineException | NotPositiveWorkloadException e) {
} catch (NegativeDeadlineException | NegativeWorkloadException e) {
e.printStackTrace();
}
......
......@@ -60,8 +60,8 @@ public class CCF extends Solver {
protected int numberOfTravels;
/**
* The number of time steps required to complete each task
* (0 means uncompleted).
* The number of time steps required to complete each task (0 means
* uncompleted).
*/
protected int[] completionTime;
......@@ -115,7 +115,8 @@ public class CCF extends Solver {
if (taskStatus[v] == TaskStatus.ALLOCATED)
idx = 1;
int arrivalTime = currentTime + problem.getAgentTravelTime(a, agentLocations[a], taskLocations[v]);
if (arrivalTime <= demands[v][0] && demands[v][0] < bestDeadline[idx] && arrivalTime < bestArrivalTime[idx]) {
if (arrivalTime <= demands[v][0] && demands[v][0] < bestDeadline[idx]
&& arrivalTime < bestArrivalTime[idx]) {
bestDeadline[idx] = demands[v][0];
bestArrivalTime[idx] = arrivalTime;
bestTask[idx] = v;
......@@ -270,10 +271,18 @@ public class CCF extends Solver {
cValue = problem.getCoalitionValue(v, agentsToAssign);
float workloadDone = 0f;
for (int j = 0; j < agentsToAssign.length - 1; j++)
for (int j = 0; j < agentsToAssign.length - 1; j++) {
/*
* If multiple agents arrive at the same time, consider only the last one in the
* order.
*/
if (arrivalTimes[j] == arrivalTimes[j + 1])
continue;
workloadDone += (arrivalTimes[j + 1] - arrivalTimes[j])
* problem.getCoalitionValue(v, ArrayUtils.addAll(
ArrayUtils.subarray(agentsToAssign, 0, j + 1), agentsWorkingAtTask));
}
/* if coalition of first i agents can complete v within deadline */
if (cValue * (demands[v][0] - arrivalTimes[i]) >= workloads[v] - workloadDone)
......@@ -351,7 +360,7 @@ public class CCF extends Solver {
}
currentTime++;
} while (!allAgentsAreAvailable() && numberOfCompletedTasks < tasks.length && currentTime < maxTaskDeadline);
} while (!allAgentsAreAvailable() && numberOfCompletedTasks < tasks.length && currentTime <= maxTaskDeadline);
if (numberOfTravels > 0)
avgTravelTime /= numberOfTravels;
......
......@@ -13,7 +13,7 @@ import toolkit.Mathematics;
import toolkit.Utilities;
/**
* Coalition Formation with improved Look-Ahead (CFLA^+) algorithm for solving CFSTPs.
* Coalition Formation with improved Look-Ahead (CFLA2) algorithm for solving CFSTPs.
*
* @author lcpz
*/
......@@ -25,7 +25,7 @@ public class CFLA extends Solver {
*/
protected boolean[][][] T;
/* CFLA or CFLA^+ */
/* CFLA or CFLA2 */
private boolean improved;
public CFLA(CFSTP problem) {
......@@ -254,7 +254,7 @@ public class CFLA extends Solver {
* has the same weight (1) */
degreeV++;
else
/* CFLA^+: each task that can be completed after v
/* CFLA2: each task that can be completed after v
* weights inversely proportional to its workload */
degreeV += 2 - Mathematics.getZ(demands[v2][1], minTaskWorkload, maxTaskWorkload);
/* in other words, the higher degreeV is, the more
......
......@@ -3,7 +3,7 @@ package toolkit;
public class Utilities {
/**
* Get an integer array with numbers from 0 to n-1.
* Get an integer array with numbers from 0 to n.
*
* @param n The length of the array.
* @return The array
......@@ -15,9 +15,9 @@ public class Utilities {
if (n == 0)
return new Integer[0];
Integer[] arr = new Integer[n];
Integer[] arr = new Integer[n + 1];
for (int i = 0; i < n; i++)
for (int i = 0; i < n + 1; i++)
arr[i] = i;
return arr;
......
......@@ -24,7 +24,7 @@ class SolversTest {
static final int TEST_REPETITIONS = 1;
static final int AGENTS = 40;
static final int AGENTS = 20;
static final int TASKS = 300;
static final int WORLD_DIM = 50;
......@@ -52,7 +52,7 @@ class SolversTest {
static CFSTP problem;
static String[] solvers = new String[] { "CFLA", "CFLAP", "CCF" };
static String[] solvers = new String[] { "CFLA", "CFLA2", "CCF" };
// solver: avg, min, max
static float[][] completedTaskPercentage = new float[solvers.length][3];
......@@ -142,7 +142,7 @@ class SolversTest {
case "CFLA":
s = new CFLA(problem);
break;
case "CFLAP":
case "CFLA2":
s = new CFLA(problem, true);
break;
case "CCF":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment