Commit 09737efc authored by Christopher Alfeld's avatar Christopher Alfeld

All the vclass stuff. Can now do:

make-vclass A 0.5 pc600 pc850

in the top file.  And then have nodes of type A.  Assign will try to put
them all as either pc600 or pc850.

Still need to write all the pre-assign stuff.
parent cb096341
......@@ -14,7 +14,7 @@ include $(TESTBED_SRCDIR)/GNUmakerules
LEDA=@LEDA@
OBJS=score.o parse_top.o parse_ptop.o config.o pclass.o
OBJS=score.o parse_top.o parse_ptop.o config.o pclass.o vclass.o
LIBS+=-L${LEDA} -lD3 -lW -lP -lG -lL -L/usr/X11R6/lib -lX11 -lm -L.
LDFLAGS+= -O3
CXXFLAGS = -I${LEDA}/incl
......
......@@ -17,6 +17,7 @@
#include "common.h"
#include "physical.h"
#include "vclass.h"
#include "virtual.h"
#include "score.h"
#include "pclass.h"
......@@ -72,7 +73,8 @@ float sensitivity = .1;
int refreshed = 0;
node_array<int> bestnodes, absnodes;
node_array<int> absnodes;
node_array<string> abstypes;
float bestscore, absbest;
extern node pnodes[MAX_PNODES];
......@@ -229,6 +231,10 @@ int assign()
}
node pn = pname2node.access(fixed_nodes.inf(fixed_it));
int ppos = pnode2posistion.access(&PG[pn]);
if (G[n].vclass != NULL) {
cerr << "Can not have fixed nodes be in a vclass!\n";
exit(1);
}
if (add_node(vn,ppos) == 1) {
cerr << "Fixed node: Could not map " << fixed_nodes.key(fixed_it)
<< " to " << fixed_nodes.inf(fixed_it) << ".\n";
......@@ -251,14 +257,6 @@ int assign()
absnodes[n3] = G[n3].posistion;
}
// if (bestscore < 0.11f) {
if (bestscore < optimal) {
#ifdef VERBOSE
cout << "Problem started optimal\n";
#endif
goto DONE;
}
while (temp >= temp_stop) {
#ifdef VERBOSE
cout << "Temperature: " << temp << " AbsBest: " << absbest << " (" << absbestv << ")" << endl;
......@@ -292,15 +290,19 @@ int assign()
}
tb_vnode &vn=G[n];
if (vn.vclass != NULL) {
vn.type = vn.vclass->choose_type();
#ifdef SCORE_DEBUG
cerr << "vclass " << vn.vclass->name << ": choose type = "
<< vn.type << " dominant = " << vn.vclass->dominant << endl;
#endif
}
tt_entry tt = type_table.access(vn.type);
int num_types = tt.first();
pclass_array &acceptable_types = *(tt.second());
////
// We've now calculated the weights and the total weight. We
// will loop through all the classes until we find an acceptable
// one.
////
// Loop will break eventually.
tb_pnode *newpnode;
int i = random()%num_types;
......@@ -353,7 +355,6 @@ int assign()
if ((newscore < optimal) || (violated < bestviolated) ||
((violated == bestviolated) && (newscore < bestscore)) ||
accept(scorediff*((bestviolated - violated)/2), temp)) {
bestnodes[n] = G[n].posistion;
bestscore = newscore;
bestviolated = violated;
accepts++;
......@@ -363,6 +364,7 @@ int assign()
node n2;
forall_nodes(n2, G) {
absnodes[n2] = G[n2].posistion;
abstypes[n2] = G[n2].type;
}
absbest = newscore;
absbestv = violated;
......@@ -389,9 +391,6 @@ int assign()
cout << "Done.\n";
DONE:
forall_nodes(n, G) {
bestnodes[n] = absnodes[n];
}
bestscore = absbest;
forall_nodes(n, G) {
......@@ -401,6 +400,10 @@ int assign()
forall_nodes(n, G) {
if (absnodes[n] != 0) {
if (G[n].vclass != NULL) {
G[n].type = abstypes[n];
}
assert(G[n].type == abstypes[n]);
if (add_node(n,absnodes[n]) != 0) {
cerr << "Invalid assumption. Tell calfeld that reseting to best configuration doesn't work" << endl;
}
......@@ -441,8 +444,8 @@ void loopassign()
float totaltime;
nodestorage.init(G, 0);
bestnodes.init(G, 0);
absnodes.init(G, 0);
abstypes.init(G, "");
nnodes = G.number_of_nodes();
optimal = assign();
......@@ -473,8 +476,8 @@ void chopgraph() {
void batch()
{
bestnodes.init(G, 0);
absnodes.init(G, 0);
abstypes.init(G, "");
chopgraph();
}
......
......@@ -32,7 +32,8 @@ static float SCORE_OVER_BANDWIDTH = 0.5;/* Cost of going over bandwidth*/
static float SCORE_DESIRE = 1;/* Multiplier for desire costs*/
static float SCORE_FEATURE = 1;/* Multiplier for feature weights*/
static float SCORE_PCLASS = 0.5; /* Cost of each pclass */
static float SCORE_VCLASS = 1; /* vclass score multiplier */
static struct config_param options[] = {
{ "IT", CONFIG_INT, &init_temp, 0 },
{ "OP", CONFIG_INT, &USE_OPTIMAL, 0 },
......@@ -51,6 +52,7 @@ static struct config_param options[] = {
{ "PN", CONFIG_FLOAT, &SCORE_PNODE, 0 },
{ "PP", CONFIG_FLOAT, &SCORE_PNODE_PENALTY, 0 },
{ "PC", CONFIG_FLOAT, &SCORE_PCLASS, 0 },
{ "VC", CONFIG_FLOAT, &SCORE_VCLASS, 0 },
{ "SW", CONFIG_FLOAT, &SCORE_SWITCH, 0 },
{ "ON", CONFIG_FLOAT, &opt_nodes_per_sw, 0 },
{ "TR", CONFIG_FLOAT, &temp_rate, 0 }
......
......@@ -15,6 +15,7 @@
#include <LEDA/sortseq.h>
#include "common.h"
#include "vclass.h"
#include "virtual.h"
extern dictionary<string,node> vname2node;
......@@ -34,6 +35,7 @@ int parse_top(tb_vgraph &G, istream& i)
int num_nodes = 0;
int bw;
int r;
dictionary<string,tb_vclass*> vclass_map;
while (!i.eof()) {
char *ret;
......@@ -61,9 +63,16 @@ int parse_top(tb_vgraph &G, istream& i)
G[no1].no_connections=0;
vname2node.insert(s1, no1);
scur=strsep(&snext," ");
G[no1].type=string(scur);
dic_item dit = vclass_map.lookup(string(scur));
if (dit != nil) {
G[no1].type = string("");
G[no1].vclass = vclass_map.inf(dit);
} else {
G[no1].type=string(scur);
G[no1].vclass=NULL;
vtypes.push(G[no1].type);
}
G[no1].fixed = false; // this may get set to true later
vtypes.push(G[no1].type);
/* Read in desires */
while ((scur=strsep(&snext," ")) != NULL) {
......@@ -106,6 +115,28 @@ int parse_top(tb_vgraph &G, istream& i)
string s2(n2);
fixed_nodes.insert(s1,s2);
}
} else if (! strncmp(inbuf, "make-vclass",11)) {
char *snext = inbuf;
char *scur = strsep(&snext," ");
if (strcmp("make-vclass",scur) != 0) {
fprintf(stderr,"bad vclass line: %s\n",inbuf);
} else {
scur=strsep(&snext," ");
string s(scur);
scur=strsep(&snext," ");
double weight;
if (sscanf(scur,"%lg",&weight) != 1) {
fprintf(stderr,"bad vclass weight: %s\n",inbuf);
weight=0.5;
}
tb_vclass *v = new tb_vclass(s,weight);
vclass_map.insert(s,v);
while ((scur = strsep(&snext, " ")) != NULL) {
string s2(scur);
v->add_type(s2);
vtypes.push(s2);
}
}
} else {
fprintf(stderr, "unknown directive: %s\n", inbuf);
}
......
......@@ -18,6 +18,7 @@
#include "common.h"
#include "physical.h"
#include "vclass.h"
#include "virtual.h"
#include "pclass.h"
......@@ -252,7 +253,7 @@ void pclass_debug()
int n = type_table.inf(dit).first();
pclass_array &A = *(type_table.inf(dit).second());
for (int i = 0; i < n ; ++i) {
cout << " " << A[i];
cout << " " << A[i]->name;
}
cout << "\n";
}
......
......@@ -25,6 +25,7 @@
#include <string.h>
#include "common.h"
#include "vclass.h"
#include "virtual.h"
#include "physical.h"
#include "pclass.h"
......@@ -143,10 +144,24 @@ void remove_node(node n)
// pclass
if (pnoder.my_class->used == 0) {
#ifdef SCORE_DEBUG
cerr << " freeing pclass\n";
cerr << " freeing pclass\n";
#endif
SSUB(SCORE_PCLASS);
}
// vclass
if (vnoder.vclass != NULL) {
double score_delta = vnoder.vclass->unassign_node(vnoder.type);
#ifdef SCORE_DEBUG
cerr << " vclass unassign " << score_delta << endl;
#endif
if (score_delta <= -1) {
violated--;
vinfo.vclass--;
}
SSUB(-score_delta*SCORE_VCLASS);
}
edge e;
tb_vlink *vlink;
......@@ -510,11 +525,24 @@ int add_node(node n,int ploc)
// pclass
if (pnoder.my_class->used == 0) {
#ifdef SCORE_DEBUG
cerr << " new pclass\n";
cerr << " new pclass\n";
#endif
SADD(SCORE_PCLASS);
}
// vclass
if (vnoder.vclass != NULL) {
double score_delta = vnoder.vclass->assign_node(vnoder.type);
#ifdef SCORE_DEBUG
cerr << " vclass assign " << score_delta << endl;
#endif
SADD(score_delta*SCORE_VCLASS);
if (score_delta >= 1) {
violated++;
vinfo.vclass++;
}
}
#ifdef SCORE_DEBUG
fprintf(stderr," posistion = %d\n",vnoder.posistion);
fprintf(stderr," new score = %.2f new violated = %d\n",score,violated);
......
......@@ -10,6 +10,7 @@ typedef struct {
int link_users;
int bandwidth;
int desires;
int vclass;
} violated_info;
extern float score;
......
#include <LEDA/graph_alg.h>
#include <LEDA/graphwin.h>
#include <LEDA/ugraph.h>
#include <LEDA/dictionary.h>
#include <LEDA/map.h>
#include <LEDA/graph_iterator.h>
#include <LEDA/node_pq.h>
#include <LEDA/sortseq.h>
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <string.h>
#include <assert.h>
#include "common.h"
#include "vclass.h"
#include "virtual.h"
void tb_vclass::add_type(string type)
{
members.insert(type,0);
if (members.lookup(dominant) == 0) {
dominant = type;
}
}
double tb_vclass::assign_node(string type)
{
double new_score = score;
dic_item dit = members.lookup(type);
int newnum = members.inf(dit) + 1;
members.change_inf(dit,newnum);
if (type != dominant) {
if (members.access(dominant) != 0) {
new_score = weight;
}
if (newnum > members.access(dominant)) {
dominant = type;
}
}
double delta = new_score-score;
score=new_score;
return delta;
}
double tb_vclass::unassign_node(string type)
{
double new_score = 0;
dic_item dit = members.lookup(type);
int newnum = members.inf(dit) - 1;
members.change_inf(dit,newnum);
int curmax = 0;
forall_items(dit,members) {
int n = members.inf(dit);
if (n > curmax) {
if (curmax != 0) {
new_score = weight;
}
curmax = n;
dominant = members.key(dit);
}
}
double delta = new_score-score;
score=new_score;
return delta;
}
string tb_vclass::choose_type()
{
// This may take some tweaking
if (random()%2 == 0) {
return dominant;
}
int r = random()%members.size();
dic_item dit;
forall_items(dit,members) {
if (r == 0) break;
r--;
}
return members.key(dit);
}
void tb_vclass::dump_data()
{
cerr << "vclass: " << name;
cerr << " dominant: " << dominant;
cerr << " weight: " << weight;
cerr << " score: " << score << endl;
dic_item dit;
cerr << " ";
forall_items(dit,members) {
cerr << members.key(dit) << ":" << members.inf(dit) << " ";
}
cerr << endl;
}
#ifndef __VCLASS_H
#define __VCLASS_H
class tb_vclass {
public:
tb_vclass(string n,double w) : name(n), weight(w), score(0) {;}
string name;
dictionary<string,int> members;
string dominant;
double weight;
double score; // the current score of the vclass
void add_type(string type);
// The next two routines report the *change* in score. The score
// for the vclass as a whole is 0 if all nodes are of the dominant
// type and the weight if they aren't.
double assign_node(string type);
double unassign_node(string type);
string choose_type();
void dump_data();
};
#endif
......@@ -18,7 +18,8 @@ public:
sortseq<string,double> desires; // contains weight of each desire
int posistion; // index into pnode array
int no_connections; // how many unfulfilled connections from this node
string type;
string type; // the current type of the node
tb_vclass *vclass; // the virtual class of the node, if any
string name; // string name of the node
bool fixed; // is this node fixed
};
......
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