double TSPsolver::dF(std::vector<double> const &X, unsigned neuron) { double sum_1 = 0 ,sum_2 = 0; unsigned num_neuron_row = neuron / amount_cities; unsigned num_neuron_col = neuron % amount_cities; unsigned next_city = (num_neuron_row == amount_cities-1) ? 0 : num_neuron_row - 1; unsigned prev_city = (num_neuron_row == 0) ? amount_cities-1 : num_neuron_row; for (unsigned row = 0; row < amount_cities; ++row) //time dimension { sum_1 += (row != num_neuron_row) ? get_by_index(X, num_neuron_col, row) : 0; } for (unsigned col = 0; col < amount_cities; ++col) //city dimension { sum_1 += (col != num_neuron_col) ? get_by_index(X, col, num_neuron_row) : 0; sum_2 += (col != num_neuron_col) ? dist[num_neuron_col][col] * (get_by_index(X, col, next_city) + get_by_index(X, col ,prev_city)) : 0; } return -W1 * sum_1 - W2 * sum_2 + W1; }
Entity* EntityVector::get_by_name(const char* name) const { const size_t index = get_index(name); return index == size_t(~0) ? 0 : get_by_index(index); }
Entity* EntityVector::get_by_uid(const UniqueID id) const { const size_t index = get_index(id); return index == size_t(~0) ? 0 : get_by_index(index); }
bool is_in_cset(const HeapRegion* hr) const { return get_by_index(hr->hrm_index()).is_in_cset(); }
void set_in_old(uintptr_t index) { assert(get_by_index(index).is_default(), err_msg("State at index " INTPTR_FORMAT" should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value())); set_by_index(index, InCSetState::Old); }
void set_in_young(uintptr_t index) { assert(get_by_index(index).is_default(), "State at index " INTPTR_FORMAT " should be default but is " CSETSTATE_FORMAT, index, get_by_index(index).value()); set_by_index(index, InCSetState::Young); }