Commit a60e81ac authored by Mac Newbold's avatar Mac Newbold

Changes to allow scoring/heuristic parameters to be passed in commandline.

parent 6d2a7389
......@@ -14,12 +14,16 @@ include $(TESTBED_SRCDIR)/GNUmakerules
LEDA=@LEDA@
OBJS=score.o parse_top.o parse_ptop.o
OBJS=score.o parse_top.o parse_ptop.o config.o
LIBS+=-L${LEDA} -lD3 -lW -lP -lG -lL -L/usr/X11R6/lib -lX11 -lm -L.
LDFLAGS+= -O3 -fomit-frame-pointer -m486
CXXFLAGS = -I${LEDA}/incl
# Pick one of the two below.
CXXFLAGS += -Wall -O3 -fomit-frame-pointer -m486 -DUSE_OPTIMAL
#CXXFLAGS += -Wall -O3 -fomit-frame-pointer -m486
#CXXFLAGS += -Wall -O3 -fomit-frame-pointer -m486 -DUSE_OPTIMAL
CXXFLAGS += -O0 -g -Wall -DSCORE_DEBUG -DVERBOSE -DSCORE_DEBUG
#CXXFLAGS += -O0 -g -Wall -DSCORE_DEBUG -DVERBOSE -DSCORE_DEBUG -DUSE_OPTIMAL
#CXXFLAGS += -O0 -g -Wall -DSCORE_DEBUG -DVERBOSE -DSCORE_DEBUG_MORE
#CXXFLAGS += -O0 -g -Wall -DSCORE_DEBUG -DVERBOSE -DSCORE_DEBUG_MORE -DUSE_OPTIMAL
DEPLIBS=$(OBJS)
......
......@@ -19,13 +19,18 @@
#include "virtual.h"
#include "score.h"
void parse_options(char **argv, struct config_param options[], int nopt);
int config_parse(char **args, struct config_param cparams[], int nparams);
void dump_options(const char *str, struct config_param cparams[], int nparams);
// Purely heuristic
#ifdef USE_OPTIMAL
#define OPTIMAL_SCORE(edges,nodes) (nodes*SCORE_PNODE + \
nodes/5.0*SCORE_SWITCH + \
nodes/opt_nodes_per_sw*SCORE_SWITCH + \
edges*((SCORE_INTRASWITCH_LINK+ \
SCORE_DIRECT_LINK*2)*4+\
SCORE_INTERSWITCH_LINK)/5.0)
SCORE_INTERSWITCH_LINK)/opt_nodes_per_sw)
#else
#define OPTIMAL_SCORE(edges,nodes) 0
#endif
......@@ -48,9 +53,6 @@ int batch_mode = 0;
float sensitivity = .1;
static const int initial_temperature = 100;
static const int temp_prob = 130;
int refreshed = 0;
node_array<int> bestnodes, absnodes;
......@@ -115,7 +117,7 @@ int assign()
nnodes = G.number_of_nodes();
float cycles = 120.0*(float)(nnodes + G.number_of_edges());
float cycles = CYCLES*(float)(nnodes + G.number_of_edges());
float optimal = OPTIMAL_SCORE(G.number_of_edges(),nnodes);
#ifdef STATS
......@@ -131,7 +133,7 @@ int assign()
int bestviolated;
int absbestv;
float temp = initial_temperature;
float temp = init_temp;
/* Set up the initial counts */
init_score();
......@@ -153,7 +155,7 @@ int assign()
goto DONE;
}
while (temp >= 2) {
while (temp >= temp_stop) {
#ifdef VERBOSE
cout << "Temperature: " << temp << endl;
#endif
......@@ -244,7 +246,7 @@ int assign()
}
}
temp *= .9;
temp *= temp_rate;
}
DONE:
......@@ -433,6 +435,16 @@ int main(int argc, char **argv)
argc -= optind;
argv += optind;
/* newbold@cs
These relate to the globals defined in common.h
It reads in all the parameters for the program that were formerly
all hardcoded constants.
*/
parse_options(argv, options, noptions);
#ifdef SCORE_DEBUG
dump_options("Send options", options, noptions);
#endif
int seed = time(NULL)+getpid();
if (getenv("ASSIGN_SEED") != NULL) {
sscanf(getenv("ASSIGN_SEED"),"%d",&seed);
......
#ifndef __COMON_H
#define __COMON_H
const int MAX_PNODES = 1024; // maximum # of physical nodes
#include "config.h"
const int MAX_PNODES = 1024; /* maximum # of physical nodes */
/*
To use these on the command line, each entry gets a
<name>=<value> pair on the command line.
Here we declare them all and give them defaults.
*/
static int init_temp = 100;
static int USE_OPTIMAL = 1;
static int temp_prob = 130;
static int temp_stop = 2;
static int CYCLES = 120;
static float temp_rate = 0.9;
static float opt_nodes_per_sw = 5.0;
static float SCORE_DIRECT_LINK = 0.01;/* Cost of a direct link */
static float SCORE_DIRECT_LINK_PENALTY = 0.5;/* Cost of overused direct link*/
static float SCORE_INTRASWITCH_LINK = 0.02;/* Cost of an intraswitch link*/
static float SCORE_INTERSWITCH_LINK = 0.05;/* Cost of an interswitch link*/
static float SCORE_NO_CONNECTION = 0.5;/* Cost of not filling a virt. link*/
static float SCORE_PNODE = 0.05;/* Cost of using a pnode*/
static float SCORE_PNODE_PENALTY = 0.5;/* Cost of overusing a pnode*/
static float SCORE_SWITCH = 0.5;/* Cost of using a switch.*/
static float SCORE_UNASSIGNED = 1;/* Cost of an unassigned node*/
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 struct config_param options[] = {
{ "IT", CONFIG_INT, &init_temp, 0 },
{ "OP", CONFIG_INT, &USE_OPTIMAL, 0 },
{ "TP", CONFIG_INT, &temp_prob, 0 },
{ "TS", CONFIG_INT, &temp_stop, 0 },
{ "CY", CONFIG_INT, &CYCLES, 0 },
{ "UN", CONFIG_FLOAT, &SCORE_UNASSIGNED, 0 },
{ "DE", CONFIG_FLOAT, &SCORE_DESIRE, 0 },
{ "FE", CONFIG_FLOAT, &SCORE_FEATURE, 0 },
{ "1S", CONFIG_FLOAT, &SCORE_INTERSWITCH_LINK, 0 },
{ "2S", CONFIG_FLOAT, &SCORE_INTRASWITCH_LINK, 0 },
{ "NC", CONFIG_FLOAT, &SCORE_NO_CONNECTION, 0 },
{ "OB", CONFIG_FLOAT, &SCORE_OVER_BANDWIDTH, 0 },
{ "DL", CONFIG_FLOAT, &SCORE_DIRECT_LINK, 0 },
{ "DP", CONFIG_FLOAT, &SCORE_DIRECT_LINK_PENALTY, 0 },
{ "PN", CONFIG_FLOAT, &SCORE_PNODE, 0 },
{ "PP", CONFIG_FLOAT, &SCORE_PNODE_PENALTY, 0 },
{ "SW", CONFIG_FLOAT, &SCORE_SWITCH, 0 },
{ "ON", CONFIG_FLOAT, &opt_nodes_per_sw, 0 },
{ "TR", CONFIG_FLOAT, &temp_rate, 0 }
};
static int noptions = sizeof(options) / sizeof(options[0]);
#endif
......
/*
* Copyright (c) 1999-2001 The University of Utah and the Flux Group.
* All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
/*
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "config.h"
#include "tgenlib.h"
*/
/*
* Dumb as a stump config for options that the test program supports
*/
void
parse_options(char **argv, struct config_param options[], int nopt)
{
extern char **environ;
/* get from environment first */
config_parse(environ, options, nopt);
/* then command line */
config_parse(argv, options, nopt);
}
int
config_parse(char **args, struct config_param cparams[], int nparams)
{
int i, j, len;
char *arg, *bp, *var, *val, buf[256];
for (i = 0, arg = args[i]; arg != 0; i++, arg = args[i]) {
len = sizeof(buf) - 1;
strncpy(buf, arg, len);
buf[len] = 0;
var = val = buf;
if (strsep(&val, "=") == 0 || val == 0 || *val == 0)
continue;
for (j = 0; j < nparams; j++)
if (strcmp(var, cparams[j].name) == 0)
break;
if (j == nparams)
continue;
if (cparams[j].func) {
cparams[j].func(&cparams[j], val);
continue;
}
switch (cparams[j].type) {
case CONFIG_INT:
*(int *)cparams[j].ptr = atoi(val);
break;
case CONFIG_FLOAT:
*(float *)cparams[j].ptr = (float) atof(val);
break;
/*
case CONFIG_STRING:
bp = malloc(strlen(val) + 1);
assert(bp);
strcpy(bp, val);
*(char **)cparams[j].ptr = bp;
break;
*/
}
}
return 0;
}
void
dump_options(const char *str, struct config_param cparams[], int numparams)
{
int i;
fprintf(stderr,"%s configuration:\n", str);
for (i = 0; i < numparams; i++) {
fprintf(stderr," %s ", cparams[i].name);
switch (cparams[i].type) {
case CONFIG_INT:
fprintf(stderr,"%d\n",
*(int *)cparams[i].ptr);
break;
case CONFIG_FLOAT:
fprintf(stderr,"%f\n",
*(float *)cparams[i].ptr);
break;
/*
case CONFIG_STRING:
fprintf(stderr,"%s\n", *(char **)cparams[i].ptr ?
*(char **)cparams[i].ptr : "<unset>");
break;
*/
}
}
}
/*
* Copyright (c) 1999-2001 The University of Utah and the Flux Group.
* All rights reserved.
*/
#ifndef __CONFIG_H
#define __CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Dumb as a stump config for options that the test program supports
*/
struct config_param {
const char *name; /* name of the option */
int type; /* type (see below) */
void *ptr; /* pointer to value portion */
void (*func)(struct config_param *opt, char *newval);
/* function to set value */
};
/* types */
#define CONFIG_INT 0
#define CONFIG_FLOAT 1
void parse_options(char **argv, struct config_param options[], int nopt);
int config_parse(char **args, struct config_param cparams[], int nparams);
void dump_options(const char *str, struct config_param cparams[], int nparams);
#ifdef __cplusplus
}
#endif
#endif
......@@ -2,39 +2,6 @@
#ifndef _SCORE_H
#define _SCORE_H
// Cost of a direct link
const float SCORE_DIRECT_LINK = 0.01;
// Cost of overusing a direct link
const float SCORE_DIRECT_LINK_PENALTY = 0.5;
// Cost of an intraswitch link
const float SCORE_INTRASWITCH_LINK = 0.02;
// Cost of an interswitch link
const float SCORE_INTERSWITCH_LINK = 0.05;
// Cost of being unable to fulfill a virtual link
const float SCORE_NO_CONNECTION = 0.5;
// Cost of using a pnode
const float SCORE_PNODE = 0.05;
// Cost of overusing a pnode
const float SCORE_PNODE_PENALTY = 0.5;
// Cost of using a switch.
const float SCORE_SWITCH = 0.5;
// Cost of an unassigned node
const float SCORE_UNASSIGNED = 1;
// Cost of going over bandwidth
const float SCORE_OVER_BANDWIDTH = 0.5;
// Multiplier for desire costs
const float SCORE_DESIRE = 1;
// Multiplier for feature weights
const float SCORE_FEATURE = 1;
typedef struct {
int unassigned;
......
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