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.
|
|
|
|
//
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2019-01-04 00:17:22 +00:00
|
|
|
// Copyright 2003-2019 by Wilson Snyder. This program is free software; you can
|
2018-06-18 01:06:11 +00:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
|
|
|
//
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2018-06-18 01:06:11 +00:00
|
|
|
#ifndef _V3TSP_H_
|
|
|
|
#define _V3TSP_H_ 1
|
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 {
|
|
|
|
// Perform a "Traveling Salesman Problem" optimizing sort
|
|
|
|
// on any type you like -- so long as inherits from TspStateBase.
|
|
|
|
|
|
|
|
class TspStateBase {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<const TspStateBase*> StateVec;
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-23 09:09:12 +00:00
|
|
|
#endif // Guard
|