2018-06-18 01:06:11 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Implementation of Christofides' algorithm to
|
|
|
|
// approximate the solution to the traveling salesman problem.
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2018-06-18 01:06:11 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2021-01-01 15:29:54 +00:00
|
|
|
// Copyright 2003-2021 by Wilson Snyder. This program is free software; you
|
2020-03-21 15:24:24 +00:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2018-06-18 01:06:11 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2018-06-18 01:06:11 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2021-03-04 02:57:07 +00:00
|
|
|
#ifndef VERILATOR_V3TSP_H_
|
|
|
|
#define VERILATOR_V3TSP_H_
|
2018-10-14 17:43:24 +00:00
|
|
|
|
2018-06-18 01:06:11 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 17:43:24 +00:00
|
|
|
|
2018-06-18 01:06:11 +00:00
|
|
|
#include "V3Error.h"
|
|
|
|
|
|
|
|
namespace V3TSP {
|
2020-04-14 02:51:35 +00:00
|
|
|
// Perform a "Traveling Salesman Problem" optimizing sort
|
|
|
|
// on any type you like -- so long as inherits from TspStateBase.
|
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class TspStateBase VL_NOT_FINAL {
|
2020-04-14 02:51:35 +00: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 12:37:34 +00:00
|
|
|
|
|
|
|
virtual ~TspStateBase() = default;
|
2020-04-14 02:51:35 +00:00
|
|
|
};
|
|
|
|
|
2021-03-12 23:10:45 +00:00
|
|
|
using StateVec = std::vector<const TspStateBase*>;
|
2020-04-14 02:51:35 +00:00
|
|
|
|
|
|
|
// Given an unsorted set of TspState's, sort them to minimize
|
|
|
|
// the transition cost for walking the sorted list.
|
|
|
|
void tspSort(const StateVec& states, StateVec* resultp);
|
|
|
|
|
|
|
|
void selfTest();
|
2020-04-04 02:31:54 +00:00
|
|
|
} // namespace V3TSP
|
2018-06-18 01:06:11 +00:00
|
|
|
|
2018-08-23 09:09:12 +00:00
|
|
|
#endif // Guard
|