Commit 19ddb13d authored by Christopher Alfeld's avatar Christopher Alfeld

Code for fixed nodes stuff.

parent 19556013
......@@ -51,6 +51,10 @@ dictionary<tb_pnode*,int> pnode2posistion;
pclass_list pclasses;
dictionary<string,pclass_list*> type_table;
dictionary<string,node> pname2node;
dictionary<string,node> vname2node;
dictionary<string,string> fixed_nodes;
/* How can we chop things up? */
#define PARTITION_BY_ANNEALING 0
......@@ -208,6 +212,32 @@ int assign()
/* Set up the initial counts */
init_score();
/* Set up fixed nodes */
dic_item fixed_it;
forall_items(fixed_it,fixed_nodes) {
if (vname2node.lookup(fixed_nodes.key(fixed_it)) == nil) {
cerr << "Fixed node: " << fixed_nodes.key(fixed_it)
<< " does not exist.\n",
exit(1);
}
node vn = vname2node.access(fixed_nodes.key(fixed_it));
if (pname2node.lookup(fixed_nodes.inf(fixed_it)) == nil) {
cerr << "Fixed node: " << fixed_nodes.inf(fixed_it)
<< " does not exist.\n",
exit(1);
}
node pn = pname2node.access(fixed_nodes.inf(fixed_it));
int ppos = pnode2posistion.access(&PG[pn]);
if (add_node(vn,ppos) == 1) {
cerr << "Fixed node: Could not map " << fixed_nodes.key(fixed_it)
<< " to " << fixed_nodes.inf(fixed_it) << ".\n";
exit(1);
}
unassigned_nodes.del(vn);
G[vn].fixed=true;
}
bestscore = get_score();
bestviolated = violated;
#ifdef VERBOSE
......@@ -247,8 +277,10 @@ int assign()
iters++;
n = unassigned_nodes.find_min();
if (n == nil)
while (n == nil) {
n = G.choose_node();
if (G[n].fixed) n=nil;
}
// Note: we have a lot of +1's here because of the first
// node loc in pnodes is 1 not 0.
......@@ -362,7 +394,11 @@ int assign()
int pos = 0;
node ntor;
while (pos == 0) {
ntor = G.choose_node();
ntor=nil;
while (ntor == nil) {
ntor = G.choose_node();
if (G[ntor].fixed) ntor=nil;
}
pos = G[ntor].posistion;
}
remove_node(ntor);
......
......@@ -14,7 +14,7 @@ const int MAX_PNODES = 1024; /* maximum # of physical nodes */
static int init_temp = 100;
static int USE_OPTIMAL = 1;
static int temp_prob = 130;
static int temp_stop = 2;
static int temp_stop = 20;
static int CYCLES = 20;
static float temp_rate = 0.9;
......
......@@ -24,6 +24,7 @@
#include "common.h"
#include "physical.h"
extern dictionary<string,node> pname2node;
extern node pnodes[MAX_PNODES]; // int -> node map
node_array<int> switch_index;
extern list<string> ptypes;
......@@ -31,7 +32,6 @@ extern list<string> ptypes;
int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
{
int switchi=0;
dictionary<string, node> nmap;
node no1;
edge ed1;
string s1, s2;
......@@ -116,7 +116,7 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
/* Done */
if (! isswitch)
pnodes[n++]=no1;
nmap.insert(s, no1);
pname2node.insert(s, no1);
}
}
else if (!strncmp(inbuf, "link", 4)) {
......@@ -131,16 +131,16 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
dmac = n2;
snode = strsep(&smac,":");
dnode = strsep(&dmac,":");
if (nmap.lookup(snode) == nil) {
if (pname2node.lookup(snode) == nil) {
fprintf(stderr,"PTOP error: Unknown source node %s\n",snode);
exit(1);
}
if (nmap.lookup(dnode) == nil) {
if (pname2node.lookup(dnode) == nil) {
fprintf(stderr,"PTOP error: Unknown destination node %s\n",dnode);
exit(1);
}
node node1 = nmap.access(snode);
node node2 = nmap.access(dnode);
node node1 = pname2node.access(snode);
node node2 = pname2node.access(dnode);
#define ISSWITCH(n) (PG[n].types.lookup("switch") != nil)
for (int i = 0; i < num; ++i) {
ed1=PG.new_edge(node1, node2);
......
......@@ -17,6 +17,8 @@
#include "common.h"
#include "virtual.h"
extern dictionary<string,node> vname2node;
extern dictionary<string,string> fixed_nodes;
extern list<string> vtypes;
extern tb_vgraph G;
......@@ -24,7 +26,6 @@ extern node_pq<int> unassigned_nodes;
int parse_top(tb_vgraph &G, istream& i)
{
dictionary<string, node> nmap;
node no1;
string s1, s2;
char inbuf[255];
......@@ -58,9 +59,10 @@ int parse_top(tb_vgraph &G, istream& i)
G[no1].name=string(scur);
G[no1].posistion = 0;
G[no1].no_connections=0;
nmap.insert(s1, no1);
vname2node.insert(s1, no1);
scur=strsep(&snext," ");
G[no1].type=string(scur);
G[no1].fixed = false; // this may get set to true later
vtypes.push(G[no1].type);
/* Read in desires */
......@@ -79,15 +81,15 @@ int parse_top(tb_vgraph &G, istream& i)
}
} else if (!strncmp(inbuf, "link", 4)) {
r=sscanf(inbuf, "link %s %s %s %d", lname, n1, n2,&bw);
if (r < 2) {
if (r < 3) {
fprintf(stderr, "bad link line: %s\n", inbuf);
} else {
if (r == 2) bw = 10;
if (r == 3) bw = 10;
string s1(n1);
string s2(n2);
edge e;
node node1 = nmap.access(s1);
node node2 = nmap.access(s2);
node node1 = vname2node.access(s1);
node node2 = vname2node.access(s2);
e = G.new_edge(node1, node2);
G[e].bandwidth = bw;
G[e].type = tb_vlink::LINK_UNKNOWN;
......@@ -95,8 +97,16 @@ int parse_top(tb_vgraph &G, istream& i)
G[e].plink_two = NULL;
G[e].name = string(lname);
}
}
else {
} else if (! strncmp(inbuf, "fix-node",8)) {
r=sscanf(inbuf,"fix-node %s %s",n1,n2);
if (r != 2) {
fprintf(stderr, "bad fix-node line: %s\n",inbuf);
} else {
string s1(n1);
string s2(n2);
fixed_nodes.insert(s1,s2);
}
} else {
fprintf(stderr, "unknown directive: %s\n", inbuf);
}
}
......
......@@ -20,6 +20,7 @@ public:
int no_connections; // how many unfulfilled connections from this node
string type;
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