solution.h 4.49 KB
Newer Older
1 2
/*
 * EMULAB-COPYRIGHT
3
 * Copyright (c) 2003-2006 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * All rights reserved.
 */

/*
 * Functions used for printing out a solution, or intermediary steps on the way
 * to a solution
 */

#ifndef __SOLUTION_H
#define __SOLUTION_H

#include "port.h"

#include "delay.h"
#include "physical.h"
#include "virtual.h"
#include "maps.h"

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * Stucture to hold a potential solution
 */
class solution {
    public:
    explicit solution() : vnode_assignments(), vtype_assignments(),
	vlink_assignments() { ; };
    ~solution() {;};
    
    // Copy constructor and operator
    solution(const solution &other) : vnode_assignments(other.vnode_assignments),
	vtype_assignments(other.vtype_assignments) { ; };
    
    solution &operator=(const solution &other) {
	// TODO: make sure copying the assignments doesn't alias!
	this->vnode_assignments = other.vnode_assignments;
	this->vtype_assignments = other.vtype_assignments;
39
	return(*this);
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    };
    
    inline bool is_assigned(const vvertex &vv) const {
	//return vnode_is_assigned[vv];
	node_map::const_iterator it = vnode_assignments.find(vv);
	if (it == vnode_assignments.end()) {
	    return false;
	} else {
	    return true;
	}
    };
    inline bool link_is_assigned(const vedge &ve) const {
	link_map::const_iterator it = vlink_assignments.find(ve);
	if (it == vlink_assignments.end()) {
	    return false;
	} else {
	    return true;
	}
    };
    
    inline pvertex get_assignment(const vvertex &vv) const {
	node_map::const_iterator it = vnode_assignments.find(vv);
	return it->second;
    };
    inline fstring get_vtype_assignment(const vvertex &vv) const {
	type_map::const_iterator it = vtype_assignments.find(vv);
	return it->second;
	//return vtype_assignments[vv];
    };
    inline tb_link_info get_link_assignment(const vedge &ve) const {
	link_map::const_iterator it = vlink_assignments.find(ve);
	return it->second;
    };
    
    inline void set_assignment(const vvertex &vv, const pvertex &pv) {
	vnode_assignments[vv] = pv;
    }
    
    inline void clear_assignment(const vvertex &vv) {
	vnode_assignments.erase(vv);
    }
    
    inline void set_link_assignment(const vedge &ve, const tb_link_info &info) {
	vlink_assignments[ve] = info;
    }
    
    inline void clear_link_assignment(const vedge &ve) {
	vlink_assignments.erase(ve);
    }
    
    inline void set_vtype_assignment(const vvertex &vv, const fstring t) {
	vtype_assignments[vv] = t;
    }
    
    private:
    /*
     * These variables store the actual solution
     */
    // The vvertex -> pnode : assignment
    node_map vnode_assignments;
    // vvertex -> bool : is the vnode assigned?
    //assigned_map vnode_is_assigned;
    // vtype -> ptype : what type has the ptype taken on?
    type_map vtype_assignments;
    // vedge -> link_info
    link_map vlink_assignments;
};

108 109 110 111 112
/* 
 * External globals
 */

/* From assign.cc */
113
extern tb_pgraph PG;
114 115

/* Print a solution */
116
void print_solution(const solution &s);
117

118 119 120 121
/* Print a summary of the solution and annotate the rspec with the assignment
   This is only called when an rspec file is given as input */
void print_solution(const solution &s, const char* output_rspec_filename);

122
/* Print a summary of the solution */
123
void print_solution_summary(const solution &s);
124

125 126 127 128 129 130 131 132
/* Check to see if two scores are, for all intents and purposes, the same */
bool compare_scores(double score1, double score2);

/* The amount by twhich two scores can differ and still look the same - should
 * be << than the smallest possible weight
 */
const double ITTY_BITTY = 0.00001;

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
/*
 * These structs are used for traversing edges, etc. to produce graphviz
 * outputs. They are used as functors.
 */
struct pvertex_writer {
  void operator()(ostream &out,const pvertex &p) const;
};
struct vvertex_writer {
  void operator()(ostream &out,const vvertex &v) const;
};
struct pedge_writer {
  void operator()(ostream &out,const pedge &p) const;
};
struct sedge_writer {
  void operator()(ostream &out,const sedge &s) const;
};
struct svertex_writer {
  void operator()(ostream &out,const svertex &s) const;
};
struct vedge_writer {
  void operator()(ostream &out,const vedge &v) const;
};
struct graph_writer {
  void operator()(ostream &out) const;
};
struct solution_edge_writer {
  void operator()(ostream &out,const vedge &v) const;
};
struct solution_vertex_writer {
162
    solution_vertex_writer(const solution &s) : my_solution(s) { ; };
163
  void operator()(ostream &out,const vvertex &v) const;
164 165 166
  private:
  solution_vertex_writer(); // Hide it
  const solution my_solution;
167 168
};
#endif