/*************************************************************** 
	The GPDD Sensitivity Project (GPDD_Sens) 
 
	GPDD stands for "Graph-Pair Decision Diagram" 
 
Contributors: 
 
   CHEN, Weiwei			(MS 2007 graduate) 
   MENG, Xiaoxuan		(MS 2009 graduate) 
   ZENG, Mei			(MS 2010 graduate) 
   LI, Ji				(MS 2010 graduate) 
   MA, Diming			(MS 2011 graduate) 
 
   SHI, Guoyong 		(Prof)  shiguoyong@ic.sjtu.edu.cn 
 
   School of Microelectronics 
   Shanghai Jiao Tong University 
   (c) 2005 - 2010 
******************************************************************/ 


#ifndef	GPDD_STRUCT_H
#define GPDD_STRUCT_H

#include "gpdd_global.h"

//class MOS;	// used in the struct Edge_g

/** 
	A structure for storing a graph node.
*/
struct Node_g
{
	int	 	num;		// node number
	Node_g	*next;		// linked list
};

/** 
	A structure for storing a graph edge.
*/
struct Edge_g
{
	/// Name of the edge
	char	*name;		
	
	/** 
		The edge is derived from this node.
		Node number is stored in the node list.
	*/
	Node_g	*node1;

	/** 
		The edge is ended to this node.
		Node number is stored in the node list.
	*/
	Node_g	*node2;		

	/// the type of this edge (Y/Z/VC/VS/CC/CS).
	int		type;

	/// Name of the pairing edge
	char	*pname;	
	
//	MOS *pMOS;
	
	/// Value of the element
	double	value;		

	/// Variable name for the value (not used now)
	char	*var_name;

	/// Make a linked list
	Edge_g	*next;		
};

/**
 A structure for edge
*/
struct Edge
{
	
	char		*name;		/// The edge name.
	char 	*pname;	/// The pairing edge name.	
	
	int		node1;		// the edge is directed from <node1> to <node2>
	int		node2;		
		
	int		type;		/// The type of this edge.	
	
	int		edgenum;	// edgeindex;	/// Index of this edges
	int		pnum;		/// The edge number of the pairing edge.	
	
	/// value (R/L/C/Gain) read from netlist.
	double	value;		

	int		lumped;		// 1 = lumped, 0 = unlumped.

	int		index;		/// Index of edges after Y/Z lumping, which is also the lumped symbol index
	
//	MOS *pMOS;
};

/**
 A structure for symbol
 */
struct SymbNode
{
	char		*symbname;	
	
	int		symbindex;		// index of a lumped symbol
	int		symbindex0;		// ExpSymbIndex;	//non-lumped original symbol index

	int		isSrc;	// 1 : a source; 0 : not a source. 

	/// the Symbol value.
	double	value;	
	
	/// Imaginary part for a composite symbol.
	double	imag;		

	/// Points to the EList in Enumerator.
	Edge	*edge;	
	
	/// the pointer to the pairedge if the symbol is a dependent source.
	Edge	*pairedge;

	/// The next symbol in array.
	SymbNode*next;		

	// The next symbol in parallel.
	SymbNode*nextP;		

	double 	Count;		// double appearTimes;
	
	/// Fields for sensitivity analysis; added by Xu Hui, 2010-06-02
///	double 	sens_r;	// real part
///	double 	sens_i;	// imaginary part
///	(not needed; G.Shi)
};


/**
	The sturcture is used to record the reduced graphs, whose node numbers
	are changeable as edges are collapsed.
*/
struct EdgeInfo  
{
	 short node1		: 16;
	 short node2		: 16;

	/** 
		the selected mark.
		1-the edge is selected in the reduced graph. 
		0-the edge is removed in the reduced graph.
	*/
	 short mark		:1;

	/// the index of the edge in the edge list.
	 int 	 edgenum;	// edgeindex	:30;

	/** 
		the flag to identify whether the symbol is a source or not.
		1-is a source, 0-is not a source.
	*/
	 short isSrc		:1;
};

/**
	The tag structure used for sorting symbols.
 */
struct stag
{
	/// the index of the symbol.
	int id;

	/// the random index assigned to the symbol.
	int rand;
};

/**
	the structure for comparing the edges.
	used in subtree::completeCompareTree().
*/
struct edgeComp
{
	/// the index of the edge in the edge list.
	int edgeNo;

	/** 
		the direction of the edge.
		1   --  positive. the edge is derived from node1 and ended to node2.
		-1  --  negative. the edge is dervied from node2 and ended to node1.
	*/
	int direct;

	/// the pointer to the next edge to compare.
	edgeComp *pNext;
};

/**
	The sructure for comparing the vertices.
	used in subtree::completeCompareTree().
*/

struct vertexComp
{
	/// the index of the vertex.
	int vertexNo;

	/// the number of the edges connected to this node.
	int edgeSum;

	/// the pointer to the next edge to compare.
	edgeComp *pedge;
};

enum ModelType
{
	NMOS_DEF,
	NMOS_L3,
	PMOS_DEF,
	PMOS_L3,
	MODEL_TYPE_UNKNOWN,
};

enum ModelLevel
{
	MODEL_MOS1,		// MOSFET_MODEL_L1,
	MODEL_MOS2,		// MOSFET_MODEL_L2,
	MODEL_MOS3,		// MOSFET_MODEL_L3,
	MODEL_MOS4,		// MOSFET_MODEL_L4,
	MODEL_BSIM3V3,		// MOSFET_MODEL_BSIM3V3,
	MODEL_UNKNOWN,		// MOSFET_MODEL_UNKOWN,
};



#endif

