2018-06-18 03:06:11 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
2022-12-26 10:30:41 +01:00
|
|
|
// DESCRIPTION: Verilator: Implementation of Christofides algorithm to
|
2018-06-18 03:06:11 +02:00
|
|
|
// approximate the solution to the traveling salesman problem.
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2018-06-18 03:06:11 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2023-01-01 16:18:39 +01:00
|
|
|
// Copyright 2003-2023 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2018-06-18 03:06:11 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2018-06-18 03:06:11 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2021-03-04 03:57:07 +01:00
|
|
|
#ifndef VERILATOR_V3TSP_H_
|
|
|
|
|
#define VERILATOR_V3TSP_H_
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2018-06-18 03:06:11 +02:00
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2018-06-18 03:06:11 +02:00
|
|
|
#include "V3Error.h"
|
2023-09-25 04:12:23 +02:00
|
|
|
#include "V3ThreadSafety.h"
|
2018-06-18 03:06:11 +02:00
|
|
|
|
2022-01-08 18:01:39 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-06-18 03:06:11 +02:00
|
|
|
namespace V3TSP {
|
2020-04-14 04:51:35 +02:00
|
|
|
// Perform a "Traveling Salesman Problem" optimizing sort
|
|
|
|
|
// on any type you like -- so long as inherits from TspStateBase.
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class TspStateBase VL_NOT_FINAL {
|
2020-04-14 04:51:35 +02:00
|
|
|
public:
|
|
|
|
|
// This is the cost function that the TSP sort will minimize.
|
|
|
|
|
// All costs in V3TSP are int, chosen to match the type of
|
|
|
|
|
// V3GraphEdge::weight() which will reflect each edge's cost.
|
|
|
|
|
virtual int cost(const TspStateBase* otherp) const = 0;
|
|
|
|
|
|
|
|
|
|
// This operator< must place a meaningless, arbitrary, but
|
|
|
|
|
// stable order on all TspStateBase's. It's used only to
|
|
|
|
|
// key maps so that iteration is stable, without relying
|
|
|
|
|
// on pointer values that could lead to nondeterminism.
|
|
|
|
|
virtual bool operator<(const TspStateBase& otherp) const = 0;
|
2020-12-02 13:37:34 +01:00
|
|
|
|
|
|
|
|
virtual ~TspStateBase() = default;
|
2020-04-14 04:51:35 +02:00
|
|
|
};
|
|
|
|
|
|
2021-03-13 00:10:45 +01:00
|
|
|
using StateVec = std::vector<const TspStateBase*>;
|
2020-04-14 04:51:35 +02:00
|
|
|
|
|
|
|
|
// Given an unsorted set of TspState's, sort them to minimize
|
|
|
|
|
// the transition cost for walking the sorted list.
|
2023-09-25 04:12:23 +02:00
|
|
|
void tspSort(const StateVec& states, StateVec* resultp) VL_MT_DISABLED;
|
2020-04-14 04:51:35 +02:00
|
|
|
|
2023-09-25 04:12:23 +02:00
|
|
|
void selfTest() VL_MT_DISABLED;
|
2020-04-04 04:31:54 +02:00
|
|
|
} // namespace V3TSP
|
2018-06-18 03:06:11 +02:00
|
|
|
|
2018-08-23 11:09:12 +02:00
|
|
|
#endif // Guard
|