use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class FixedNodeSetsPartitioning method split.
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
Model mo = i.getModel();
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
List<Instance> parts = new ArrayList<>(partitions.size());
// nb of VMs
int nbVMs = i.getModel().getMapping().getNbVMs();
int nbNodes = i.getModel().getMapping().getNbNodes();
TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
int partNumber = 0;
Set<VM> toLaunch = getVMsToLaunch(i);
for (Collection<Node> s : partitions) {
SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
// VM Index
partModel.getMapping().fillVMIndex(vmPosition, partNumber);
// Node index
for (Node n : s) {
nodePosition.put(n.id(), partNumber);
}
partNumber++;
}
// Round-robin placement for the VMs to launch
int p = 0;
for (VM v : toLaunch) {
if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
}
vmPosition.put(v.id(), p);
p = (p + 1) % parts.size();
}
// Split the constraints
for (SatConstraint cstr : i.getSatConstraints()) {
if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
throw new SplitException(i.getModel(), "Unable to split " + cstr);
}
}
return parts;
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class ElementSubSetTest method test.
@Test
public void test() {
Model mo = new DefaultModel();
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(mo.newVM());
index.put(i, i % 2);
}
SplittableElementSet<VM> si = SplittableElementSet.newVMIndex(l, index);
List<VM> values = si.getValues();
ElementSubSet<VM> p1 = new ElementSubSet<>(si, 0, 0, 5);
// test contains()
Assert.assertTrue(p1.contains(values.get(0)));
Assert.assertFalse(p1.contains(values.get(5)));
// test containsAll()
Assert.assertFalse(p1.containsAll(l));
// test size()
Assert.assertEquals(p1.size(), 5);
Assert.assertFalse(p1.isEmpty());
System.out.println(p1);
// test iterator
for (VM v : p1) {
Assert.assertEquals(v.id() % 2, 0);
}
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class SplittableElementSetTest method testOrdering.
@Test(dependsOnMethods = "testNewVMSet")
public void testOrdering() {
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
Random rnd = new Random();
for (int i = 0; i < 10; i++) {
l.add(new VM(i));
index.put(i, rnd.nextInt(3));
}
SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
System.err.println(s);
List<VM> values = s.getValues();
for (int i = 0; i < values.size() - 1; i++) {
Assert.assertTrue(index.get(values.get(i).id()) <= index.get(values.get(i + 1).id()));
}
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class SplittableElementSetTest method testForEachPartition.
@Test(dependsOnMethods = "testNewVMSet")
public void testForEachPartition() {
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(new VM(i));
index.put(i, i % 2);
}
SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
s.forEachPartition((index1, key, from, to) -> {
Assert.assertEquals(to - from, 5);
for (int i = from; i < to; i++) {
Assert.assertEquals(key, index1.getValues().get(i).id() % 2);
}
return true;
});
// We stop after the first partition
s.forEachPartition(new IterateProcedure<VM>() {
final boolean first = true;
@Override
public boolean extract(SplittableElementSet<VM> index, int key, int from, int to) {
Assert.assertTrue(first);
return false;
}
});
}
use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.
the class SplittableElementSetTest method testNewNodeSet.
@Test
public void testNewNodeSet() {
List<Node> l = new ArrayList<>();
TIntIntHashMap m = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(new Node(i));
m.put(i, i % 2);
}
SplittableElementSet<Node> s = SplittableElementSet.newNodeIndex(l, m);
for (Node v : s.getValues()) {
Assert.assertTrue(v.id() >= 0 && v.id() < 10);
}
Assert.assertEquals(s.size(), l.size());
Assert.assertEquals(s.getRespectiveIndex(), m);
}
Aggregations