예제 #1
0
int main(int argc, char **argv) {
    int num_comms = 2;
    int triple_type = D3CS_NOBACK;
    int cut_type = BIPARTITE;
    std::string name = "tripartite_flow";

    std::cout << "DIRLAP ---------" << std::endl;
    {
	Network net = Network("data", name, triple_type);
	CommDetection comm(net, num_comms, DIRLAP, cut_type, name);
	comm.Run();
    }
    std::cout << "D3C_ONLY ---------" << std::endl;
    {
	Network net = Network("data", name, triple_type);
	CommDetection comm(net, num_comms, D3C_ONLY_DIRLAP, cut_type, name);
	comm.Run();
    }
    std::cout << "TENSOR ---------" << std::endl;
    {
	Network net = Network("data", name, triple_type);
	CommDetection comm(net, num_comms, TENSOR, cut_type, name);
	comm.Run();
    }
    std::cout << "END ---------" << std::endl;
}
예제 #2
0
파일: Network.cpp 프로젝트: T045T/neural
  Network Network::read(istream &s) {
    Network fail = Network(0,0);
    if(!s.good()) {
      return fail;
    }
    string keyword;
    s >> keyword;
    if(keyword != "NETWORK") {
      {
	return fail;
      }
    }

    s >> keyword;
    if(keyword != "input_size") {
      {
	return fail;
      }
    }
    int input_size;
    s >> input_size;
    
    s >> keyword;
    if(keyword != "layers") {
      return fail;
    }
    int layers;
    s >> layers;

    char c = s.get();
    if(c != '\n') {
      return fail;
    }

    shared_ptr<Layer> first(Layer::read(s, input_size));
    if (first->size() == 0) {
      return fail;
    }
    layers--;
    if (layers == 0) {
      return Network(input_size, shared_ptr<Layer>(NULL), first);
    }
    shared_ptr<Layer> current = shared_ptr<Layer>(Layer::read(s, first));
    if (current->size() == 0) {
      return fail;
    }
    first->setNextLayer(current);
    layers--;
    while(layers > 0) {
      current->setNextLayer(shared_ptr<Layer>(Layer::read(s, current)));
      current = current->nextLayer();
      if (current->size() == 0) {
	return fail;
      }
      layers--;
    }
    return Network(input_size, first, current);
  }
예제 #3
0
void main (){

int gdriver=0,gmode,opc,opc1,opc2,opc3,opc4,opc5,opc6,opc7,opc8,opc9;
float Periodos,Tasa;

initgraph(&gdriver,&gmode," ");
mouse.Inicializar(); //Inicializa Mouse

boton(90,70,500,300,8,15,7,5);
barra_titulo(92,72,499,"Ingreso De Datos - Mac Software");
DibujeIcono(97,73,Network(),16,16);
boton(483,75,495,87,8,15,7,1);DibujeIcono(485,77,Cerrar(),9,9);
marco_grabado(100,98,490,290);
Periodos=CuadroDato(115,"Digite Numero de Periodos","");
Tasa=CuadroDato(185,"Digite Tasa de Interes","");
conv_text(125,253,"NOTA: ");
conv_text(125,268,"EL PERIODO CERO (0) ES EL MOMENTO INICIAL");
getch();
cleardevice();
printf("Periodo= %f  Tasa=%f",Periodos,Tasa);


getch();
closegraph();exit(0);restorecrtmode();system("cls");


} //FIN
예제 #4
0
int main(int argc,char *argv[]){
   Network nw=Network();
   nw.addCompartment(0,"unknown");
   nw.addCompartment(1,"ex");
   nw.addCompartment(2,"pm");
   nw.addCompartment(3,"cy");
   nw.addNode(0, reaction , "R", 100 , 100 , 00, 00 ,0,2);     
   nw.addNode(1, compound , "c1", 100 , 100 , 300, 00 , 00,1);     
   nw.addNode(2, compound , "c2", 100 , 100 , 300, 300 , 00,1);     
   nw.addNode(3, compound , "c3", 100 , 100 , 00, 300 , 00,2);     
   nw.addNode(4, compound , "c4", 100 , 100 , 200, 300 , 00,2);     
   nw.addNode(5, compound , "c5", 100 , 100 , 400, 300 , 00,3);     
   nw.addEdge(0,1,substrate);
   nw.addEdge(0,2,substrate);
   nw.addEdge(0,3,product);
   nw.addEdge(0,4,inhibitor);
   nw.addEdge(0,5,catalyst);
   nw.dump();
   Plugins& pgs=register_plugins();
   Layouter l(nw,pgs);
   l.stepAddPlugins(0,P_force_adj,  P_torque_adj, P_distribute_edges, P_adjust_compartments, P_force_compartments);
   l.stepAddEndCondition(0,C_relForceDiff,0.0005);
   l.stepAddEndCondition(0,C_temp,10);
   l.stepAddPlugins(1,P_fix_compartments);
   l.stepAddEndCondition(1,C_iterations,1);
   l.stepAddPlugins(2,P_force_adj,  P_torque_adj,P_force_nadj, P_distribute_edges, P_adjust_compartments_fixed, P_force_compartments);
   l.stepAddEndCondition(2,C_relForceDiff,0.0005);
   l.stepAddEndCondition(2,C_temp,10);
   l.execute();
   printf("finished. [press key]\n");
   getc(stdin);
   return 0;
}
int main(int argc,char *argv[]) {
    if(argc != 5) {
            printf("Wrong Number of Arguments\n");
            exit(0);
    }

    //double alpha1 = argv[1]-0.0;
    double alpha1, alpha2, beta1, beta2, gamma1, gamma2, phi1, phi2;
    alpha1 = alpha2 = atof( argv[1] );
    beta1 = 0.35;
    beta2 = atof( argv[2] );
    gamma1 = gamma2 = 1.0/5.0;
    phi1 = phi2 = atof( argv[4]);
    int intro_time;
    intro_time = atoi( argv[3] );

    int num_reps = 5;

    Network net = Network("gillespie toy", Network::Undirected);
    net.populate(10000);
    net.connect_all_nodes();
    Gillespie_TwoStrain_Network_Sim sim(&net, alpha1, alpha2, gamma1, gamma2, beta1, beta2, phi1, phi2, intro_time);
    for(int i =1; i <= num_reps; i++){
        cout << "Simulation number: " << i << endl;
        sim.reset();
        sim.rand_infect(5, 1);
        sim.run_simulation(10000.0);
    }
    return 0;
}
예제 #6
0
void main()
{
	for (int i = 0; i < 4; i++)
	{
		PlayerAddresses[i].port = 0;
	}

	NetDevice = RakNet::RakPeerInterface::GetInstance();

	NetDevice->Startup(MaxClients, &RakNet::SocketDescriptor(ServerPort, 0), 1);

	Print("Starting the server...");
	Skip();
	NetDevice->SetMaximumIncomingConnections(MaxClients);

	while(1)
	{
			TimeDelta = timeGetTime() - Start;

			Start = timeGetTime();

			for (int i = 0; i < 1000; i++)
			{
				std::cout << "";
			}

			Timers();

			Network();

			Game();
	}

	RakNet::RakPeerInterface::DestroyInstance(NetDevice);
}
예제 #7
0
int main(void) {
  int i;
  int64_t llTime;
  llTime = GetTime();
  for (i = 2; i <= 64; i += 2) {
    printf("R(%d)=%.15f(%dms)\n", i, Network(i), (int) (GetTime() - llTime));
  }
  return 0;
}
예제 #8
0
// runs a seasonally forced gillespie simulation on a exponential network
int main(int argc,char *argv[]) {
    if(argc != 9) {
            printf("Wrong Number of Arguments\n");
            exit(0);
    }

    double alpha1, alpha2, beta1_max, beta2_max, gamma1, gamma2, phi1, phi2, eta1, eta2;
    alpha1 = alpha2 = atof( argv[1] );
    beta1_max = atof( argv[2] );  
    beta2_max = atof( argv[3] );
    eta1 = eta2 = 1.0/2.62;
    gamma1 = gamma2 = 1.0/3.38;
    phi1 = phi2 = atof( argv[4]);
    int intro_time, start_ind, shift;
    intro_time = atoi( argv[5] );
    start_ind = atoi( argv[6] );
    shift = atoi( argv[7] );
    string network_type = argv[8];
    
    int num_reps = 4000;

    Network net = Network("gillespie toy", Network::Undirected);
    net.populate(10000);
    for(int i =1; i <= num_reps; i++){
        net.clear_edges();
        if(network_type == "exp"){
            net.rand_connect_exponential(0.06453487);
        } else if(network_type == "unif"){
            vector<int> degrees(10000, 16);
            net.rand_connect_explicit(degrees);
        } else{
            cerr << "Unrecognized network type" << endl;
        }
        // cout << net.mean_deg() << endl;
        Gillespie_SEIR_TwoStrain_Network sim(&net, alpha1, alpha2, eta1, eta2, gamma1, gamma2, beta1_max, beta2_max, phi1, phi2, intro_time, start_ind, shift);
        cout << "Simulation number: " << i << endl;
        sim.reset();
        sim.rand_infect(5, 1);
        sim.run_simulation(10000.0);
    }
    return 0;
}
예제 #9
0
파일: vax_sim.cpp 프로젝트: sjfox/EpiFire
int main(int argc,char *argv[]) {
    if(argc != 10) {
            printf("Wrong Number of Arguments\n");
            exit(0);
    }

    //double alpha1 = argv[1]-0.0;
    double beta_vax, beta_dis, gamma_vax, gamma_dis;
    int init_inf, init_vax;

    beta_vax = atof( argv[1] ); // vaccine transmissibility
    beta_dis = atof( argv[2] ); // disease transmissibility
    gamma_vax = atof( argv[3] ); // vaccine recovery rate
    gamma_dis = atof( argv[4] ); // disease recovery rate
    init_vax = atoi( argv[5] ); // number initially vaccinated
    init_inf = atoi( argv[6] ); // number initially infected

    string network_type = argv[7] ;
    string vax_type = argv[8];
    int num_reps = atoi( argv[9]);

    Network net = Network("gillespie toy", Network::Undirected);
    net.populate(10000);
    for(int i =1; i <= num_reps; i++){
        net.clear_edges();
        if(network_type == "er"){
            net.erdos_renyi(10);
        } else if(network_type == "exp"){
            net.rand_connect_exponential(0.1);
        } else if(network_type == "unif"){
            vector<int> degrees(10000, 10);
            net.rand_connect_explicit(degrees);
        } else{
            cerr << "Unrecognized network type" << endl;
        }
        Gillespie_trans_vaccine sim(&net, gamma_vax, gamma_dis, beta_vax, beta_dis, vax_type);
        cout << "Simulation number: " << i << endl;
        sim.reset();
        sim.run_simulation(10000.0, init_vax, init_inf);
    }
    return 0;
}
예제 #10
0
int main(int argc,char *argv[]){
   Network nw=Network();
   nw.addCompartment(0,"unknown");
   nw.addNode(0, reaction , "R1", 100 , 100 , 00, 00 , 00,00);     
   nw.addNode(1, compound , "c1", 100 , 100 , 300, 00 , 00,00);     
   nw.addNode(2, compound , "c2", 100 , 100 , 300, 300 , 00,00);     
   nw.addNode(3, compound , "c3", 100 , 100 , 00, 300 , 00,00);     
   nw.addNode(4, compound , "c4", 100 , 100 , 200, 300 , 00,00);     
   nw.addNode(5, compound , "c5", 100 , 100 , 400, 300 , 00,00);     
   nw.addNode(6, reaction , "R2", 100 , 100 , 300, -300 , 00,00);     
   nw.addNode(7, compound , "c6", 100 , 100 , 500, -300 , 00,00);     
   nw.addNode(8, compound , "c7", 100 , 100 , 500, 00 , 00,00);     
   nw.addNode(9, compound , "c8", 100 , 100 , 500, 200 , 00,00);     
   nw.addNode(10, compound , "c9", 100 , 100 , 300, 200 , 00,00);     
   
   nw.addEdge(0,1,substrate);
   nw.addEdge(0,2,substrate);
   nw.addEdge(0,3,product);
   nw.addEdge(0,4,inhibitor);
   nw.addEdge(0,5,catalyst);
   nw.addEdge(6,1,product);
   nw.addEdge(6,7,substrate);
   
   nw.addEdge(8,9,directed);
   nw.addEdge(9,10,directed);
   
   nw.dump();
   Plugins& pgs=register_plugins();
   Layouter l(nw,pgs);
   l.stepAddPlugins(0,P_force_adj,  P_torque_adj, P_distribute_edges, P_force_nadj, P_limit_mov);
   l.stepAddEndCondition(0,C_relForceDiff,0.0005);
   l.execute();
   printf("finished. [press key]\n");
   getc(stdin);
   return 0;
}
void BPNN_Recommendation::recommendArticleByBP()
{
	cout << "Compute NN model. " << endl;
	//first compute the model
	int neurons[3] = {20, 20, NodeNum};

	BPLearning NN(
		Network(NodeNum,3,new SigmodFunction(2),neurons),
		1,0.0
		);

	ifstream in("NetModel//netWorkOutput.txt");   //netWork outPut
	if(in.fail())
	{
		cout << "ERROR: fail to open file netWorkOutput.txt..." << endl;
		return;
	}

	for(int i = 0; i < NN.network.output.size(); i++)
		in >> NN.network.output[i];
	in.close();

	in.open("NetModel//laySum.txt"); // lay sum
	if(in.fail())
	{
		cout << "ERROR: fail to open file laySum.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].sum.size(); k++)
		{
			in >>  NN.network.layer[i].sum[k];
		}
	in.close();

	in.open("NetModel//layOutput.txt"); // lay output
	if(in.fail())
	{
		cout << "ERROR: fail to open file layOutput.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].output.size(); k++)
			in >> NN.network.layer[i].output[k];
	in.close();

	in.open("NetModel//layNeuronOutput.txt"); // lay neuron output
	if(in.fail())
	{
		cout << "ERROR: fail to open file layNeuronOutput.txt..." << endl;
		return;
	}

	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].neuron.size(); k++)
			in >> NN.network.layer[i].neuron[k].output;
	in.close();

	in.open("NetModel//layNeuronThreshold.txt"); // lay neuron threshold
	if(in.fail())
	{
		cout << "ERROR: fail to open file layNeuronThreshold.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].neuron.size(); k++)
			in >> NN.network.layer[i].neuron[k].threshold;
	in.close();

	in.open("NetModel//layNeuronWeight.txt"); // lay neuron weight
	if(in.fail())
	{
		cout << "ERROR: fail to open file layNeuronWeight.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].neuron.size(); k++)
			for(int j = 0; j < NN.network.layer[i].neuron[k].weight.size(); j++)
				in >> NN.network.layer[i].neuron[k].weight[j];
	in.close();

	cout << "NN model completed! " << endl;

	//get input
	ReadXYintoFile("xy.txt");
	
	//figure weight
	for(int i = 0; i < m_userList.size(); ++i){
		//input
		for(int k = 0; k < m_userList[i]->alternativeList.size(); k++)
		{
			m_userList[i]->alternativeList[k].weight[FINAL] = m_x * m_userList[i]->alternativeList[k].weight[SOCIAL] / m_userList[i]->maxWeght[SOCIAL] +
				m_y * m_userList[i]->alternativeList[k].weight[PERSONAL] / m_userList[i]->maxWeght[PERSONAL] + 
				(1 - m_x - m_y) * m_userList[i]->alternativeList[k].weight[ITEM] / m_userList[i]->maxWeght[ITEM];

			//max 
			if(m_userList[i]->maxWeght[FINAL] < m_userList[i]->alternativeList[k].weight[FINAL])
				m_userList[i]->maxWeght[FINAL] = m_userList[i]->alternativeList[k].weight[FINAL];
			m_userList[i]->maxWeght[FINAL] = (m_userList[i]->maxWeght[FINAL] == 0? 1.0 : m_userList[i]->maxWeght[FINAL]);
		}
	}

	vector <double> curI;
	double accu = 0.0;
	//make input and figure output
	for(int i = 1; i <= CASENUM; ++i){
		curI.clear();
		
		//input
		for(int k = 0; k < m_userList[i - 1]->alternativeList.size(); k++)
		{
			m_userList[i - 1]->alternativeList[k].weight[FINAL] /= m_userList[i - 1]->maxWeght[FINAL];
			
			curI.push_back(m_userList[i - 1]->alternativeList[k].weight[FINAL]);
		}

		while(curI.size() < NodeNum)
			curI.push_back(0.0);
		
		//figure output
		vector <double> outp = NN.calc(curI);
		/*
		if(i == 1)
		{
			cout << "size: " << outp.size() << endl;
			for(int k = 0; k < outp.size(); k++)
				cout << outp[k] << " ";
			cout << endl;
			//break;
		}
		cout << endl << endl;
		*/

		//compute weight
		for(int m = 0; m < m_userList[i - 1]->alternativeList.size(); m++)
		{
			outp[m] = (1.0 - outp[m] > 0 ? 1.0 - outp[m] : outp[m] - 1.0);
			//if(i == 1)
				//cout << outp[m] << " ";
			//cout << endl << endl;
			m_userList[i - 1]->alternativeList[m].weight[FINAL] = 10.0 - outp[m];
		}
		/*
		if(i == 1)
		{
			for(int k = 0; k < m_userList[i - 1]->alternativeList.size(); k++)
				cout << m_userList[i - 1]->alternativeList[k].weight[FINAL] << " ";
			cout << endl;
			break;
		}
		*/

		//figure accuracy
		vector<WeightArticle> v = getTopN_Y(m_userList[i - 1]->alternativeList, FINAL, TOP_N);
		/*
		if(i == 1)
		{
			cout << "v" << endl;
			for(int k = 0; k < v.size(); k++)
				cout << v[k].id << " " << v[k].weight[FINAL] << endl;
		}
		*/
		int commom = 0;
		for(int k = 0; k < m_answer[i - 1].size(); k++)
		{
			for(int j = 0; j < m_answer[i - 1].size(); j++)
			{
				if(v[k].id == m_answer[i - 1][j])
					commom++;
			}
		}

		accu += (double)commom / m_answer[i - 1].size();
	}

	accu /= m_userList.size();
	cout << "NN model accuracy: " << accu << endl;

}
예제 #12
0
//**************************
void Box(int x,int y,int x1,int y1,char Titulo []){
boton(x,y,x1,y1,8,15,7,5);marco_grabado(x+10,y+28,x1-10,y1-10);
barra_titulo(x+2,y+2,x1-1,Titulo);DibujeIcono(x+7,y+3,Network(),16,16);
boton(x1-17,y+5,x1-5,y+17,8,15,7,1);DibujeIcono(x1-15,y+7,Cerrar(),9,9);
}
예제 #13
0
	NetworkTest()
		:n_(Network())
	{
	}
예제 #14
0
TcpConnection::TcpConnection(char* ip, int port) {

  struct sockaddr_in myaddr, remaddr;
  int fd, slen = sizeof(remaddr);
  char buf[BUFLEN];	/* message buffer */
  int recvlen;		/* # bytes in acknowledgement message */

  srand((int) time(NULL));
  bool flags[] = { false, false, false, false, false, false, false, true, false };
  seqNo = rand() % 10000;
  TcpPacket synPacket(seqNo, rand(), flags, 1u, time(0), PACKET_SIZE, nullptr);

  /* Initialize Network */
  Network network = Network();

  /* create a socket */
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    printf("socket created\n");

  /* bind it to all local addresses and pick any port number */

  memset((char *) &myaddr, 0, sizeof(myaddr));
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  myaddr.sin_port = htons(0);

  if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
    perror("bind failed");
    return;
  }

  /* now define remaddr, the address to whom we want to send messages */
  /* For convenience, the host address is expressed as a numeric IP address */
  /* that we will convert to a binary format via inet_aton */

  memset((char *) &remaddr, 0, sizeof(remaddr));
  remaddr.sin_family = AF_INET;
  remaddr.sin_port = htons(SERVICE_PORT);
  if (inet_pton(remaddr.sin_family, SERVER, &remaddr.sin_addr) == 0) {
    fprintf(stderr, "inet_pton() failed\n");
    exit(1);
  }

  /* Set socket timeout */
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 100000;
  if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv)) < 0) {
    perror("socket timeout set failed");
    exit(1);
  }


  printf("Sending packet to %s port %d\n", SERVER, SERVICE_PORT);
  if (sendto(fd, synPacket.buf, PACKET_SIZE, 0, (struct sockaddr *)&remaddr, slen) == -1) {
    perror("sendto");
    exit(1);
  }
  printf("syn packet sent\n");
  /* now receive an acknowledgement from the server */
  recvlen = recvfrom(fd, buf, BUFLEN, 0, (struct sockaddr *)&remaddr, &slen);
  if (recvlen >= 0) {
    /* check if ACK & SYN flag set in response*/
    bool* Aflags = TcpPacket::getFlags(buf);
    if (*(Aflags + ACKBIT) && *(Aflags + SYNBIT)) {
      printf("Ack received\n");
      char* seqno = TcpPacket::getBytes(buf, 0, SEQUENCE_SIZE);
      int AseqNo = atoi(seqno);
      char* ackno = TcpPacket::getBytes(buf, SEQUENCE_SIZE, ACK_SIZE);
      int ano = atoi(ackno);
      if (ano != seqNo + 1) {
        perror("seq error mismtach");
        exit(1);
      }

      /* construct ack for the packet just received*/
      bool flags[] = { false, false, false, false, true, false, false, false, false };
      seqNo++;
      TcpPacket ackPacket(seqNo, AseqNo + 1, flags, 1u, time(0), PACKET_SIZE, nullptr);
      if (sendto(fd, ackPacket.buf, PACKET_SIZE, 0, (struct sockaddr *)&remaddr, slen) == -1) {
        perror("ackPacket");
        exit(1);
      }
      printf("Three way handshake complete\n");

      /* Free memory */
      free(seqno);
      free(ackno);
    } else {
      perror("Ack not received");
      exit(1);
    }
    free(Aflags);
  }
  closesocket(fd);

}
예제 #15
0
Network::Network(const std::string address, const quint16 port):
    m_hostAddress(m_hostAddress.fromStdString(address)),
    m_hostPort(port)
{
    Network();
}
예제 #16
0
Network::Network() {
	Network(false,false,false);
}
void BPNN_Recommendation::training()
{
	ReadXYintoFile("xy.txt");
	
	//figure weight
	for(int i = 0; i < m_userList.size(); ++i){
		//input
		for(int k = 0; k < m_userList[i]->alternativeList.size(); k++)
		{
			m_userList[i]->alternativeList[k].weight[FINAL] = m_x * m_userList[i]->alternativeList[k].weight[SOCIAL] / m_userList[i]->maxWeght[SOCIAL] +
				m_y * m_userList[i]->alternativeList[k].weight[PERSONAL] / m_userList[i]->maxWeght[PERSONAL] + 
				(1 - m_x - m_y) * m_userList[i]->alternativeList[k].weight[ITEM] / m_userList[i]->maxWeght[ITEM];

			//max 
			if(m_userList[i]->maxWeght[FINAL] < m_userList[i]->alternativeList[k].weight[FINAL])
				m_userList[i]->maxWeght[FINAL] = m_userList[i]->alternativeList[k].weight[FINAL];
			m_userList[i]->maxWeght[FINAL] = (m_userList[i]->maxWeght[FINAL] == 0? 1.0 : m_userList[i]->maxWeght[FINAL]);
		}
	}

	vector <vector<double>> input, output;
	vector <double> curI, curO;
	//make input and output
	for(int i = 1; i <= CASENUM; ++i){
		curI.clear();
		curO.clear();
		
		//input
		for(int k = 0; k < m_userList[i - 1]->alternativeList.size(); k++)
		{
			m_userList[i - 1]->alternativeList[k].weight[FINAL] /= m_userList[i - 1]->maxWeght[FINAL];
			
			curI.push_back(m_userList[i - 1]->alternativeList[k].weight[FINAL]);

			//output
			bool isNum1 = false;
			for(int m = 0; m < m_answer[i - 1].size(); m++)
			{
				if(m_userList[i - 1]->alternativeList[k].id == m_answer[i - 1][m])
				{
					curO.push_back(1.0);
					isNum1 = true;
					break;
				}
			}

			if(!isNum1)
				curO.push_back(0.0);
		}

		while(curI.size() < NodeNum)
			curI.push_back(0.0);
		input.push_back(curI);

		while(curO.size() < NodeNum)
			curO.push_back(0.0);
		output.push_back(curO);
	}

	//printNNInput(input);
	//printNNOutput(output);
	
	//int neurons[3] = {8, 8, NodeNum};
	int neurons[3] = {20, 20, NodeNum};

	BPLearning NN(
		Network(NodeNum,3,new SigmodFunction(2),neurons),
		1,0.0
		);
	//NN.run(input[0],output[0]);
	for(int i = 0;i < TIME; ++i)
	{
		double error =  NN.runAll(input,output);
		printf("case %d's error is %lf\n", i, error);
		if(error < ACCURACY)
			break;
	}

	/********************save***********************/ 
	ofstream ou("NetModel//netWorkOutput.txt");   //netWork outPut
	if(ou.fail())
	{
		cout << "ERROR: fail to open file netWorkOutput.txt..." << endl;
		return;
	}

	for(int i = 0; i < NN.network.output.size(); i++)
		ou << NN.network.output[i] << endl;
	ou.close();

	ou.open("NetModel//laySum.txt"); // lay sum
	if(ou.fail())
	{
		cout << "ERROR: fail to open file laySum.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].sum.size(); k++)
		{
			ou << NN.network.layer[i].sum[k] << endl;
		}
	ou.close();

	ou.open("NetModel//layOutput.txt"); // lay output
	if(ou.fail())
	{
		cout << "ERROR: fail to open file layOutput.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].output.size(); k++)
			ou << NN.network.layer[i].output[k] << endl;
	ou.close();

	ou.open("NetModel//layNeuronOutput.txt"); // lay neuron output
	if(ou.fail())
	{
		cout << "ERROR: fail to open file layNeuronOutput.txt..." << endl;
		return;
	}

	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].neuron.size(); k++)
			ou << NN.network.layer[i].neuron[k].output << endl;
	ou.close();

	ou.open("NetModel//layNeuronThreshold.txt"); // lay neuron threshold
	if(ou.fail())
	{
		cout << "ERROR: fail to open file layNeuronThreshold.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].neuron.size(); k++)
			ou << NN.network.layer[i].neuron[k].threshold << endl;
	ou.close();

	ou.open("NetModel//layNeuronWeight.txt"); // lay neuron weight
	if(ou.fail())
	{
		cout << "ERROR: fail to open file layNeuronWeight.txt..." << endl;
		return;
	}
	for(int i = 0; i < NN.network.layer.size(); i++)
		for(int k = 0; k < NN.network.layer[i].neuron.size(); k++)
			for(int j = 0; j < NN.network.layer[i].neuron[k].weight.size(); j++)
				ou << NN.network.layer[i].neuron[k].weight[j] << endl;
	ou.close();

	cout << "NN model completed! " << endl;
	/*
	//test
	vector <double> data;
	for(int i = 0; i < input[0].size(); i++)
		data.push_back(input[0][i]);

	vector <double> res = NN.calc(data);
	for(int i=0;i<(int)res.size();++i)
		cout<< res[i] << " ";
	cout << endl;
	*/
}