solution.h 5.19 KB
Newer Older
1
/*
2
 * Copyright (c) 2003-2006 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 */

/*
 * 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"

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*
 * 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;
56
	return(*this);
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    };
    
    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;
};

125 126 127 128 129
/* 
 * External globals
 */

/* From assign.cc */
130
extern tb_pgraph PG;
131 132

/* Print a solution */
133
void print_solution(const solution &s);
134

135 136 137 138
/* 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);

139
/* Print a summary of the solution */
140
void print_solution_summary(const solution &s);
141

142 143 144 145 146 147 148 149
/* 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;

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/*
 * 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 {
179
    solution_vertex_writer(const solution &s) : my_solution(s) { ; };
180
  void operator()(ostream &out,const vvertex &v) const;
181 182 183
  private:
  solution_vertex_writer(); // Hide it
  const solution my_solution;
184 185
};
#endif