Commit dfd5fb50 authored by Christopher Alfeld's avatar Christopher Alfeld

* Added extra violated info for better understanding of failures.

* Fixed bug when OPTIMAL solution found.
* Fixed bug in length two interswitch paths.
parent 2d008e2c
......@@ -187,30 +187,23 @@ int assign()
// instead re randomly choose a node and remove it and
// then continue the 'continue'
// XXX - could improve this
node n = G.choose_node();
while (G[n].posistion != 0)
n = G.choose_node();
remove_node(n);
unassigned_nodes.insert(n,random());
node ntor = G.choose_node();
while (G[ntor].posistion == 0)
ntor = G.choose_node();
remove_node(ntor);
unassigned_nodes.insert(ntor,random());
continue;
}
}
if (unassigned) unassigned_nodes.del(n);
newscore = get_score();
// if (newscore < 0.11f) {
if (newscore < optimal) {
timeend = used_time(timestart);
cout << "OPTIMAL ( " << optimal << ") in "
<< iters << " iters, "
<< timeend << " seconds" << endl;
goto DONE;
}
/* So it's negative if bad */
scorediff = bestscore - newscore;
// tinkering aournd witht his.
if ((violated < bestviolated) ||
if ((newscore < optimal) || (violated < bestviolated) ||
((violated == bestviolated) && (newscore < bestscore)) ||
accept(scorediff*((bestviolated - violated)/2), temp)) {
bestnodes[n] = G[n].posistion;
......@@ -228,6 +221,14 @@ int assign()
absbestv = violated;
cycles_to_best = iters;
}
// if (newscore < 0.11f) {
if (newscore < optimal) {
timeend = used_time(timestart);
cout << "OPTIMAL ( " << optimal << ") in "
<< iters << " iters, "
<< timeend << " seconds" << endl;
goto DONE;
}
} else { /* Reject this change */
remove_node(n);
if (oldpos != 0) {
......@@ -267,6 +268,12 @@ int assign()
cout << "With " << violated << " violations" << endl;
cout << "With " << accepts << " accepts of increases\n";
cout << "Iters to find best score: " << cycles_to_best << endl;
cout << "Violations: " << violated << endl;
cout << " unassigned: " << vinfo.unassigned << endl;
cout << " pnode_load: " << vinfo.pnode_load << endl;
cout << " no_connect: " << vinfo.no_connection << endl;
cout << " link_users: " << vinfo.link_users << endl;
cout << " bandwidth: " << vinfo.bandwidth << endl;
return 0;
}
......@@ -529,6 +536,9 @@ int main(int argc, char **argv)
argv += optind;
int seed = time(NULL)+getpid();
if (getenv("ASSIGN_SEED") != NULL) {
sscanf(getenv("ASSIGN_SEED"),"%d",&seed);
}
printf("seed = %d\n",seed);
srandom(seed);
......
......@@ -122,6 +122,14 @@ int parse_ptop(tb_pgraph &PG, istream& i)
dnode = strsep(&dmac,":");
string s1(snode);
string s2(dnode);
if (nmap.lookup(s1) == nil) {
fprintf(stderr,"PTOP error: Unknown source node %s\n",snode);
exit(1);
}
if (nmap.lookup(s2) == nil) {
fprintf(stderr,"PTOP error: Unknown destination node %s\n",dnode);
exit(1);
}
node node1 = nmap.access(s1);
node node2 = nmap.access(s2);
for (int i = 0; i < num; ++i) {
......
......@@ -35,6 +35,8 @@ int violated; // How many times the restrictions
node pnodes[MAX_PNODES]; // int->node map
// pnodes[0] == NULL
violated_info vinfo; // specific info on violations
extern tb_vgraph G; // virtual graph
extern tb_pgraph PG; // physical grpaph
......@@ -71,6 +73,8 @@ void init_score()
#endif
score=0;
violated=0;
vinfo.unassigned = vinfo.pnode_load = 0;
vinfo.no_connection = vinfo.link_users = vinfo.bandwidth = 0;
node n;
edge e;
......@@ -79,6 +83,7 @@ void init_score()
vn.posistion=0;
vn.no_connections=0;
SADD(SCORE_UNASSIGNED);
vinfo.unassigned++;
violated++;
}
forall_edges(e,G) {
......@@ -194,6 +199,7 @@ void remove_node(node n)
// remove scores associated with the node
SSUB(SCORE_NO_CONNECTION*vnoder.no_connections);
violated -= vnoder.no_connections;
vinfo.no_connection -= vnoder.no_connections;
// adjust pnode scores
pnoder.current_load--;
......@@ -221,10 +227,12 @@ void remove_node(node n)
fprintf(stderr," reducing penalty, new load = %d (>= %d)\n",pnoder.current_load,pnoder.max_load);
#endif
SSUB(SCORE_PNODE_PENALTY);
vinfo.pnode_load--;
violated--;
}
// add score for unassigned node
SADD(SCORE_UNASSIGNED);
vinfo.unassigned++;
violated++;
#ifdef SCORE_DEBUG
fprintf(stderr," new score = %.2f new violated = %d\n",score,violated);
......@@ -378,9 +386,14 @@ int add_node(node n,int ploc)
#ifdef SCORE_DEBUG
fprintf(stderr," could not find path - no connection\n");
#endif
// XXX - this is a hack for the moment
pnoder.current_type = TYPE_UNKNOWN;
return 1;
// couldn't find path.
vnoder.no_connections++;
SADD(SCORE_NO_CONNECTION);
vinfo.no_connection++;
violated++;
} else {
#ifdef SCORE_DEBUG
......@@ -417,6 +430,7 @@ int add_node(node n,int ploc)
fprintf(stderr," load to high - penalty (%d)\n",pnoder.current_load);
#endif
SADD(SCORE_PNODE_PENALTY);
vinfo.pnode_load++;
violated++;
} else {
#ifdef SCORE_DEBUG
......@@ -439,6 +453,7 @@ int add_node(node n,int ploc)
// node no longer unassigned
SSUB(SCORE_UNASSIGNED);
vinfo.unassigned--;
violated--;
#ifdef SCORE_DEBUG
......@@ -534,19 +549,29 @@ int find_interswitch_path(node src,node dst,int bandwidth,edge *f,edge *s)
edge best_first,best_second;
float best_bw;
float bw;
int best_length = 1000;
best_bw=100.0;
best_first = best_second = NULL;
if (!src || ! dst) return 0;
// try to find a path to the destination
node ldst,ldstb;
edge first,second;
#ifdef SCORE_DEBUG
tb_pnode *ldstr,*ldstbr;
tb_plink *firstr,*secondr;
#endif
forall_inout_edges(first,src) {
ldst = PG.target(first);
if (ldst == src)
ldst = PG.source(first);
#ifdef SCORE_DEBUG
ldstr = &PG[ldst];
firstr = &PG[first];
#endif
if (ldst == dst) {
// we've found a path, it's just firstedge
if (first)
......@@ -555,14 +580,19 @@ int find_interswitch_path(node src,node dst,int bandwidth,edge *f,edge *s)
best_first = first;
best_bw = bw;
best_second = NULL;
best_length = 1;
}
}
forall_inout_edges(second,ldst) {
ldstb = PG.target(second);
if (ldstb == ldst)
ldstb = PG.source(second);
#ifdef SCORE_DEBUG
ldstbr = &PG[ldstb];
secondr = &PG[second];
#endif
if (ldstb == dst) {
if (! best_second) continue;
if (best_length == 1) continue;
bw = (PG[first].bw_used+bandwidth)/PG[first].bandwidth;
if (second)
// NOTE: One thing to try differently.
......@@ -571,6 +601,7 @@ int find_interswitch_path(node src,node dst,int bandwidth,edge *f,edge *s)
best_first = first;
best_second = second;
best_bw = bw;
best_length = 2;
}
}
}
......@@ -608,6 +639,7 @@ void score_link(edge e,edge v,bool interswitch)
fprintf(stderr," not first user - penalty\n");
#endif
SADD(SCORE_DIRECT_LINK_PENALTY);
vinfo.link_users++;
violated++;
}
}
......@@ -622,6 +654,7 @@ void score_link(edge e,edge v,bool interswitch)
pl.bw_used,pl.bandwidth);
#endif
violated++;
vinfo.bandwidth++;
SADD(SCORE_OVER_BANDWIDTH);
}
}
......@@ -649,6 +682,7 @@ void unscore_link(edge e,edge v,bool interswitch)
fprintf(stderr," reducing users\n");
#endif
SSUB(SCORE_DIRECT_LINK_PENALTY);
vinfo.link_users--;
violated--;
}
}
......@@ -663,6 +697,7 @@ void unscore_link(edge e,edge v,bool interswitch)
pl.bw_used,pl.bandwidth);
#endif
violated--;
vinfo.bandwidth--;
SSUB(SCORE_OVER_BANDWIDTH);
}
}
......@@ -30,8 +30,17 @@ const float SCORE_UNASSIGNED = 1;
// Cost of going over bandwidth
const float SCORE_OVER_BANDWIDTH = 0.5;
typedef struct {
int unassigned;
int pnode_load;
int no_connection;
int link_users;
int bandwidth;
} violated_info;
extern float score;
extern int violated;
extern violated_info vinfo;
void init_score();
void remove_node(node n);
......
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