score.h 3.56 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
 * All rights reserved.
 */
6 7 8 9

#ifndef _SCORE_H
#define _SCORE_H

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * 'optimal' score - computes a lower bound on the optimal score for this
 * mapping, so that if we find this score, we know we're done and can exit
 * early.
 */
#ifdef USE_OPTIMAL
#define OPTIMAL_SCORE(edges,nodes) (nodes*SCORE_PNODE + \
                                    nodes/opt_nodes_per_sw*SCORE_SWITCH + \
                                    edges*((SCORE_INTRASWITCH_LINK+ \
                                    SCORE_DIRECT_LINK*2)*4+\
                                    SCORE_INTERSWITCH_LINK)/opt_nodes_per_sw)
#else
#define OPTIMAL_SCORE(edges,nodes) 0
#endif

/*
 * Details about which violations are present
 */
class violated_info {

    /* Spit out the current violations (details only, not the total) */
    friend ostream &operator<<(ostream &o, const violated_info &vinfo) {
32 33 34 35 36 37 38 39
	o << "  unassigned:  " << vinfo.unassigned << endl;
	o << "  pnode_load:  " << vinfo.pnode_load << endl;
	o << "  no_connect:  " << vinfo.no_connection << endl;
	o << "  link_users:  " << vinfo.link_users << endl;
	o << "  bandwidth:   " << vinfo.bandwidth << endl;
	o << "  desires:     " << vinfo.desires << endl;
	o << "  vclass:      " << vinfo.vclass << endl;
	o << "  delay:       " << vinfo.delay << endl;
40 41
	o << "  trivial mix: " << vinfo.trivial_mix << endl;
	o << "  subnodes:    " << vinfo.subnodes << endl;
42
	o << "  max_types:   " << vinfo.max_types << endl;
43
#ifdef FIX_PLINK_ENDPOINTS
44
	o << "  endpoints:   " << vinfo.incorrect_endpoints << endl;
45 46 47 48 49 50 51 52
#endif
	return o;
    }
    
    public: /* No real reason to hide this stuff */
	violated_info():
	    unassigned(0), pnode_load(0), no_connection(0), link_users(0),
	    bandwidth(0), desires(0), vclass(0), delay(0),
53 54
	    incorrect_endpoints(0), trivial_mix(0), subnodes(0), max_types(0)
	{ }
55 56 57 58 59 60
	
	int count_violations() const {
	    return unassigned + pnode_load + no_connection + link_users + bandwidth
		+ desires + vclass + delay + incorrect_endpoints + trivial_mix 
		+ subnodes + max_types;
	}
61 62 63 64 65 66 67 68 69 70

	int unassigned;
	int pnode_load;
	int no_connection;
	int link_users;
	int bandwidth;
	int desires;
	int vclass;
	int delay;
	int incorrect_endpoints;
71
	int trivial_mix;
72
	int subnodes;
73
	int max_types;
74
};
75

76
extern double score;
77 78
extern int violated;
extern violated_info vinfo;
79
extern bool allow_trivial_links;
Robert Ricci's avatar
Robert Ricci committed
80
extern bool greedy_link_assignment;
81

82 83 84 85 86
/*
 * Vector used to hold several possible link resolutions
 */
typedef vector<tb_link_info> resolution_vector;

87 88 89
/*
 * Scoring functions
 */
90
void init_score();
91
void remove_node(vvertex vv);
92
int add_node(vvertex vv,pvertex pv,bool deterministic, bool is_fixed, bool skip_links = false);
93 94 95
double get_score();
pvertex make_lan_node(vvertex vv);
void delete_lan_node(pvertex pv);
96

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/*
 * Functions specifically for dealing with links
 */
void score_link_info(vedge ve, tb_pnode *src_pnode, tb_pnode *dst_pnode,
	tb_vnode *src_vnode, tb_vnode *dst_vnode);
void unscore_link_info(vedge ve, tb_pnode *src_pnode, tb_pnode *dst_pnode,
	tb_vnode *src_vnode, tb_vnode *dst_vnode);
float find_link_resolutions(resolution_vector &resolutions, pvertex pv,
    pvertex dest_pv, tb_vlink *vlink, tb_pnode *pnode, tb_pnode *dest_pnode,
    bool flipped);
void resolve_link(vvertex vv, pvertex pv, tb_vnode *vnode, tb_pnode *pnode,
    bool deterministic, hash_set<const tb_vlink*, 
    hashptr<const tb_vlink*> > &seen_loopback_links, vedge edge);
void resolve_links(vvertex vv, pvertex pv, tb_vnode *vnode, tb_pnode *pnode,
    bool deterministic);
void mark_vlink_unassigned(tb_vlink *vlink);
113
#endif