common.h 7.44 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1 2
/*
 * EMULAB-COPYRIGHT
3
 * Copyright (c) 2000-2006 University of Utah and the Flux Group.
Robert Ricci's avatar
Robert Ricci committed
4 5 6
 * All rights reserved.
 */

7 8 9
#ifndef __COMON_H
#define __COMON_H

10 11
#include "port.h"

12 13 14 15
/*
 * We have to do these includes differently depending on which version of gcc
 * we're compiling with
 */
16
#ifdef NEW_GCC
17
#include <ext/hash_map>
18
#include <ext/hash_fun.h>
19
using namespace __gnu_cxx;
20
#define RANDOM() random()
21 22
#else
#include <hash_map>
23
#define RANDOM() std::random()
24 25
#endif

26
#include "config.h"
27
#include <utility>
28 29
#include "port.h"
#include "fstring.h"
30

31 32
#include <boost/graph/adjacency_list.hpp>

33 34 35 36 37 38 39 40
/*
 * Exit vaules from assign
 */

// A solution with no violations was found
#define EXIT_SUCCESS 0

// No valid solution was found, but one may exist
41
// No violation-free solution was found after annealing.
42 43 44 45 46
#define EXIT_RETRYABLE 1

// It is not possible to map the given top file into the given ptop file,
// so there's no point in re-running assign.
#define EXIT_UNRETRYABLE 2
47

48 49 50 51
// An internal error occured, or there was a problem with the input - for
// example, the top or ptop file does not exist or cannot be parsed
#define EXIT_FATAL -1

52 53 54 55 56 57
/*
  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.
*/

58 59
//static int init_temp = 100;
static int init_temp = 10;
60 61
static int USE_OPTIMAL = 1;
static int temp_prob = 130;
62 63 64 65 66 67 68
#ifdef LOW_TEMP_STOP
//static int temp_stop = 1;
static float temp_stop = .005;
#else
static float temp_stop = 2;
//static int temp_stop = 20;
#endif
69
static int CYCLES = 20;
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84
// The following are basically arbitrary constants
// Initial acceptance ratio for melting
static float X0 = .95;
//static float epsilon = 0.1;
#ifdef LOCAL_DERIVATIVE
static float epsilon = 0.0001;
#else
static float epsilon = 0.01;
#endif
static float delta = 2;
//static float delta = 1;
//static float min_temp_end = 0.01;
//static float min_temp_end = 10000000.0;

85 86 87
// The weight at which a feature or desire triggers a violations if
// unstatisfied or unused
static float FD_VIOLATION_WEIGHT = 1.0;
88 89

// Number of runs to spend melting
90 91
static int melt_trans = 1000;
static int min_neighborhood_size = 1000;
92 93


94 95
static float temp_rate = 0.9;
static float opt_nodes_per_sw = 5.0;
96 97 98 99 100
#ifdef PENALIZE_BANDWIDTH
static float SCORE_DIRECT_LINK = 0.0;/* Cost of a direct link */
static float SCORE_INTRASWITCH_LINK = 0.0;/* Cost of an intraswitch link*/
static float SCORE_INTERSWITCH_LINK = 0.0;/* Cost of an interswitch link*/
#else
101
static float SCORE_DIRECT_LINK = 0.01;/* Cost of a direct link */
102
static float SCORE_INTRASWITCH_LINK = 0.02;/* Cost of an intraswitch link*/
103 104 105
static float SCORE_INTERSWITCH_LINK = 0.2;/* Cost of an interswitch link*/
#endif
static float SCORE_DIRECT_LINK_PENALTY = 0.5;/* Cost of overused direct link*/
106
static float SCORE_NO_CONNECTION = 0.5;/* Cost of not filling a virt. link*/
107
static float SCORE_PNODE = 0.2;/* Cost of using a pnode*/
108 109
static float SCORE_PNODE_PENALTY = 0.5;/* Cost of overusing a pnode*/
static float SCORE_SWITCH = 0.5;/* Cost of using a switch.*/
110 111 112
static float SCORE_UNASSIGNED = 1.0;/* Cost of an unassigned node*/
static float SCORE_DESIRE = 1.0;/* Multiplier for desire costs*/
static float SCORE_FEATURE = 1.0;/* Multiplier for feature weights*/
113 114
static float SCORE_MISSING_LOCAL_FEATURE = 1.0;
static float SCORE_OVERUSED_LOCAL_FEATURE = 0.5;
115 116 117
#ifdef NO_PCLASS_PENALTY
static float SCORE_PCLASS = 0.0; /* Cost of each pclass */
#else
118
static float SCORE_PCLASS = 0.5; /* Cost of each pclass */
119 120
#endif
static float SCORE_VCLASS = 1.0; /* vclass score multiplier */
121
static float SCORE_EMULATED_LINK = 0.01; /* cost of an emualted link */
122 123 124 125 126 127
static float SCORE_OUTSIDE_DELAY = 0.5;	/* penalty for going out of delay
					   requirements */
