vclass.h 2.18 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 52
  void add_type(crope type);	// Add a member of a certain type to the
				// vclass

  crope dominant;		// Current dominant type
53 54 55 56

  // 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.
57 58 59 60 61
  double assign_node(crope type);
  double unassign_node(crope type);

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

63 64 65 66 67 68 69 70 71 72 73 74
  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;
  }
75
};
76 77 78

typedef hash_map<crope,tb_vclass*> name_vclass_map;

79
#endif