-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
11,228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@author: augustinparjadis | ||
""" | ||
|
||
import sys | ||
import ctypes | ||
from numpy.ctypeslib import ndpointer | ||
|
||
def thetas_C(file,N,UB): | ||
LP_c_char = ctypes.POINTER(ctypes.c_char) | ||
LP_LP_c_char = ctypes.POINTER(LP_c_char) | ||
|
||
N_NODES = N | ||
|
||
hkl = ctypes.CDLL("./hkfactors.so", mode = ctypes.RTLD_GLOBAL) | ||
hk = hkl.hkfactors | ||
hk.argtypes = [ctypes.c_int,LP_LP_c_char] | ||
hk.restype = ndpointer(dtype=ctypes.c_float, shape=(N_NODES+1,)) | ||
argv = ["hkfactors","-filein",file,"-UB",str(UB)] | ||
argc = len(argv) | ||
|
||
p = (LP_c_char*len(argv))() | ||
for i, arg in enumerate(argv): | ||
enc_arg = arg.encode('utf-8') | ||
p[i] = ctypes.create_string_buffer(enc_arg) | ||
|
||
na = ctypes.cast(p, LP_LP_c_char) | ||
|
||
hk_res = hk(argc, na) | ||
|
||
print(f'\nHKbound = {hk_res[0]}') | ||
print(hk_res) | ||
|
||
return hk_res[0],hk_res[1:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef ATSP_H | ||
#define ATSP_H | ||
#include <graphe.h> | ||
#include <stsp.h> | ||
|
||
/*! | ||
* \class ATSP | ||
* \brief An Asymmetric Travelling Salesman Problem object. | ||
* \author Pascal Benchimol | ||
*/ | ||
|
||
class ATSP : public Graphe { | ||
|
||
public : | ||
/*! | ||
* \brief Constructeur | ||
* \param n : number of nodes. | ||
*/ | ||
ATSP(int n); | ||
|
||
/*! | ||
* \brief Build a symmetric TSP instance from this asymmetric instance using duplication of nodes. | ||
* \return A SymTSP object. | ||
*/ | ||
|
||
SymTSP * getTSP(); | ||
|
||
void printDot(string nomFichier) const; | ||
|
||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#ifndef BB_H | ||
#define BB_H | ||
|
||
#include <hk.h> | ||
#include <stsp.h> | ||
#include <hungarianMethod.h> | ||
|
||
#include <time.h> | ||
|
||
class BB { | ||
|
||
private : | ||
HeldKarp hk; | ||
SymTSP * graphe; | ||
|
||
hungarianMethod hg; | ||
|
||
clock_t startTime; | ||
|
||
float percent_edges_filtered; | ||
|
||
double upperBound; | ||
int nbNode; | ||
bool bb_tourFound; | ||
double tourCost; | ||
|
||
|
||
std::vector<Edge*>* toForce_temp; | ||
std::vector<Edge*>* toRemove_temp; | ||
|
||
pair<bool,Edge*> getEdgeWithMaxReplacementCost(); | ||
void getEdgesToBranchOn(std::vector<Edge*>* edgesToBranchOn); | ||
|
||
int nbForce; | ||
|
||
int nbForceCut; | ||
int nbForceCost; | ||
|
||
public : | ||
BB(SymTSP * graphe, double UB, int nF); | ||
|
||
~BB(); | ||
|
||
void test(); | ||
|
||
void compute(int size_bf, float bound_factors[]); | ||
|
||
|
||
void dfs_Remove(int profondeur); | ||
|
||
void filter_and_force(std::vector<Edge*>* toRemove, std::vector<Edge*>* toForce, bool *canStopBranching, float *HKbound_fnf, float *factors); | ||
|
||
|
||
void compute_ap(); | ||
|
||
|
||
void dfs_Remove_ap(int profondeur); | ||
|
||
void filter_and_force_ap(std::vector<Edge*>* toRemove, std::vector<Edge*>* toForce, bool *canStopBranching); | ||
void printEndInfos(bool isOptimal); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#ifndef BIGRAPHE_H | ||
#define BIGRAPHE_H | ||
|
||
|
||
#include<stsp.h> | ||
|
||
#include <list> | ||
|
||
#include <vector> | ||
#include <binode.h> | ||
#include <node.h> | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <fstream> | ||
//#include <stsp.h> | ||
/*! | ||
* \file Graphe.h | ||
* \brief Header for Graphe. | ||
* \author Pascal Benchimol | ||
*/ | ||
|
||
typedef std::vector<BiNode*> bigraphNodes; | ||
|
||
|
||
using namespace std; | ||
|
||
/*! | ||
* \class Graphe | ||
*/ | ||
class BiGraphe { | ||
private: | ||
int size; | ||
int matchingSize; | ||
bigraphNodes rightNodes; /*!< Vector of nodes*/ | ||
bigraphNodes leftNodes; /*!< Vector of nodes*/ | ||
bigraphEdges edges; /*!< List of edges*/ | ||
|
||
|
||
BiEdge* addEdge(int leftIndex, int rightIndex, double weight, Edge* _edge); | ||
|
||
|
||
|
||
public: | ||
|
||
/*! | ||
* \brief Constructeur | ||
* \param size : number of nodes. | ||
*/ | ||
BiGraphe(SymTSP * stsp); | ||
|
||
~BiGraphe(); | ||
|
||
|
||
/*! | ||
* \brief Return the maximum index of a node that can be found in this graphe. | ||
*/ | ||
int getSize() const; | ||
int getMatchingSize() const; | ||
|
||
|
||
bigraphNodes* getRightNodes(); | ||
bigraphNodes* getLeftNodes(); | ||
bigraphEdges* getEdges(); | ||
|
||
|
||
|
||
|
||
void print() const; | ||
|
||
|
||
void addEdge(BiEdge * edge); | ||
|
||
void removeEdge(BiEdge * e); | ||
|
||
/*! | ||
* \brief Print the graph in graphviz dot format into file nomFichier. | ||
* A view of the graph can the be created using graphviz (www.graphviz.org). | ||
* type "dot -Tformat -o outfile grapheInDotFormatFile | ||
*/ | ||
void printDot(string nomFichier) const; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}; | ||
#endif |
Oops, something went wrong.