use of org.btrplace.model.view.network.Routing.LinkDirection in project scheduler by btrplace.
the class CNetwork method addLinkConstraints.
/**
* Add the cumulative constraints for each link.
*
* Full-duplex links are considered, two cumulative constraints are defined per link by looking at
* the migration direction for each link on the migration path.
*
* @param rp the reconfiguration problem
*/
private void addLinkConstraints(ReconfigurationProblem rp) {
// Links limitation
List<Task> tasksListUp = new ArrayList<>();
List<Task> tasksListDown = new ArrayList<>();
List<IntVar> heightsListUp = new ArrayList<>();
List<IntVar> heightsListDown = new ArrayList<>();
for (Link l : net.getLinks()) {
for (VM vm : rp.getVMs()) {
VMTransition a = rp.getVMAction(vm);
if (a instanceof RelocatableVM && !a.getDSlice().getHoster().isInstantiatedTo(a.getCSlice().getHoster().getValue())) {
Node src = source.getMapping().getVMLocation(vm);
Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
List<Link> path = net.getRouting().getPath(src, dst);
// Check first if the link is on migration path
if (path.contains(l)) {
// Get link direction
LinkDirection linkDirection = net.getRouting().getLinkDirection(src, dst, l);
// UpLink
if (linkDirection == LinkDirection.UPLINK) {
tasksListUp.add(((RelocatableVM) a).getMigrationTask());
heightsListUp.add(((RelocatableVM) a).getBandwidth());
} else // DownLink
{
tasksListDown.add(((RelocatableVM) a).getMigrationTask());
heightsListDown.add(((RelocatableVM) a).getBandwidth());
}
}
}
}
if (!tasksListUp.isEmpty()) {
// Post the cumulative constraint for the current UpLink
csp.post(csp.cumulative(tasksListUp.toArray(new Task[tasksListUp.size()]), heightsListUp.toArray(new IntVar[heightsListUp.size()]), csp.intVar(l.getCapacity()), true));
tasksListUp.clear();
heightsListUp.clear();
}
if (!tasksListDown.isEmpty()) {
// Post the cumulative constraint for the current DownLink
csp.post(csp.cumulative(tasksListDown.toArray(new Task[tasksListDown.size()]), heightsListDown.toArray(new IntVar[heightsListDown.size()]), csp.intVar(l.getCapacity()), true));
tasksListDown.clear();
heightsListDown.clear();
}
}
}
Aggregations