static float SCORE_DELAY = 10.0; /* multiplier to distance for delay scoring */
#ifdef PENALIZE_UNUSED_INTERFACES
static float SCORE_UNUSED_INTERFACE = 0.04;
#endif
128
static float SCORE_TRIVIAL_PENALTY = 0.5; /* Cost of over-using a trivial link */
129

130 131 132 133
static float SCORE_TRIVIAL_MIX = 0.5; /* Cost of mixing trivial and non-trivial
					 links */

static float SCORE_SUBNODE = 0.5; /* Cost of not properly assigning subnodes */
134 135 136
static float SCORE_MAX_TYPES = 0.15; /* Cost of going over type limits - low 
                                      * enough that assign ususally picks this
				      * over leaving a node unassigned */
137

138
// The following are used to weight possible link resolutions.  Higher
139 140
// numbers mean a more likely resolution.
static float LINK_RESOLVE_TRIVIAL = 8.0;
141 142 143
static float LINK_RESOLVE_DIRECT = 4.0;
static float LINK_RESOLVE_INTRASWITCH = 2.0;
static float LINK_RESOLVE_INTERSWITCH = 1.0;
144

145 146 147
// The amount that each violation contributes to the total score
static float VIOLATION_SCORE = 1.0;

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
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 },
  { "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 },
164
  { "PC",	CONFIG_FLOAT,	&SCORE_PCLASS,		        0 },
165
  { "VC",       CONFIG_FLOAT,   &SCORE_VCLASS,                  0 },
166
  { "SW",	CONFIG_FLOAT,	&SCORE_SWITCH,			0 },
167
  { "EL",	CONFIG_FLOAT,	&SCORE_EMULATED_LINK,		0 },
168
  { "ON",	CONFIG_FLOAT,	&opt_nodes_per_sw,		0 },
169 170 171 172 173 174
  { "TR",	CONFIG_FLOAT,	&temp_rate,			0 },
  { "LD",       CONFIG_FLOAT,   &LINK_RESOLVE_DIRECT,           0 },
  { "LI",       CONFIG_FLOAT,   &LINK_RESOLVE_INTRASWITCH,      0 },
  { "LT",       CONFIG_FLOAT,   &LINK_RESOLVE_INTERSWITCH,      0 },
  { "OD",       CONFIG_FLOAT,   &SCORE_OUTSIDE_DELAY,           0 },
  { "DM",       CONFIG_FLOAT,   &SCORE_DELAY,                   0 }
175 176 177
};

static int noptions = sizeof(options) / sizeof(options[0]);
178

179 180 181 182 183 184 185 186 187 188
void parse_options(char **argv, struct config_param options[], int nopt);

struct eqstr
{
  bool operator()(const char* A, const char* B) const
  {
    return (! strcmp(A, B));
  }
};

189
#ifdef NEW_GCC
190 191 192 193 194 195 196 197 198 199
namespace __gnu_cxx
{
#endif
    template<> struct hash< std::string >
    {
        size_t operator()( const std::string& x ) const
        {
            return hash< const char* >()( x.c_str() );
        }
    };
200
#ifdef NEW_GCC
201 202 203 204
};
#endif


205 206
enum edge_data_t {edge_data};
enum vertex_data_t {vertex_data};
207

208 209 210 211
namespace boost {
  BOOST_INSTALL_PROPERTY(edge,data);
  BOOST_INSTALL_PROPERTY(vertex,data);
}
212

213 214 215
/*
 * Used to count the number of nodes in each ptype and vtype
 */
216 217
typedef hash_map<fstring,int> name_count_map;
typedef hash_map<fstring,vector<fstring> > name_list_map;
218

219 220 221
/*
 * A hash function for pointers
 */
222 223 224 225 226 227
template <class T> struct hashptr {
  size_t operator()(T const &A) const {
    return (size_t) A;
  }
};

228 229 230 231 232 233 234 235 236
/*
 * Misc. debugging stuff
 */
#ifdef ROB_DEBUG
#define RDEBUG(a) a
#else
#define RDEBUG(a)
#endif

237 238 239 240
/*
 * Needed for the transition from gcc 2.95 to 3.x - the new gcc puts some
 * non-standard (ie. SGI) STL extensions in different place
 */
241
#ifdef NEW_GCC
242 243 244 245 246
#define HASH_MAP <ext/hash_map>
#else
#define HASH_MAP
#endif

247 248 249
// For use in functions that want to return a score/violations pair
typedef pair<double,int> score_and_violations;

250
#endif