public release

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
.gradle/
.settings/
bin/
build/
datasets/
target/
*.class
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cfstp</name>
<comment>
</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
MIT License
Copyright (c) 2020 ECS Centre for Machine Intelligence
University of Southampton, UK
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
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
# CFSTP
| **Author** | **License** |
|---|---|
| [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.
## Dependencies
- [Eclipse IDE](https://www.eclipse.org/eclipseide)
- [OpenJDK 13](https://openjdk.java.net/projects/jdk/13) or above
- [Apache Maven](https://maven.apache.org)
- [Apache Commons Lang 3](https://commons.apache.org/proper/commons-lang)
- [Apache Commons Math 3](https://commons.apache.org/proper/commons-math)
## Usage
1. Import the project in Eclipse
2. Update it to download the Maven dependencies
3. Run `src/test/java/solvers/SolversTest`
## To-do list
- [ ] Test with [RoboCupRescue simulator](https://github.com/roborescue/rcrs-adf-sample)
- [ ] Test with [RMASBench](https://github.com/RMASBench)
- [ ] 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))
- [ ] Write a [microbenchmark](https://stackoverflow.com/a/513259) to measure
computation time accurately (or use [Stopwatch](https://www.javarticles.com/2016/02/junit-stopwatch-rule-example.html))
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>soton</groupId>
<artifactId>cfstp</artifactId>
<version>1.0.0</version>
<name>CFSTP</name>
<description>Algorithms for solving the CFSTP and its extensions</description>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
</project>
[100 random CFSTP instances, 300 tasks, 50 world_dim]
avg(completed tasks, agent travel time, task completion time, problem completion time, computational time)
[2 agents]
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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 NegativeDeadlineException extends Exception {
private static final long serialVersionUID = 1L;
public NegativeDeadlineException(String msg) {
super(msg);
}
}
\ No newline at end of file
package exceptions;
public class NotPositiveWorkloadException extends Exception {
private static final long serialVersionUID = 1L;
public NotPositiveWorkloadException(String msg) {
super(msg);
}
}
\ No newline at end of file
package model;
import java.util.Arrays;
import org.apache.commons.lang3.ArrayUtils;
/**
* Data structure containing information about a task-coalition allocation.
*
* @author lcpz
*/
public class Allocation {
protected int task;
protected int[] agents;
private int travelTime;
private int completionTime;
/**
* @param task The task to which the coalition is allocated.
* @param agents The set of agents composing the coalition.
* @param travelTime The travel time units required by the coalition to
* reach the task.
* @param completionTime The completion time units required by the coalition to
* complete the task.
*/
public Allocation(int task, int[] agents, int travelTime, int completionTime) {
this.task = task;
this.agents = agents;
if (agents == null)
agents = ArrayUtils.EMPTY_INT_ARRAY;
this.travelTime = travelTime;
this.completionTime = completionTime;
}
/**
* Return an empty allocation.
*/
public Allocation() {
task = -1;
agents = ArrayUtils.EMPTY_INT_ARRAY;
travelTime = -1;
completionTime = -1;
}
@Override
public String toString() {
return String.format("%3d -> %s [%3d, %3d]", task, Arrays.toString(agents), travelTime, completionTime);
}
public int getTask() {
return task;
}
public int[] getAgents() {
return agents;
}
public int getTravelTime() {
return travelTime;
}
public int getCompletionTime() {
return completionTime;
}
}
\ No newline at end of file
package model;
import exceptions.NegativeDeadlineException;
import exceptions.NotPositiveWorkloadException;
/**
* A Coalition Formation with Spatial and Temporal constraints Problem (CFSTP).
*
* @author lcpz
*/
public abstract class CFSTP {
/* Tasks and agents are uniquely identified by integers */
protected int[] tasks, agents;
/* Task locations (static) are 2-dimensional points: [taskId][x,y] */
protected int[][] taskLocations;
/* Likewise, initial agent locations are 2-dimensional points: [agentId][x,y] */
protected int[][] initialAgentLocations;
/*
* Task demands: [deadline, workload].
*
* Row of index <code>i</code> contains the demands of <code>tasks[i]</code>.
*/
protected int[][] demands;
/* Some useful data */
protected int maxTaskDeadline, minTaskDeadline, maxTaskWorkload, minTaskWorkload;
public CFSTP(int[] agents, int[] tasks, int[][] initialAgentLocations, int[][] taskLocations, int[][] demands) {
this.agents = agents;
this.tasks = tasks;
this.taskLocations = taskLocations;
this.demands = demands;
minTaskDeadline = Integer.MAX_VALUE;
minTaskWorkload = Integer.MAX_VALUE;
try {
for (int i = 0; i < demands.length; i++) {
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]));
if (demands[i][0] > maxTaskDeadline)
maxTaskDeadline = demands[i][0];
if (demands[i][0] < minTaskDeadline)
minTaskDeadline = demands[i][0];
if (demands[i][1] > maxTaskWorkload)
maxTaskWorkload = demands[i][1];
if (demands[i][1] < minTaskWorkload)
minTaskWorkload = demands[i][1];
}
} catch (NegativeDeadlineException | NotPositiveWorkloadException e) {
e.printStackTrace();
}
/* setting initial agent locations */
this.initialAgentLocations = initialAgentLocations;
}
/**
* The time taken for an agent to travel from one location to another.
*
* This is function $\rho$ in section 2.1 of (Ramchurn et al., 2010).
*
* @param agentId The agent's identifier; to be used when you assume that
* agents cannot move at the same speed.
* @param agentLocation The agent's current location, in (x, y) coordinates.
* @param taskLocation The location of a given task, in (x, y) coordinates.
*
* @return The time steps required by agentId to travel from agentLocation to
* taskLocation.
*/
public abstract int getAgentTravelTime(int agentId, int[] agentLocation, int[] taskLocation);
/**
* Given task $v$ and coalition $C \in 2^A$, the coalition value of $C$ $u(C)$
* determines the amount of workload that $C$ does in a time step.
*
* In the CFSTP model, it is possible to take $C$ so that $u(C) = workload_v$,
* and so complete a task v in only one time step.
*
* @param task The task <code>v</code>.
* @param coalition A coalition assigned to <code>v</code>.
*
* @return The value of <code>coalition</code.
*/
public abstract float getCoalitionValue(int task, int[] coalition);
public int[] getTasks() {
return tasks;
}
public int[] getAgents() {
return agents;
}
public int[][] getTaskLocations() {
return taskLocations;
}
public int[][] getInitialAgentLocations() {
return initialAgentLocations;
}
public int[][] getDemands() {
return demands;
}
public int getMaxTaskDeadline() {
return maxTaskDeadline;
}
public int getMinTaskDeadline() {
return minTaskDeadline;
}
public int getMaxTaskWorkload() {
return maxTaskWorkload;
}
public int getMinTaskWorkload() {
return minTaskWorkload;
}
}
\ No newline at end of file
package model;
public class FeasibleAllocation extends Allocation {
private int allocationTime;
private int[] arrivalTimes;
public FeasibleAllocation(int allocationTime, int task, int[] agents, int[] arrivalTimes) {
this.allocationTime = allocationTime;
this.task = task;
this.agents = agents;
this.arrivalTimes = arrivalTimes;
}
public int getAllocationTime() {
return allocationTime;
}
public int[] getArrivalTimes() {
return arrivalTimes;
}
}
\ No newline at end of file
package model;
/**
* Data structure containing the results of a CFSTP solver, namely: average
* travel and completion time; completed task percentage.
*
* @author lcpz
*/
public class Results {
private float avgTravelTime, avgCompletionTime, completedTaskPercentage;
public Results(float avgTravelTime, float avgCompletionTime, float completedTaskPercentage) {
this.avgTravelTime = avgTravelTime;
this.avgCompletionTime = avgCompletionTime;
this.completedTaskPercentage = completedTaskPercentage;
}
public float getAvgTravelTime() {
return avgTravelTime;
}
public float getAvgCompletionTime() {
return avgCompletionTime;
}
public float getCompletedTaskPercentage() {
return completedTaskPercentage;
}
}
package solvers;
import java.util.Arrays;
import java.util.Comparator;
import org.apache.commons.lang3.ArrayUtils;
import model.CFSTP;
import model.FeasibleAllocation;
import model.Results;
import toolkit.Utilities;
/**
* Cluster-based Coalition Formation (CCF) algorithm for solving CFSTPs.
*
* @author lcpz
*/
public class CCF extends Solver {
public static enum TaskStatus {
/**
* A task is allocable when at least one agent can reach it (feasible),
* allocated when at least one agent is reaching or working on it, and completed
* when its workload is <= 0.
*/
NOT_COMPLETED, ALLOCABLE, ALLOCATED, COMPLETED;
}
public static enum AgentStatus {
FREE, REACHING_A_TASK, WORKING_ON_A_TASK;
}
public static enum AssignmentStatus {
/**
* {not working on, feasible to work on, reaching, working on, done with} a task
*/
NONE, FEASIBLE, REACHING, WORKING_ON, DONE;
}
protected TaskStatus[] taskStatus;
protected AgentStatus[] agentStatus;
protected AssignmentStatus[][] assignmentStatus; // [agent, task]
/* how many agents are currently working at each task */
protected int[] workingAtTask;
/**
* For each agent (rows), it denotes the task it's reaching (column 0), and the
* number of time steps left to reach it (column 1).
*/
protected int[][] reachingTask;
/**
* A copy of task workloads that we use for keeping track of how much workload
* is left per task.
*/
protected float[] workloads;
/* a counter for computing the average travel time after solving */
protected int numberOfTravels;
/**
* The number of time steps required to complete each task
* (0 means uncompleted).
*/
protected int[] completionTime;
protected float maxTaskWorkload;
public CCF(CFSTP problem) {
super(problem);
taskStatus = new TaskStatus[tasks.length];
agentStatus = new AgentStatus[agents.length];
assignmentStatus = new AssignmentStatus[agents.length][tasks.length];
Arrays.fill(taskStatus, TaskStatus.NOT_COMPLETED);
Arrays.fill(agentStatus, AgentStatus.FREE);
workingAtTask = new int[tasks.length];
reachingTask = new int[agents.length][2];
for (int a : agents) {
Arrays.fill(assignmentStatus[a], AssignmentStatus.NONE);
reachingTask[a][0] = -1;
reachingTask[a][1] = -1;
}
workloads = new float[tasks.length];
for (int v = 0; v < demands.length; v++) {
workloads[v] = demands[v][1];
if (workloads[v] > maxTaskWorkload)
maxTaskWorkload = workloads[v];
}
completionTime = new int[tasks.length];
}
/**
* Given agent a, return the current closest and uncompleted/allocated task v
* reachable by a.
*