Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aparjadis authored Nov 6, 2023
1 parent e8dbd44 commit 5de8c45
Show file tree
Hide file tree
Showing 41 changed files with 11,228 additions and 0 deletions.
36 changes: 36 additions & 0 deletions training/HKbound.py
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:]
31 changes: 31 additions & 0 deletions training/include/atsp.h
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
64 changes: 64 additions & 0 deletions training/include/bb.h
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
91 changes: 91 additions & 0 deletions training/include/bigraphe.h
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
Loading

0 comments on commit 5de8c45

Please sign in to comment.