Example #1
0
     /*
      * function members
      */
     TSP(Dmatrix  _costs)
         : dist(_costs),
         n(_costs.size()) {
             iorder.resize(n);
             jorder.resize(n);
             maxd = dist.max();

             /*
              * identity_permutations
              */
             std::iota(std::begin(iorder), std::end(iorder), 0);
#if 0
             for (auto &e : iorder) {
                  e = i;
             }
#endif
             /*
              * best order
              */
             border = iorder;
             bestCost = dist.pathCost(border);
         }
Example #2
0
	SearchContext(const Point* points_begin, const Point* points_end)
	{
		auto start_time = std::chrono::system_clock::now();

		auto objects = points_end - points_begin;
		if (objects > std::numeric_limits<int32_t>::max())
			return;

		auto points_count = (int32_t)objects;
		coordinates.xs.resize(points_count);
		coordinates.ys.resize(points_count);
		ids.resize(points_count);
		ordered_points.resize(points_count);

		auto ranks = Ranks(points_count, END_OF_DATA);
		auto points = std::vector<Point>(points_count);
		for (auto it = points_begin; it != points_end; ++it)
		{
			auto idx = it->rank;
			if (idx < 0 || idx >= points_count || ranks[idx] != END_OF_DATA)
				return;
			coordinates.xs[idx] = it->x;
			coordinates.ys[idx] = it->y;
			ids[idx] = it->id;
			ranks[idx] = idx;
			points[idx] = *it;
			ordered_points[idx] = *it;
		}
		Mappings mappings(points_count, coordinates, ids);

		concurrency::parallel_sort(points.begin(), points.end(), [](const Point& a, const Point& b) { return a.x < b.x; });
		for (auto i = 0; i < points_count; ++i)
		{
			mappings.x_sorted_rank_idxes[i] = points[i].rank;
			mappings.rank_idx_to_x_sorted_idxes[points[i].rank] = i;
		}

		concurrency::parallel_sort(points.begin(), points.end(), [](const Point& a, const Point& b) { return a.y < b.y; });
		for (auto i = 0; i < points_count; ++i)
		{
			mappings.y_sorted_rank_idxes[i] = points[i].rank;
			mappings.rank_idx_to_y_sorted_idxes[points[i].rank] = i;
		}

		top = surface_factory(mappings, ranks, 0, false, false);
	}