Commit ef81939b authored by Robert Ricci's avatar Robert Ricci

The beginnings of a toy version of assign written in Comet. I'm

working on getting a feeling of whether or not it's feasible to
implement assign in Comet. I think if it is, it would be a huge win in
terms of maintainability and extensibility.

So far, it's looking very promising. I'm struggling a bit with the
syntax, and the lack of an API reference. But, once I figure out how
to do what I need, it's making a lot of sense.

All this program does so far is try to respect the number of slots on
physical nodes - ie. not assign more than one vnode to a pnode, but it
can do arbitrary numbers instead of just 1.

It does not read top/ptop files, doesn't know about types, doesn't try
to minimize any score, doesn't do features/desires, doesn't know about
links at all, etc. Like I said, it's the beginnings of a toy program.

It looks to me like what we're going to end up doing is writing a
program to produce Comet programs. One of the cool things about this
is that it means we can leave out any constraints, etc. that are not
relevant to the particular mapping problem at hand. And, it should
make it easy for us to plug in other search techniques (ie. write the
obvious ones for certain pathological cases, like snakes and
trees.)
parent 8d8bd3d3
/*
* Toy version of assign, written in Comet
* Robert Ricci <ricci@cs.utah.edu>
* EMULAB-COPYRIGHT
* Copyright (c) 2005 University of Utah and the Flux Group.
* All rights reserved.
*/
string rcsid = "$Id: toy-assign.co,v 1.1 2005-12-17 00:46:45 ricci Exp $";
/*
* Include some routines for a local solver
*/
include "LocalSolver";
/*
* Declare the local solver
*/
LocalSolver m();
/*
* Virtual nodes
*/
int n_vnodes = 100;
range VSize = 1..n_vnodes;
UniformDistribution vdistr(VSize);
/*
* Physical nodes
*/
int n_pnodes = 100;
range PSize = 1..n_pnodes;
UniformDistribution pdistr(PSize);
range MaxSlots = 1..100;
/*
* Mapping of virtual to physical
*/
var{int}[] mapping = new var{int}[VSize];
forall (i in VSize) {
mapping[i] = new var{int}(m,PSize);
// Start them on random pnodes
mapping[i] := pdistr.get();
}
/*
* Constraints
*/
ConstraintSystem S(m);
/*
* All virtual nodes must be mapped to different physical nodes
* Now done with slot counts - see below
*/
//S.post(alldifferent(mapping));
/*
* Put a constraint on how many vnodes can be on each pnode
*/
int slots[PSize];
forall (k in PSize) {
// For now, every pnode gets one slot
slots[k] = 1;
}
/*
* This line says:
* for every index i in the slots array:
* i must appear as a value in mapping no more than slots[i] timex
*
*/
S.post(atmost(slots,mapping));
/*
* Maintain a list of how many slots are used in each pnode. This will get
* automatically updated for us by Comet
*/
var{int} pnodeSlotsUsed[node in PSize](m)
<- sum(k in VSize) (mapping[k] == node);
/*
* Maintain a set of empty pnodes.
* Again, maintained incrementally by Comet
*/
var{set{int}} emptyPnodes(m) <- setof(k in PSize) (pnodeSlotsUsed[k] == 0);
/*
* Let's get a set of nodes with remaining capacity too
*/
var{set{int}} pnodesWithSpace(m)
<- setof(k in PSize) (pnodeSlotsUsed[k] < slots[k]);
/*
* A simple objective function - minimize the number of pnodes used
*/
/*
Objective O = new MaxNbDistinct(slots, mapping);
*/
/*
* This says we're done adding constraints to the solver
*/
m.close();
cout << "Starting" << endl;
int it = 0;
int max_it = 50 * n_vnodes;
/*
* Termination condidtions
*/
while (S.violations() > 0
&&
it < max_it ) {
/*
* The actual search
*/
/*
* queens-style search
selectMax(q in VSize)(S.getViolations(mapping[q]))
selectMin(v in VSize)(S.getAssignDelta(mapping[q],v))
mapping[q] := v;
*/
/*
* Purely random search
select(vnode in VSize)
select(pnode in mapping[vnode].getDomain())
mapping[vnode] := pnode;
*/
/*
* Slightly smarter search
*/
// Pick the most violated virtual node
selectMax(vnode in VSize)(S.violations(mapping[vnode])) {
// Put it on the first pnode with remaining capacity we find
selectFirst(pnode in pnodesWithSpace) {
mapping[vnode] := pnode;
}
}
//cout << "On iteration " << it << endl;
it++;
}
forall(i in VSize) {
cout << "mapping[" << i << "] = " << mapping[i] << endl;
}
cout << "Done after " << it << " iterations" << endl;
cout << "Number of violations is " << S.violations() << endl;
// cout << "Objective functions returns " << O.evaluation() << endl;
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