
org.btrplace.scheduler.choco.constraint.CNoDelay Maven / Gradle / Ivy
/*
* Copyright (c) 2016 University Nice Sophia Antipolis
*
* This file is part of btrplace.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package org.btrplace.scheduler.choco.constraint;
import org.btrplace.model.Instance;
import org.btrplace.model.VM;
import org.btrplace.model.constraint.NoDelay;
import org.btrplace.scheduler.choco.Parameters;
import org.btrplace.scheduler.choco.ReconfigurationProblem;
import org.btrplace.scheduler.choco.Slice;
import org.btrplace.scheduler.choco.extensions.ChocoUtils;
import org.btrplace.scheduler.choco.transition.RelocatableVM;
import org.btrplace.scheduler.choco.transition.VMTransition;
import org.chocosolver.solver.Cause;
import org.chocosolver.solver.constraints.Arithmetic;
import org.chocosolver.solver.constraints.Operator;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.VF;
import java.util.Collections;
import java.util.Set;
/**
* @author Vincent Kherbache
*/
public class CNoDelay implements ChocoConstraint {
private NoDelay noDelay;
/**
* Make a new constraint
*
* @param nd the NoDelay constraint to rely on
*/
public CNoDelay(NoDelay nd) {
noDelay = nd;
}
@Override
public Set getMisPlacedVMs(Instance model) {
return Collections.emptySet();
}
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
VM v = noDelay.getInvolvedVMs().iterator().next();
// For each vm involved in the constraint
VMTransition vt = rp.getVMAction(v);
// Get the VMTransition start time
// Add the constraint "start = 0" to the solver
Slice d = vt.getDSlice();
if (d == null) {
return true;
}
if (!(vt instanceof RelocatableVM)) {
try {
d.getStart().instantiateTo(0, Cause.Null);
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to prevent any delay on '" + v + "'", ex);
return false;
}
} else {
Arithmetic c = new Arithmetic(d.getStart(), Operator.EQ, 0);
BoolVar move = VF.not(((RelocatableVM) vt).isStaying());
ChocoUtils.postImplies(rp, move, c);
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy