public void initial() throws IOException {

		double[] positions = null;
		// initial pbest and particles
		for (int i = 0; i < swarm_size; i++) {
			positions = new double[dimension];
			for (int j = 0; j < dimension; j++) {
				positions[j] = (Math.random() * (range_max - range_min) + range_min)
						* (Math.random() > 0.5 ? 1 : -1);
			}
			population[i] = new Particle(positions);
			pbest[i] = new Particle(positions);
		}
		
		allweights_1+="generation:" + c_generation + "\n";
		allweights_1+=pbest[0].generateText();
		pbest[0].writeFile("pbest", allweights_1);
		

		// initial gbest
		gbest = new Particle(population[0].getPosition());
		for (int i = 0; i < swarm_size; i++) {
			if (fitness(population[i]) > fitness(gbest)) {
				gbest = new Particle(population[i].getPosition());
			}
		}
		allweights+="generation:" + c_generation + "\n";
		allweights+=gbest.generateText();
		gbest.writeFile("gbest", allweights);
		

		// initial velocity of all particles
		double[] temp = new double[dimension];
		for (int i = 0; i < swarm_size; i++) {
			for (int j = 0; j < dimension; j++) {
				temp[j] = Math.random() * vmax * (Math.random() > 0.5 ? 1 : -1);
			}
			velocity[i] = temp;
			temp = new double[dimension];
		}
	}