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

7
8
9
#ifndef __VCLASS_H
#define __VCLASS_H

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "port.h"

/*
 * We have to do these includes differently depending on which version of gcc
 * we're compiling with
 */
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
#endif

#include <iostream>
using namespace std;

26
27
28
29
30
31
32
33
34
35
// tb_vclass represents a virtual equivalence class.  The main purpose
// of the code here is to monitor which members of the class are being
// used, what types that are being used as, and calculating the
// appropriate score changes.  Each vclass gives some contribution to
// the score and as nodes are assigned and unassigned this score changes.

// The membership of nodes is not stored here.  Rather each vnode
// stores which vclass it belongs to.  This class is more abstract and
// represents the scoring model.

36
37
class tb_vclass {
public:
38
39
40
  tb_vclass(crope n,double w) : name(n), weight(w), score(0) {;}

  crope name;			// Name of the vclass
41

42
43
44
45
46
  typedef hash_map<crope,int> members_map; 
  members_map members;		// Maps type to number of members of that
				// type.
  
  double weight;		// Weight of class
47
48
  double score;			// the current score of the vclass
  
49
50
51
  void add_type(crope type);	// Add a member of a certain type to the
				// vclass

52
53
  bool has_type(crope type);     // Does the vclass contain the given type?

54
  crope dominant;		// Current dominant type
55
56
57
58

  // The next two routines report the *change* in score.  The score
  // for the vclass as a whole is 0 if all nodes are of the dominant
  // type and the weight if they aren't.
59
60
61
62
63
  double assign_node(crope type);
  double unassign_node(crope type);

  // Semi randomly choose a type from a vclass.
  crope choose_type();
64

65
66
67
68
69
70
71
72
73
74
75
76
  friend ostream &operator<<(ostream &o, const tb_vclass& c)
  {
    o << "vclass: " << c.name << " dominant=" << c.dominant <<
      " weight=" << c.weight << " score=" << c.score << endl;
    o << "  ";
    for (members_map::const_iterator dit=c.members.begin();
	 dit!=c.members.end();++dit) {
      o << (*dit).first << ":" << (*dit).second << " ";
    }
    o << endl;
    return o;
  }
77
};
78
79
80

typedef hash_map<crope,tb_vclass*> name_vclass_map;

81
#endif