.h头文件的使用方法

时间:2021-10-30 09:58:04

1. 宏定义(预处理#define);

2. 结构、联合和枚举声明;

3. typedef声明;

4. 外部函数声明;

5. 全局变量声明。

可以定义在global.h文件中,但记得写extern,然后再在global.c中写一遍,不加extern,如果有赋初值的变量,在global.h中不赋值,在global.c中赋值。

global.h

#ifndef __GLOBAL_H_
#define __GLOBAL_H_

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <memory.h>
#include <vector>
#include <windows.h>

using namespace std;

#include "random.h"

#define GNEx_nodes 128
#define GNEx_edge 1024
#define GNEx_QR 1.0/(2*GNEx_edge)

#define INF 1.0e+30
#define archive_size 500 /* set capacity of archive */

extern int numVariables;
extern int numObjectives;
extern int popsize;
extern int niche;
extern int mt;
extern int max_gen;
extern int Tr;
extern int nr;

//*
extern char strFunctionType[256];
extern char strReal[256];
extern char strlabel[256];
extern char strGNExtend[256];
//*/

// ideal point used in decomposition methods
extern double *idealpoint;

// parameters for random number generation
extern int seed;
extern long rnd_uni_init;

extern int optimization; /* set optimization type, 0 for min, 1 for max */
extern double alpha;
extern double r;
extern double delta;
extern double deta;
extern const double perterbation;
extern double mutate_posibility ;
/*--实验发现对于人造数据集必须是小于等于0.01才可以,而实际数据集必须0.1才可以---*/
extern const double cross_posibility;
//extern vector<vector<double> >front; // store removed PF

extern vector<vector<int> >chrom; // store the corresponding chrom
extern vector<double> NMI;
extern vector<double> pm_NMI;
extern vector<double> pm_modularity;
extern vector<double> Thirty_Run_NMI;
extern vector<double> Thirty_Run_modularity;
extern vector<double> Thirty_Run_hs;
extern vector<vector<int> > Thirty_Run_QBestchrom;
extern vector<vector<int> > Thirty_Run_hsBestchrom;
extern vector<int> clusters;
extern double NMIavg;
extern double NMImax;
extern double hsavg;
extern double hsmin;
extern double Qmax;
extern double Qavg;
extern int SignedFlag; //1 for signed networks, 0 for unsigned networks

extern vector<double> modularity;
extern vector<double> hs_trial;
//extern unsigned int nondomCtr = 0; /* number of nondominated solutions in archive */

struct network
{
vector<int> neighbours; //positive neighbors
vector<int> neighbours_n; //negative neighbors
int degree; //positive links
int degree_n; //negative links
};

extern int **AdjacentMatrix ;
extern network *node ;



#endif
global.c
#include "global.h"int     numVariables;int     numObjectives;int     popsize;int     niche;int     mt;int     max_gen;int     Tr;int     nr;//*char    strFunctionType[256];char    strReal[256];char    strlabel[256];char    strGNExtend[256];//*/// ideal point used in decomposition methodsdouble  *idealpoint;// parameters for random number generationint     seed = 237;long    rnd_uni_init;int optimization;	   /* set optimization type, 0 for min, 1 for max */double alpha = 1.0;double r = 1.0;double delta = 2.0;//double deta = 0.01;double deta = 0;const double perterbation = 0.00001;double mutate_posibility;double const cross_posibility = 0.1;double const pm = 0.1;double const pc = 1;/*--实验发现对于人造数据集必须是小于等于0.01才可以,而实际数据集必须0.1才可以---*///const double cross_posibility = 0.3;//vector<vector<double> >front; // store removed PFvector<vector<int> >chrom;    // store the corresponding chromvector<double> NMI;vector<double> pm_NMI;vector<double> pm_modularity;vector<double> Thirty_Run_NMI;vector<double> Thirty_Run_modularity;vector<double> Thirty_Run_hs;vector<vector<int> > Thirty_Run_QBestchrom;vector<vector<int> > Thirty_Run_hsBestchrom;vector<int> clusters;double NMIavg;double NMImax;double hsavg;double hsmin;double Qmax;double Qavg;int SignedFlag;		//1 for signed networks, 0 for unsigned networksvector<double> modularity;vector<double> hs_trial;unsigned int nondomCtr = 0;		     /* number of nondominated solutions in archive      *//*struct network {	vector<int> neighbours;		//positive neighbors	vector<int> neighbours_n;	//negative neighbors	int degree;					//positive links	int degree_n;				//negative links};*/int **AdjacentMatrix ;network *node ;