All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

tbsetdest.h 4.31 KB
Newer Older
Timothy Stack's avatar
 
Timothy Stack committed
1

Timothy Stack's avatar
Timothy Stack committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
 * Copyright (c) 1997, 1998, 2005 Carnegie Mellon University.  All Rights
 * Reserved. 
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation is hereby granted (including for
 * commercial or for-profit use), provided that both the copyright notice
 * and this permission notice appear in all copies of the software,
 * derivative works, or modified versions, and any portions thereof, and
 * that both notices appear in supporting documentation, and that credit
 * is given to Carnegie Mellon University in all publications reporting
 * on direct or indirect use of this code or its derivatives.
 * 
 * ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMU
 * MONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OF
 * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
 * SOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR
 * INTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 * 
 * Carnegie Mellon encourages (but does not require) users of this
 * software or intellectual property to return any improvements or
 * extensions that they make, and to grant Carnegie Mellon the rights to
 * redistribute these changes without encumbrance.
 */

/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2005 University of Utah and the Flux Group.
 * All rights reserved.
 */

43 44 45 46 47
#ifndef __tbsetdest_h__
#define __tbsetdest_h__

#include "config.h"
#include <sys/queue.h>
Timothy Stack's avatar
 
Timothy Stack committed
48 49 50 51 52 53 54 55 56 57

#ifndef LIST_FIRST
#define LIST_FIRST(head)	((head)->lh_first)
#endif
#ifndef LIST_NEXT
#define LIST_NEXT(elm, field)	((elm)->field.le_next)
#endif

void ReadInMovementPattern(void);

58
class sdvector {
Timothy Stack's avatar
 
Timothy Stack committed
59
public:
60
	sdvector(double x = 0.0, double y = 0.0, double z = 0.0) {
Timothy Stack's avatar
 
Timothy Stack committed
61 62 63 64 65 66
		X = x; Y = y; Z = z;
	}
	double length() {
		return sqrt(X*X + Y*Y + Z*Z);
	}

67
	inline void sdvector::operator=(const sdvector a) {
Timothy Stack's avatar
 
Timothy Stack committed
68 69 70 71
		X = a.X;
		Y = a.Y;
		Z = a.Z;
	}
72
	inline void sdvector::operator+=(const sdvector a) {
Timothy Stack's avatar
 
Timothy Stack committed
73 74 75 76
		X += a.X;
		Y += a.Y;
		Z += a.Z;
	}
77
	inline int sdvector::operator==(const sdvector a) {
Timothy Stack's avatar
 
Timothy Stack committed
78 79
		return (X == a.X && Y == a.Y && Z == a.Z);
	}
80
	inline int sdvector::operator!=(const sdvector a) {
Timothy Stack's avatar
 
Timothy Stack committed
81 82
		return (X != a.X || Y != a.Y || Z != a.Z);
	}
83 84
	inline sdvector operator-(const sdvector a) {
		return sdvector(X-a.X, Y-a.Y, Z-a.Z);
Timothy Stack's avatar
 
Timothy Stack committed
85
	}
86 87
	friend inline sdvector operator*(const double a, const sdvector b) {
		return sdvector(a*b.X, a*b.Y, a*b.Z);
Timothy Stack's avatar
 
Timothy Stack committed
88
	}
89 90
	friend inline sdvector operator/(const sdvector a, const double b) {
		return sdvector(a.X/b, a.Y/b, a.Z/b);
Timothy Stack's avatar
 
Timothy Stack committed
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 125 126 127 128 129 130 131 132 133 134 135 136
	}

	double X;
	double Y;
	double Z;
};


class Neighbor {
public:
	u_int32_t	index;			// index into NodeList
	u_int32_t	reachable;		// != 0 --> reachable.
	double		time_transition;	// next change

};

struct setdest {
  double time;
  double X, Y, Z;
  double speed;
  LIST_ENTRY(setdest)   traj;
};

class Node {
  friend void ReadInMovementPattern(void);
public:
	Node(void);
	void	Update(void);
	void	UpdateNeighbors(void);
	void	Dump(void);

	double		time_arrival;		// time of arrival at dest
	double		time_transition;	// min of all neighbor times

	// # of optimal route changes for this node
	int		route_changes;
        int             link_changes;

private:
	void	RandomPosition(void);
	void	RandomDestination(void);
	void	RandomSpeed(void);

	u_int32_t	index;                  // unique node identifier
	u_int32_t 	first_trip;		// 1 if first trip, 0 otherwise. (by J. Yoon)

137 138 139
	sdvector	position;		// current position
	sdvector	destination;		// destination
	sdvector	direction;		// computed from pos and dest
Timothy Stack's avatar
 
Timothy Stack committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153

	double		speed;
	double		time_update;		// when pos last updated

	static u_int32_t	NodeIndex;

	LIST_HEAD(traj, setdest) traj;

public:
	// An array of NODES neighbors.
	Neighbor	*neighbor;
};

#endif /* __setdest_h__ */