static void print_ix_block_entry(FILE *list, struct fcb *f, struct ix_block *b, int i) {int lc,temp; struct key k; level0_pntr p0; struct leveln_pntr pn; get_nth_key(b,&k,i); lc = k.lc; fprintf(list,"%4d %4d ",b->keys[i],lc); print_key(list,b->index_type,&k,""); if ( b->level>0 ) { temp = unpackn_ptr(b,i,&pn); print_leveln_pntr(list," - ",&pn); fprintf(list,"(lc=%d)\n",temp); } else { temp = unpack0_ptr(f,b,i,&p0); print_level0_pntr(list,f," - ",&p0); fprintf(list,"(ptr_lc=%d)\n",temp); } }
NeuralNetwork* Phenotype::get_network(Individual* individual) { NeuralNetwork* network = new NeuralNetwork(); // Locate markers vector< pair<int, int> > raw_markers = get_markers(individual); vector< pair<int, int> > markers; for (int i = 0; i < raw_markers.size(); i++) { if (get_slice_size(individual, raw_markers[i]) >= 7) { markers.push_back(raw_markers[i]); } } // Create input neurons for (int i = 0; i < individual->input_units_; i++) { Neuron neuron; neuron.label_ = i; network->input_neurons_.push_back(neuron); } // Create hidden neurons for (int i = 0; i < markers.size(); i++) { Neuron neuron; neuron.label_ = get_label(individual, markers[i]); neuron.bias_ = get_bias(individual, markers[i]); neuron.output_ = neuron.bias_; network->hidden_neurons_.push_back(neuron); } // Create output neurons for (int i = 0; i < individual->output_units_; i++) { Neuron neuron; neuron.label_ = i; neuron.bias_ = individual->genes_[(individual->genes_.size()-individual->output_units_) + i]; network->output_neurons_.push_back(neuron); } // Create links for (int i = 0; i < markers.size(); i++) { Neuron& neuron = network->hidden_neurons_[i]; int connections = (get_slice_size(individual, markers[i]) - 2) / 3; for (int j = 0; j < connections; j++) { signed char key = get_nth_key(individual, markers[i], j); int label = get_nth_label(individual, markers[i], j); signed char weight = get_nth_weight(individual, markers[i], j); // Link to input/output layer if (key > 0) { // Input if (label > 0) { Neuron& input = network->input_neurons_[label % network->input_neurons_.size()]; input.outputs_.push_back(&neuron); neuron.inputs_.push_back(pair<signed char, Neuron*>(weight, &input)); } // Output else { Neuron& output = network->output_neurons_[abs(label) % network->output_neurons_.size()]; neuron.outputs_.push_back(&output); output.inputs_.push_back(pair<signed char, Neuron*>(weight, &neuron)); } } // Link to hidden layer else { int hidden_label = get_hidden_label(individual, label); Neuron* hidden = get_closest_neuron(hidden_label, network->hidden_neurons_); hidden->outputs_.push_back(&neuron); neuron.inputs_.push_back(pair<signed char, Neuron*>(weight, hidden)); } } } return network; }