From 9a9f3f822d7510b67c7a595bad96fc40f04ffde1 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 16:57:00 +0100 Subject: [PATCH 1/5] add pre-commit config files --- .clang-format | 2 +- .cmake-format.yaml | 6 ++++++ .pre-commit-config.yaml | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .cmake-format.yaml create mode 100644 .pre-commit-config.yaml diff --git a/.clang-format b/.clang-format index 686e2d9..f01f570 100644 --- a/.clang-format +++ b/.clang-format @@ -7,4 +7,4 @@ DerivePointerAlignment: false PointerAlignment: Left IndentWidth: 4 -ColumnLimit : 110 +ColumnLimit: 110 diff --git a/.cmake-format.yaml b/.cmake-format.yaml new file mode 100644 index 0000000..5b703c9 --- /dev/null +++ b/.cmake-format.yaml @@ -0,0 +1,6 @@ +# https://cmake-format.readthedocs.io/en/latest/configuration.html + +format: + tab_size: 4 + separate_ctrl_name_with_space: true + separate_fn_name_with_space: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..87c5b7f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: check-xml + - id: requirements-txt-fixer + - id: end-of-file-fixer + exclude: external/.*$ + - id: mixed-line-ending + exclude: external/.*$ + - id: trailing-whitespace + exclude: external/.*$ + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v15.0.6 + hooks: + - id: clang-format + exclude: external/.*$ + + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + additional_dependencies: [ pyyaml ] + # - id: cmake-lint + + - repo: https://github.com/psf/black + rev: 22.12.0 + hooks: + - id: black From 5674cceee287b758e9a5c3b4bbd2feb089c024fb Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:09:15 +0100 Subject: [PATCH 2/5] run pre-commit on all files --- .github/workflows/validation.yml | 2 +- CMakeLists.txt | 15 +- inc/TRestTrackPathMinimizationProcess.h | 3 +- pipeline/clang-format/clang-format.sh | 1 - pipeline/clang-format/clangformattest.sh | 1 - pipeline/validateLibrary.py | 59 +- src/TRestTrackDetachIsolatedNodesProcess.cxx | 3 +- tsp/inc/bigguy.h | 2 +- tsp/inc/combs.h | 12 +- tsp/inc/cut.h | 88 +- tsp/inc/cuttree.h | 22 +- tsp/inc/edgegen.h | 49 +- tsp/inc/heldkarp.h | 8 +- tsp/inc/kdtree.h | 66 +- tsp/inc/linkern.h | 24 +- tsp/inc/localcut.h | 56 +- tsp/inc/lp.h | 61 +- tsp/inc/pq.h | 10 +- tsp/inc/tinytsp.h | 18 +- tsp/inc/tsp.h | 613 +++--- tsp/inc/util.h | 229 +-- tsp/inc/verify.h | 6 +- tsp/src/allocrus.c | 97 +- tsp/src/branch.c | 1776 +++++++++--------- tsp/src/edgelen.c | 671 +++---- tsp/src/edgeutil.c | 133 +- tsp/src/heldkarp.c | 501 ++--- 27 files changed, 2218 insertions(+), 2308 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 62266cd..d93f898 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -21,7 +21,7 @@ defaults: jobs: framework-validation: uses: rest-for-physics/framework/.github/workflows/validation.yml@master - + libCheck: name: Validate library runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index 2255574..5caba56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,18 @@ -set( LibraryVersion "1.4" ) +set(LibraryVersion "1.4") add_definitions(-DLIBRARY_VERSION="${LibraryVersion}") -file(GLOB_RECURSE addon_src +file( + GLOB_RECURSE + addon_src "trackMinimization.c" "allocrus.c" "edgelen.c" "edgeutil.c" - "heldkarp.c" ) + "heldkarp.c") set(addon_inc ${CMAKE_CURRENT_SOURCE_DIR}/tsp/inc) -COMPILELIB("") - +compilelib("") file(GLOB_RECURSE MAC "${CMAKE_CURRENT_SOURCE_DIR}/macros/*") -INSTALL(FILES ${MAC} DESTINATION ./macros/track) - - +install(FILES ${MAC} DESTINATION ./macros/track) diff --git a/inc/TRestTrackPathMinimizationProcess.h b/inc/TRestTrackPathMinimizationProcess.h index cc55475..cfdb11d 100644 --- a/inc/TRestTrackPathMinimizationProcess.h +++ b/inc/TRestTrackPathMinimizationProcess.h @@ -13,9 +13,10 @@ #define RestCore_TRestTrackPathMinimizationProcess #include -#include "TRestEventProcess.h" #include +#include "TRestEventProcess.h" + class TRestTrackPathMinimizationProcess : public TRestEventProcess { private: #ifndef __CINT__ diff --git a/pipeline/clang-format/clang-format.sh b/pipeline/clang-format/clang-format.sh index 09ad268..f06fdef 100755 --- a/pipeline/clang-format/clang-format.sh +++ b/pipeline/clang-format/clang-format.sh @@ -106,4 +106,3 @@ if [ "-" = "$1" ] ; then }"' '"${file}"' done fi - diff --git a/pipeline/clang-format/clangformattest.sh b/pipeline/clang-format/clangformattest.sh index 41defb1..6c4fb55 100755 --- a/pipeline/clang-format/clangformattest.sh +++ b/pipeline/clang-format/clangformattest.sh @@ -52,4 +52,3 @@ fi git reset HEAD --hard exit 1 - diff --git a/pipeline/validateLibrary.py b/pipeline/validateLibrary.py index 01b8296..4c8b694 100755 --- a/pipeline/validateLibrary.py +++ b/pipeline/validateLibrary.py @@ -11,10 +11,10 @@ def validateClass(className): print(f"\n++++ Validating class : {className}") - with open(className, 'r') as file: + with open(className, "r") as file: data = file.read() - data = data[data.find("::Initialize"):] + data = data[data.find("::Initialize") :] data = getMethodDefinition(data) data = removeCppComment(data) @@ -30,13 +30,13 @@ def validateClass(className): def getObservablePositions(data): obsposes = {} pos = 0 - str = "SETOBSERVABLEVALUE(\"" + str = 'SETOBSERVABLEVALUE("' while pos < len(data): pos1 = data.find(str, pos) if pos1 == -1: break pos1 += len(str) - pos2 = data.find("\"", pos1) + pos2 = data.find('"', pos1) if pos2 == -1: break @@ -78,60 +78,65 @@ def getMethodDefinition(text): def removeCppComment(strInput): state = 0 - strOutput = '' - strRemoved = '' + strOutput = "" + strRemoved = "" for c in strInput: - if state == 0 and c == '/': # ex. [/] + if state == 0 and c == "/": # ex. [/] state = 1 - elif state == 1 and c == '*': # ex. [/*] + elif state == 1 and c == "*": # ex. [/*] state = 2 - elif state == 1 and c == '/': # ex. [#] + elif state == 1 and c == "/": # ex. [#] state = 4 elif state == 1: # ex. [ or 5/3] state = 0 - elif state == 3 and c == '*': # ex. [/*he**] + elif state == 3 and c == "*": # ex. [/*he**] state = 3 - elif state == 2 and c == '*': # ex. [/*he*] + elif state == 2 and c == "*": # ex. [/*he*] state = 3 elif state == 2: # ex. [/*heh] state = 2 - elif state == 3 and c == '/': # ex. [/*heh*/] + elif state == 3 and c == "/": # ex. [/*heh*/] state = 0 elif state == 3: # ex. [/*heh*e] state = 2 - elif state == 4 and c == '\\': # ex. [//hehe\] + elif state == 4 and c == "\\": # ex. [//hehe\] state = 9 - elif state == 9 and c == '\\': # ex. [//hehe\\\\\] + elif state == 9 and c == "\\": # ex. [//hehe\\\\\] state = 9 elif state == 9: # ex. [//hehe\ or //hehe\a] state = 4 - elif state == 4 and c == '\n': # ex. [//hehe] + elif state == 4 and c == "\n": # ex. [//hehe] state = 0 - elif state == 0 and c == '\'': # ex. ['] + elif state == 0 and c == "'": # ex. ['] state = 5 - elif state == 5 and c == '\\': # ex. ['\] + elif state == 5 and c == "\\": # ex. ['\] state = 6 elif state == 6: # ex. ['\n or '\' or '\t etc.] state = 5 - elif state == 5 and c == '\'': # ex. ['\n' or '\'' or '\t' ect.] + elif state == 5 and c == "'": # ex. ['\n' or '\'' or '\t' ect.] state = 0 - elif state == 0 and c == '\"': # ex. ["] + elif state == 0 and c == '"': # ex. ["] state = 7 - elif state == 7 and c == '\\': # ex. ["\] + elif state == 7 and c == "\\": # ex. ["\] state = 8 elif state == 8: # ex. ["\n or "\" or "\t ect.] state = 7 - elif state == 7 and c == '\"': # ex. ["\n" or "\"" or "\t" ect.] + elif state == 7 and c == '"': # ex. ["\n" or "\"" or "\t" ect.] state = 0 - if (state == 0 and c != '/') or state == 5 or \ - state == 6 or state == 7 or state == 8: + if ( + (state == 0 and c != "/") + or state == 5 + or state == 6 + or state == 7 + or state == 8 + ): strOutput += c else: # removed characters @@ -146,15 +151,15 @@ def removeCppComment(strInput): for r, d, f in os.walk(sys.argv[1]): for file in f: validate = 0 - if '.cxx' in file: + if ".cxx" in file: with open(os.path.join(r, file)) as fin: - if '::InitFromConfigFile' in fin.read(): + if "::InitFromConfigFile" in fin.read(): validate = 1 with open(os.path.join(r, file)) as fin: - if '::LoadDefaultConfig' in fin.read(): + if "::LoadDefaultConfig" in fin.read(): validate = 1 with open(os.path.join(r, file)) as fin: - if '::Initialize' in fin.read(): + if "::Initialize" in fin.read(): validate = validate + 1 if validate == 2: files.append(os.path.join(r, file)) diff --git a/src/TRestTrackDetachIsolatedNodesProcess.cxx b/src/TRestTrackDetachIsolatedNodesProcess.cxx index c4b6499..b7652a0 100644 --- a/src/TRestTrackDetachIsolatedNodesProcess.cxx +++ b/src/TRestTrackDetachIsolatedNodesProcess.cxx @@ -55,7 +55,8 @@ TRestEvent* TRestTrackDetachIsolatedNodesProcess::ProcessEvent(TRestEvent* input cout << "TRestTrackDetachIsolatedNodesProcess. Number of tracks : " << fInputTrackEvent->GetNumberOfTracks() << endl; - if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) fInputTrackEvent->PrintEvent(); + if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) + fInputTrackEvent->PrintEvent(); // Copying the input tracks to the output track for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++) diff --git a/tsp/inc/bigguy.h b/tsp/inc/bigguy.h index 52be636..3aee991 100644 --- a/tsp/inc/bigguy.h +++ b/tsp/inc/bigguy.h @@ -74,6 +74,6 @@ CCbigguy CCbigguy_itobigguy(int d), CCbigguy_dtobigguy(double d), CCbigguy_ceil( #define CCbigguy_add(x, y) (CCbigguy_addmult(x, y, 1)) #define CCbigguy_sub(x, y) (CCbigguy_addmult(x, y, -1)) -int CCbigguy_swrite(CC_SFILE*f, CCbigguy x), CCbigguy_sread(CC_SFILE*f, CCbigguy*x); +int CCbigguy_swrite(CC_SFILE* f, CCbigguy x), CCbigguy_sread(CC_SFILE* f, CCbigguy* x); #endif /* __BIGGUY_H */ diff --git a/tsp/inc/combs.h b/tsp/inc/combs.h index 3e18b40..1eabfea 100644 --- a/tsp/inc/combs.h +++ b/tsp/inc/combs.h @@ -41,12 +41,12 @@ typedef struct CC_GCgraph { CC_GCedge* edgespace; } CC_GCgraph; -int CCcombs_find_blocks(int ncount, int ecount, int*elist, double*x, int*nblocks, int**blockcnts, - int***blocks, int*ncutnodes, int**cutnodes), - CCcombs_greedy_cut(CC_GCgraph*g, int*setsize, int*set, int mark_fixed, int forced_moves, int bad_moves, - int fixed_moves, int*moves_done, double*cut_val), - CCcombs_GC_build_graph(CC_GCgraph*G, int ncount, int ecount, int*elist, double*x); +int CCcombs_find_blocks(int ncount, int ecount, int* elist, double* x, int* nblocks, int** blockcnts, + int*** blocks, int* ncutnodes, int** cutnodes), + CCcombs_greedy_cut(CC_GCgraph* g, int* setsize, int* set, int mark_fixed, int forced_moves, int bad_moves, + int fixed_moves, int* moves_done, double* cut_val), + CCcombs_GC_build_graph(CC_GCgraph* G, int ncount, int ecount, int* elist, double* x); -void CCcombs_GC_init_graph(CC_GCgraph*G), CCcombs_GC_free_graph(CC_GCgraph*G); +void CCcombs_GC_init_graph(CC_GCgraph* G), CCcombs_GC_free_graph(CC_GCgraph* G); #endif /* __COMBS_H */ diff --git a/tsp/inc/cut.h b/tsp/inc/cut.h index 788c25c..a7cf385 100644 --- a/tsp/inc/cut.h +++ b/tsp/inc/cut.h @@ -34,22 +34,23 @@ #define CC_MINCUT_BIGDOUBLE (1e30) #define CC_MINCUT_ONE_EPSILON (0.000001) -int CCcut_mincut(int ncount, int ecount, int*elist, double*dlen, double*cutval, int**cut, int*cutcount), - CCcut_violated_cuts(int ncount, int ecount, int*elist, double*dlen, double cutoff, - int (*doit_fn)(double, int, int*, void*), void*pass_param), - CCcut_shrink_cuts(int ncount, int ecount, int*elist, double*dlen, double cutoff, - int (*doit_fn)(double, int, int*, void*), void*pass_param), - CCcut_mincut_containing_set(int ncount, int ecount, int*elist, double*dlen, int scount, int*slist, - double*cutval, int**cut, int*cutcount, int quickshrink, CCrandstate*rstate), - CCcut_mincut_st(int ncount, int ecount, int*elist, double*ecap, int s, int t, double*value, int**cut, - int*cutcount), - CCcut_linsub(int ncount, int ecount, int*endmark, int*elist, double*x, double maxval, void*u_data, - int (*cut_callback)(double cut_val, int cut_start, int cut_end, void*u_data)), - CCcut_linsub_allcuts(int ncount, int ecount, int*perm, int*endmark, int*elist, double*x, double maxval, - void*u_data, - int (*cut_callback)(double cut_val, int cut_start, int cut_end, void*u_data)), - CCcut_connect_components(int ncount, int ecount, int*elist, double*x, int*ncomp, int**compscount, - int**comps); +int CCcut_mincut(int ncount, int ecount, int* elist, double* dlen, double* cutval, int** cut, int* cutcount), + CCcut_violated_cuts(int ncount, int ecount, int* elist, double* dlen, double cutoff, + int (*doit_fn)(double, int, int*, void*), void* pass_param), + CCcut_shrink_cuts(int ncount, int ecount, int* elist, double* dlen, double cutoff, + int (*doit_fn)(double, int, int*, void*), void* pass_param), + CCcut_mincut_containing_set(int ncount, int ecount, int* elist, double* dlen, int scount, int* slist, + double* cutval, int** cut, int* cutcount, int quickshrink, + CCrandstate* rstate), + CCcut_mincut_st(int ncount, int ecount, int* elist, double* ecap, int s, int t, double* value, int** cut, + int* cutcount), + CCcut_linsub(int ncount, int ecount, int* endmark, int* elist, double* x, double maxval, void* u_data, + int (*cut_callback)(double cut_val, int cut_start, int cut_end, void* u_data)), + CCcut_linsub_allcuts(int ncount, int ecount, int* perm, int* endmark, int* elist, double* x, + double maxval, void* u_data, + int (*cut_callback)(double cut_val, int cut_start, int cut_end, void* u_data)), + CCcut_connect_components(int ncount, int ecount, int* elist, double* x, int* ncomp, int** compscount, + int** comps); /****************************************************************************/ /* */ @@ -78,7 +79,7 @@ typedef struct CC_GHtree { int CCcut_gomory_hu(CC_GHtree* T, int ncount, int ecount, int* elist, double* ecap, int markcount, int* marks, CCrandstate* rstate); -void CCcut_GHtreeinit(CC_GHtree*T), CCcut_GHtreefree(CC_GHtree*T), CCcut_GHtreeprint(CC_GHtree*T); +void CCcut_GHtreeinit(CC_GHtree* T), CCcut_GHtreefree(CC_GHtree* T), CCcut_GHtreeprint(CC_GHtree* T); /****************************************************************************/ /* */ @@ -132,32 +133,33 @@ typedef struct CC_SRKcallback { int (*doit_fn)(double, int, int*, void*); } CC_SRKcallback; -void CCcut_SRK_identify_paths(CC_SRKgraph*G, int*newcount, int onecnt_okay), - CCcut_SRK_identify_paths_to_edges(CC_SRKgraph*G, int*newcount, int onecnt_okay), - CCcut_SRK_identify_ones(CC_SRKgraph*G, int*count, double epsilon), - CCcut_SRK_identify_one_triangles(CC_SRKgraph*G, int*count, CC_SRKnode*qstart, double epsilon, +void CCcut_SRK_identify_paths(CC_SRKgraph* G, int* newcount, int onecnt_okay), + CCcut_SRK_identify_paths_to_edges(CC_SRKgraph* G, int* newcount, int onecnt_okay), + CCcut_SRK_identify_ones(CC_SRKgraph* G, int* count, double epsilon), + CCcut_SRK_identify_one_triangles(CC_SRKgraph* G, int* count, CC_SRKnode* qstart, double epsilon, double cutoff, int unmarked), - CCcut_SRK_identify_tight_triangles(CC_SRKgraph*G, int*count, double cutoff, int unmarked), - CCcut_SRK_identify_tight_squares(CC_SRKgraph*G, int*count, double cutoff, int unmarked), - CCcut_SRK_identify_triangle_square(CC_SRKgraph*G, int*count, double epsilon, int unmarked), - CCcut_SRK_identify_one_square(CC_SRKgraph*G, int*count, double epsilon, double cutoff, int unmarked), - CCcut_SRK_identify_nodes(CC_SRKgraph*G, CC_SRKnode*n, CC_SRKnode*m), CCcut_SRK_init_graph(CC_SRKgraph*G), - CCcut_SRK_free_graph(CC_SRKgraph*G), CCcut_SRK_init_expinfo(CC_SRKexpinfo*expand), - CCcut_SRK_free_expinfo(CC_SRKexpinfo*expand), CCcut_SRK_init_callback(CC_SRKcallback*cb), - CCcut_SRK_increment_marker(CC_SRKgraph*G), CCcut_SRK_set_mark(CC_SRKgraph*G, int marker); - -int CCcut_SRK_buildgraph(CC_SRKgraph*G, int ncount, int ecount, int*elist, double*dlen), - CCcut_SRK_subtour_shrink(CC_SRKgraph*G, double*minval, double epsilon, CC_SRKcallback*cb, int**cut, - int*cutcount), - CCcut_SRK_crowder_padberg(CC_SRKgraph*G, double epsilon, CC_SRKcallback*cb), - CCcut_SRK_identify_pr_edges(CC_SRKgraph*G, double*minval, int*count, CC_SRKnode*qstart, double epsilon, - CC_SRKcallback*cb, int**cut, int*cutcount), - CCcut_SRK_identify_set(CC_SRKgraph*G, int scount, int*slist), CCcut_SRK_defluff(CC_SRKgraph*G), - CCcut_SRK_grab_edges(CC_SRKgraph*G, int*oncount, int*oecount, int**olist, double**olen, - CC_SRKexpinfo*expand), - CCcut_SRK_grab_nodes(CC_SRKgraph*G, CC_SRKexpinfo*expand), - CCcut_SRK_trivial(int ncount, CC_SRKexpinfo*expand), - CCcut_SRK_expand(CC_SRKexpinfo*expand, int*arr, int size, int**pnewarr, int*pnewsize), - CCcut_SRK_original_ncount(CC_SRKexpinfo*expand); + CCcut_SRK_identify_tight_triangles(CC_SRKgraph* G, int* count, double cutoff, int unmarked), + CCcut_SRK_identify_tight_squares(CC_SRKgraph* G, int* count, double cutoff, int unmarked), + CCcut_SRK_identify_triangle_square(CC_SRKgraph* G, int* count, double epsilon, int unmarked), + CCcut_SRK_identify_one_square(CC_SRKgraph* G, int* count, double epsilon, double cutoff, int unmarked), + CCcut_SRK_identify_nodes(CC_SRKgraph* G, CC_SRKnode* n, CC_SRKnode* m), + CCcut_SRK_init_graph(CC_SRKgraph* G), CCcut_SRK_free_graph(CC_SRKgraph* G), + CCcut_SRK_init_expinfo(CC_SRKexpinfo* expand), CCcut_SRK_free_expinfo(CC_SRKexpinfo* expand), + CCcut_SRK_init_callback(CC_SRKcallback* cb), CCcut_SRK_increment_marker(CC_SRKgraph* G), + CCcut_SRK_set_mark(CC_SRKgraph* G, int marker); + +int CCcut_SRK_buildgraph(CC_SRKgraph* G, int ncount, int ecount, int* elist, double* dlen), + CCcut_SRK_subtour_shrink(CC_SRKgraph* G, double* minval, double epsilon, CC_SRKcallback* cb, int** cut, + int* cutcount), + CCcut_SRK_crowder_padberg(CC_SRKgraph* G, double epsilon, CC_SRKcallback* cb), + CCcut_SRK_identify_pr_edges(CC_SRKgraph* G, double* minval, int* count, CC_SRKnode* qstart, + double epsilon, CC_SRKcallback* cb, int** cut, int* cutcount), + CCcut_SRK_identify_set(CC_SRKgraph* G, int scount, int* slist), CCcut_SRK_defluff(CC_SRKgraph* G), + CCcut_SRK_grab_edges(CC_SRKgraph* G, int* oncount, int* oecount, int** olist, double** olen, + CC_SRKexpinfo* expand), + CCcut_SRK_grab_nodes(CC_SRKgraph* G, CC_SRKexpinfo* expand), + CCcut_SRK_trivial(int ncount, CC_SRKexpinfo* expand), + CCcut_SRK_expand(CC_SRKexpinfo* expand, int* arr, int size, int** pnewarr, int* pnewsize), + CCcut_SRK_original_ncount(CC_SRKexpinfo* expand); #endif /* __CUT_H */ diff --git a/tsp/inc/cuttree.h b/tsp/inc/cuttree.h index 128768e..5fc3bf5 100644 --- a/tsp/inc/cuttree.h +++ b/tsp/inc/cuttree.h @@ -19,17 +19,17 @@ #include "pq.h" #include "tsp.h" -void CCpq_cuttree_init(CCtsp_cuttree*t), CCpq_cuttree_freetree(CCtsp_cuttree*t), - CCpq_check_clique(CCpq_tree*pqt, CCtsp_lpclique*c, int*status), CCpq_cuttree_display(CCtsp_cuttree*t), - CCpq_cuttree_describe(CCtsp_cuttree*t); +void CCpq_cuttree_init(CCtsp_cuttree* t), CCpq_cuttree_freetree(CCtsp_cuttree* t), + CCpq_check_clique(CCpq_tree* pqt, CCtsp_lpclique* c, int* status), CCpq_cuttree_display(CCtsp_cuttree* t), + CCpq_cuttree_describe(CCtsp_cuttree* t); -int CCpq_cuttree_trivial(CCtsp_cuttree*t, int nodecount, int extern_node), - CCpq_cuttree_update_clean(CCtsp_cuttree*t, int edgecount, int*elist, double*x), - CCpq_cuttree_improve_quick(CCtsp_cuttree*t, CCtsp_lpcuts*pool, int edgecount, int*elist, double*x), - CCpq_apply_clique(CCpq_tree*T, CCtsp_lpclique*c, int*status), - CCpq_cuttree_gen_cliques(CCtsp_cuttree*t, void*u_data, - int (*cut_callback)(int*arr, int cnt, int*stop, void*u_data)), - CCpq_cuttree_build_necklaces(CCtsp_cuttree*t, int ecount, int*elist, double*x, int*p_neckcount, - CCtsp_cutnode***p_necklist, int*necknum); +int CCpq_cuttree_trivial(CCtsp_cuttree* t, int nodecount, int extern_node), + CCpq_cuttree_update_clean(CCtsp_cuttree* t, int edgecount, int* elist, double* x), + CCpq_cuttree_improve_quick(CCtsp_cuttree* t, CCtsp_lpcuts* pool, int edgecount, int* elist, double* x), + CCpq_apply_clique(CCpq_tree* T, CCtsp_lpclique* c, int* status), + CCpq_cuttree_gen_cliques(CCtsp_cuttree* t, void* u_data, + int (*cut_callback)(int* arr, int cnt, int* stop, void* u_data)), + CCpq_cuttree_build_necklaces(CCtsp_cuttree* t, int ecount, int* elist, double* x, int* p_neckcount, + CCtsp_cutnode*** p_necklist, int* necknum); #endif /* __CUTTREE_H */ diff --git a/tsp/inc/edgegen.h b/tsp/inc/edgegen.h index a5cb51a..66f33b2 100644 --- a/tsp/inc/edgegen.h +++ b/tsp/inc/edgegen.h @@ -77,9 +77,9 @@ typedef struct CCedgegengroup { int mlinkern; } CCedgegengroup; -int CCedgegen_read(char*egname, CCedgegengroup*plan), - CCedgegen_edges(CCedgegengroup*plan, int ncount, CCdatagroup*dat, double*wcoord, int*ecount, int**elist, - int silent, CCrandstate*rstate); +int CCedgegen_read(char* egname, CCedgegengroup* plan), + CCedgegen_edges(CCedgegengroup* plan, int ncount, CCdatagroup* dat, double* wcoord, int* ecount, + int** elist, int silent, CCrandstate* rstate); void CCedgegen_init_edgegengroup(CCedgegengroup* plan); /****************************************************************************/ @@ -95,29 +95,30 @@ typedef struct CCxnear { int* invnames; } CCxnear; -int CCedgegen_x_k_nearest(int ncount, int num, CCdatagroup*dat, double*wcoord, int wantlist, int*ecount, - int**elist, int silent), - CCedgegen_x_quadrant_k_nearest(int ncount, int num, CCdatagroup*dat, double*wcoord, int wantlist, - int*ecount, int**elist, int silent), - CCedgegen_x_node_k_nearest(CCxnear*xn, int n, int nearnum, int ncount, int*list), - CCedgegen_x_node_quadrant_k_nearest(CCxnear*xn, int n, int nearnum, int ncount, int*list), - CCedgegen_x_node_nearest(CCxnear*xn, int ncount, int ni, char*marks), - CCedgegen_x_nearest_neighbor_tour(int ncount, int start, CCdatagroup*dat, int*outcycle, double*val), - CCedgegen_x_greedy_tour(int ncount, CCdatagroup*dat, int*outcycle, double*val, int ecount, int*elist, +int CCedgegen_x_k_nearest(int ncount, int num, CCdatagroup* dat, double* wcoord, int wantlist, int* ecount, + int** elist, int silent), + CCedgegen_x_quadrant_k_nearest(int ncount, int num, CCdatagroup* dat, double* wcoord, int wantlist, + int* ecount, int** elist, int silent), + CCedgegen_x_node_k_nearest(CCxnear* xn, int n, int nearnum, int ncount, int* list), + CCedgegen_x_node_quadrant_k_nearest(CCxnear* xn, int n, int nearnum, int ncount, int* list), + CCedgegen_x_node_nearest(CCxnear* xn, int ncount, int ni, char* marks), + CCedgegen_x_nearest_neighbor_tour(int ncount, int start, CCdatagroup* dat, int* outcycle, double* val), + CCedgegen_x_greedy_tour(int ncount, CCdatagroup* dat, int* outcycle, double* val, int ecount, int* elist, int silent), - CCedgegen_x_qboruvka_tour(int ncount, CCdatagroup*dat, int*outcycle, double*val, int ecount, int*elist, - int silent), - CCedgegen_junk_k_nearest(int ncount, int num, CCdatagroup*dat, double*wcoord, int wantlist, int*ecount, - int**elist, int silent), - CCedgegen_junk_node_k_nearest(CCdatagroup*dat, double*wcoord, int n, int nearnum, int ncount, int*list), - CCedgegen_junk_node_nearest(CCdatagroup*dat, double*wcoord, int ncount, int n, char*marks), - CCedgegen_junk_nearest_neighbor_tour(int ncount, int start, CCdatagroup*dat, int*outcycle, double*val, + CCedgegen_x_qboruvka_tour(int ncount, CCdatagroup* dat, int* outcycle, double* val, int ecount, + int* elist, int silent), + CCedgegen_junk_k_nearest(int ncount, int num, CCdatagroup* dat, double* wcoord, int wantlist, int* ecount, + int** elist, int silent), + CCedgegen_junk_node_k_nearest(CCdatagroup* dat, double* wcoord, int n, int nearnum, int ncount, + int* list), + CCedgegen_junk_node_nearest(CCdatagroup* dat, double* wcoord, int ncount, int n, char* marks), + CCedgegen_junk_nearest_neighbor_tour(int ncount, int start, CCdatagroup* dat, int* outcycle, double* val, int silent), - CCedgegen_junk_greedy_tour(int ncount, CCdatagroup*dat, int*outcycle, double*val, int ecount, int*elist, - int silent), - CCedgegen_junk_qboruvka_tour(int ncount, CCdatagroup*dat, int*outcycle, double*val, int ecount, int*elist, - int silent), - CCedgegen_xnear_build(int ncount, CCdatagroup*dat, double*wcoord, CCxnear*xn); + CCedgegen_junk_greedy_tour(int ncount, CCdatagroup* dat, int* outcycle, double* val, int ecount, + int* elist, int silent), + CCedgegen_junk_qboruvka_tour(int ncount, CCdatagroup* dat, int* outcycle, double* val, int ecount, + int* elist, int silent), + CCedgegen_xnear_build(int ncount, CCdatagroup* dat, double* wcoord, CCxnear* xn); void CCedgegen_xnear_free(CCxnear* xn); diff --git a/tsp/inc/heldkarp.h b/tsp/inc/heldkarp.h index 5ec9a9c..4c40399 100644 --- a/tsp/inc/heldkarp.h +++ b/tsp/inc/heldkarp.h @@ -21,10 +21,10 @@ #include "util.h" -int CCheldkarp_small(int ncount, CCdatagroup*dat, double*upbound, double*optval, int*foundtour, int anytour, - int*tour_elist, int nodelimit, int silent), - CCheldkarp_small_elist(int ncount, int ecount, int*elist, int*elen, double*upbound, double*optval, - int*foundtour, int anytour, int*tour_elist, int nodelimit, int silent); +int CCheldkarp_small(int ncount, CCdatagroup* dat, double* upbound, double* optval, int* foundtour, + int anytour, int* tour_elist, int nodelimit, int silent), + CCheldkarp_small_elist(int ncount, int ecount, int* elist, int* elen, double* upbound, double* optval, + int* foundtour, int anytour, int* tour_elist, int nodelimit, int silent); // Added to introduce user-defined distance matrix (through *elen) int CCheldkarp_small_segment(int ncount, int* elen, double* upbound, double* optval, int* foundtour, diff --git a/tsp/inc/kdtree.h b/tsp/inc/kdtree.h index a5772e2..96a93de 100644 --- a/tsp/inc/kdtree.h +++ b/tsp/inc/kdtree.h @@ -46,39 +46,39 @@ typedef struct CCkdbnds { struct CCkdbnds* next; } CCkdbnds; -void CCkdtree_free(CCkdtree*kt), CCkdtree_delete(CCkdtree*kt, int k), - CCkdtree_delete_all(CCkdtree*kt, int ncount), CCkdtree_undelete(CCkdtree*kt, int k), - CCkdtree_undelete_all(CCkdtree*kt, int ncount); +void CCkdtree_free(CCkdtree* kt), CCkdtree_delete(CCkdtree* kt, int k), + CCkdtree_delete_all(CCkdtree* kt, int ncount), CCkdtree_undelete(CCkdtree* kt, int k), + CCkdtree_undelete_all(CCkdtree* kt, int ncount); -int CCkdtree_build(CCkdtree*kt, int ncount, CCdatagroup*dat, double*wcoord, CCrandstate*rstate), - CCkdtree_k_nearest(CCkdtree*kt, int ncount, int k, CCdatagroup*dat, double*wcoord, int wantlist, - int*ocount, int**olist, int silent, CCrandstate*rstate), - CCkdtree_quadrant_k_nearest(CCkdtree*kt, int ncount, int k, CCdatagroup*dat, double*wcoord, int wantlist, - int*ocount, int**olist, int silent, CCrandstate*rstate), - CCkdtree_node_k_nearest(CCkdtree*kt, int ncount, int n, int k, CCdatagroup*dat, double*wcoord, int*list, - CCrandstate*rstate), - CCkdtree_node_quadrant_k_nearest(CCkdtree*kt, int ncount, int n, int k, CCdatagroup*dat, double*wcoord, - int*list, CCrandstate*rstate), - CCkdtree_node_nearest(CCkdtree*kt, int n, CCdatagroup*dat, double*wcoord), - CCkdtree_fixed_radius_nearest(CCkdtree*kt, CCdatagroup*dat, double*wcoord, int n, double rad, - int (*doit_fn)(int, int, void*), void*pass_param), - CCkdtree_nearest_neighbor_tour(CCkdtree*kt, int ncount, int start, CCdatagroup*dat, int*outcycle, - double*val, CCrandstate*rstate), - CCkdtree_nearest_neighbor_2match(CCkdtree*kt, int ncount, int start, CCdatagroup*dat, int*outmatch, - double*val, CCrandstate*rstate), - CCkdtree_prim_spanningtree(CCkdtree*kt, int ncount, CCdatagroup*dat, double*wcoord, int*outtree, - double*val, CCrandstate*rstate), - CCkdtree_greedy_tour(CCkdtree*kt, int ncount, CCdatagroup*dat, int*outcycle, double*val, int silent, - CCrandstate*rstate), - CCkdtree_far_add_tour(CCkdtree*kt, int ncount, int start, CCdatagroup*dat, int*outcycle, double*val, - CCrandstate*rstate), - CCkdtree_qboruvka_tour(CCkdtree*kt, int ncount, CCdatagroup*dat, int*outcycle, double*val, - CCrandstate*rstate), - CCkdtree_boruvka_tour(CCkdtree*kt, int ncount, CCdatagroup*dat, int*outcycle, double*val, - CCrandstate*rstate), - CCkdtree_twoopt_tour(CCkdtree*kt, int ncount, CCdatagroup*dat, int*incycle, int*outcycle, double*val, - int run_two_and_a_half_opt, int silent, CCrandstate*rstate), - CCkdtree_3opt_tour(CCkdtree*kt, int ncount, CCdatagroup*dat, int*incycle, int*outcycle, double*val, - int silent, CCrandstate*rstate); +int CCkdtree_build(CCkdtree* kt, int ncount, CCdatagroup* dat, double* wcoord, CCrandstate* rstate), + CCkdtree_k_nearest(CCkdtree* kt, int ncount, int k, CCdatagroup* dat, double* wcoord, int wantlist, + int* ocount, int** olist, int silent, CCrandstate* rstate), + CCkdtree_quadrant_k_nearest(CCkdtree* kt, int ncount, int k, CCdatagroup* dat, double* wcoord, + int wantlist, int* ocount, int** olist, int silent, CCrandstate* rstate), + CCkdtree_node_k_nearest(CCkdtree* kt, int ncount, int n, int k, CCdatagroup* dat, double* wcoord, + int* list, CCrandstate* rstate), + CCkdtree_node_quadrant_k_nearest(CCkdtree* kt, int ncount, int n, int k, CCdatagroup* dat, double* wcoord, + int* list, CCrandstate* rstate), + CCkdtree_node_nearest(CCkdtree* kt, int n, CCdatagroup* dat, double* wcoord), + CCkdtree_fixed_radius_nearest(CCkdtree* kt, CCdatagroup* dat, double* wcoord, int n, double rad, + int (*doit_fn)(int, int, void*), void* pass_param), + CCkdtree_nearest_neighbor_tour(CCkdtree* kt, int ncount, int start, CCdatagroup* dat, int* outcycle, + double* val, CCrandstate* rstate), + CCkdtree_nearest_neighbor_2match(CCkdtree* kt, int ncount, int start, CCdatagroup* dat, int* outmatch, + double* val, CCrandstate* rstate), + CCkdtree_prim_spanningtree(CCkdtree* kt, int ncount, CCdatagroup* dat, double* wcoord, int* outtree, + double* val, CCrandstate* rstate), + CCkdtree_greedy_tour(CCkdtree* kt, int ncount, CCdatagroup* dat, int* outcycle, double* val, int silent, + CCrandstate* rstate), + CCkdtree_far_add_tour(CCkdtree* kt, int ncount, int start, CCdatagroup* dat, int* outcycle, double* val, + CCrandstate* rstate), + CCkdtree_qboruvka_tour(CCkdtree* kt, int ncount, CCdatagroup* dat, int* outcycle, double* val, + CCrandstate* rstate), + CCkdtree_boruvka_tour(CCkdtree* kt, int ncount, CCdatagroup* dat, int* outcycle, double* val, + CCrandstate* rstate), + CCkdtree_twoopt_tour(CCkdtree* kt, int ncount, CCdatagroup* dat, int* incycle, int* outcycle, double* val, + int run_two_and_a_half_opt, int silent, CCrandstate* rstate), + CCkdtree_3opt_tour(CCkdtree* kt, int ncount, CCdatagroup* dat, int* incycle, int* outcycle, double* val, + int silent, CCrandstate* rstate); #endif /* __KDTREE_H */ diff --git a/tsp/inc/linkern.h b/tsp/inc/linkern.h index 76f409b..d229f5d 100644 --- a/tsp/inc/linkern.h +++ b/tsp/inc/linkern.h @@ -23,13 +23,13 @@ #define CC_LK_CLOSE_KICK (2) #define CC_LK_WALK_KICK (3) -int CClinkern_tour(int ncount, CCdatagroup*dat, int ecount, int*elist, int stallcount, int repeatcount, - int*incycle, int*outcycle, double*val, int silent, double time_bound, double length_bound, - char*saveit_name, int kicktype, CCrandstate*rstate), - CClinkern_path(int ncount, CCdatagroup*dat, int ecount, int*elist, int nkicks, int*inpath, int*outpath, - double*val, int silent, CCrandstate*rstate), - CClinkern_fixed(int ncount, CCdatagroup*dat, int ecount, int*elist, int nkicks, int*incycle, int*outcycle, - double*val, int fcount, int*flist, int silent, CCrandstate*rstate); +int CClinkern_tour(int ncount, CCdatagroup* dat, int ecount, int* elist, int stallcount, int repeatcount, + int* incycle, int* outcycle, double* val, int silent, double time_bound, + double length_bound, char* saveit_name, int kicktype, CCrandstate* rstate), + CClinkern_path(int ncount, CCdatagroup* dat, int ecount, int* elist, int nkicks, int* inpath, + int* outpath, double* val, int silent, CCrandstate* rstate), + CClinkern_fixed(int ncount, CCdatagroup* dat, int ecount, int* elist, int nkicks, int* incycle, + int* outcycle, double* val, int fcount, int* flist, int silent, CCrandstate* rstate); #endif /* __LINKERN_H */ @@ -66,10 +66,10 @@ typedef struct CClk_flipper { int split_cutoff; } CClk_flipper; -int CClinkern_flipper_init(CClk_flipper*f, int ncount, int*cyc), - CClinkern_flipper_next(CClk_flipper*f, int x), CClinkern_flipper_prev(CClk_flipper*f, int x), - CClinkern_flipper_sequence(CClk_flipper*f, int x, int y, int z); -void CClinkern_flipper_flip(CClk_flipper*F, int x, int y), CClinkern_flipper_cycle(CClk_flipper*F, int*x), - CClinkern_flipper_finish(CClk_flipper*F); +int CClinkern_flipper_init(CClk_flipper* f, int ncount, int* cyc), + CClinkern_flipper_next(CClk_flipper* f, int x), CClinkern_flipper_prev(CClk_flipper* f, int x), + CClinkern_flipper_sequence(CClk_flipper* f, int x, int y, int z); +void CClinkern_flipper_flip(CClk_flipper* F, int x, int y), CClinkern_flipper_cycle(CClk_flipper* F, int* x), + CClinkern_flipper_finish(CClk_flipper* F); #endif /* __FLIPPER_H */ diff --git a/tsp/inc/localcut.h b/tsp/inc/localcut.h index 4f77cc1..06e69c2 100644 --- a/tsp/inc/localcut.h +++ b/tsp/inc/localcut.h @@ -75,14 +75,14 @@ int CCchunk_localcuts(CCtsp_lpcut_in** clist, int* cutcount, int ncount, int eco double eps, CCchunk_flag flags, CCchunk_localcut_timer* timer, int silent, CCrandstate* rstate); -void CCchunk_init_separate_timer(CCchunk_separate_timer*timer), - CCchunk_init_find_timer(CCchunk_find_timer*timer), CCchunk_init_lift_timer(CCchunk_lift_timer*timer), - CCchunk_init_oracle_timer(CCchunk_oracle_timer*timer), - CCchunk_init_localcut_timer(CCchunk_localcut_timer*timer), - CCchunk_print_separate_timer(CCchunk_separate_timer*timer), - CCchunk_print_find_timer(CCchunk_find_timer*timer), CCchunk_print_lift_timer(CCchunk_lift_timer*timer), - CCchunk_print_oracle_timer(CCchunk_oracle_timer*timer), - CCchunk_print_localcut_timer(CCchunk_localcut_timer*timer); +void CCchunk_init_separate_timer(CCchunk_separate_timer* timer), + CCchunk_init_find_timer(CCchunk_find_timer* timer), CCchunk_init_lift_timer(CCchunk_lift_timer* timer), + CCchunk_init_oracle_timer(CCchunk_oracle_timer* timer), + CCchunk_init_localcut_timer(CCchunk_localcut_timer* timer), + CCchunk_print_separate_timer(CCchunk_separate_timer* timer), + CCchunk_print_find_timer(CCchunk_find_timer* timer), CCchunk_print_lift_timer(CCchunk_lift_timer* timer), + CCchunk_print_oracle_timer(CCchunk_oracle_timer* timer), + CCchunk_print_localcut_timer(CCchunk_localcut_timer* timer); typedef struct CCchunklp { CClp* lp; @@ -97,10 +97,10 @@ typedef struct CCchunklp { #define CC_CHUNK_LPFEASIBLE 0 #define CC_CHUNK_LPINFEASIBLE 1 -int CCchunk_lpinit(CCchunklp**lp_p, const char*lp_name, int lp_nrows, double*xstar), - CCchunk_lpaddcol(CCchunklp*lp, double*x), CCchunk_lprelaxrow(CCchunklp*lp, int del_row), - CCchunk_lpsolve(CCchunklp*lp, int*lpstatus_p, double*c, double*alpha_p), - CCchunk_lpbasis(CCchunklp*lp, int ncols, int*basis); +int CCchunk_lpinit(CCchunklp** lp_p, const char* lp_name, int lp_nrows, double* xstar), + CCchunk_lpaddcol(CCchunklp* lp, double* x), CCchunk_lprelaxrow(CCchunklp* lp, int del_row), + CCchunk_lpsolve(CCchunklp* lp, int* lpstatus_p, double* c, double* alpha_p), + CCchunk_lpbasis(CCchunklp* lp, int ncols, int* basis); void CCchunk_lpfree(CCchunklp** lp_p); @@ -148,17 +148,17 @@ typedef struct CCchunk_cut_callback { #define CC_CHUNK_ORACLE_SEARCHLIMITEXCEEDED (1) #define CC_CHUNK_ORACLE_INFEASIBLE (2) -int CCchunk_finder(int ncount, int ecount, int*elist, double*elen, double eps, CCchunk_flag flags, - CCchunk_find_timer*timer, CCchunk_chunk_callback*callback, CCrandstate*rstate), - CCchunk_separate(CCchunk_graph*chunk, CCchunk_separate_timer*timer, CCchunk_fault_callback*callback), - CCchunk_lift(CCchunk_graph*chunk, CCchunk_fault*fault, CCchunk_lift_timer*timer, - CCchunk_cut_callback*callback), - CCchunk_ineq_to_lpcut_in(int nnodes, int ecount, int*elist, int*ecoef, int rhs, CCtsp_lpcut_in*c), - CCchunk_ineq_to_cut(int nnodes, int ecount, int*elist, int*ecoef, int rhs, int outside, - CCchunk_cut_callback*callback), - CCchunk_oracle(CCchunk_graph*ch, CCchunk_ineq*c, int*xsol, int*objval, int rhsvalid, int effort_limit, - CCchunk_oracle_timer*timer), - CCchunk_verify(CCchunk_graph*ch, CCchunk_ineq*c); +int CCchunk_finder(int ncount, int ecount, int* elist, double* elen, double eps, CCchunk_flag flags, + CCchunk_find_timer* timer, CCchunk_chunk_callback* callback, CCrandstate* rstate), + CCchunk_separate(CCchunk_graph* chunk, CCchunk_separate_timer* timer, CCchunk_fault_callback* callback), + CCchunk_lift(CCchunk_graph* chunk, CCchunk_fault* fault, CCchunk_lift_timer* timer, + CCchunk_cut_callback* callback), + CCchunk_ineq_to_lpcut_in(int nnodes, int ecount, int* elist, int* ecoef, int rhs, CCtsp_lpcut_in* c), + CCchunk_ineq_to_cut(int nnodes, int ecount, int* elist, int* ecoef, int rhs, int outside, + CCchunk_cut_callback* callback), + CCchunk_oracle(CCchunk_graph* ch, CCchunk_ineq* c, int* xsol, int* objval, int rhsvalid, int effort_limit, + CCchunk_oracle_timer* timer), + CCchunk_verify(CCchunk_graph* ch, CCchunk_ineq* c); CCchunk_graph* CCchunk_graph_alloc(int ncount, int ecount); @@ -190,11 +190,11 @@ typedef struct CCchunk_intmat { /* Exported functions */ -int CCchunk_intmat_build(CCchunk_intmat*mat_p, int ncols), - CCchunk_intmat_addrow(CCchunk_intmat*mat_p, int*row), - CCchunk_intmat_ortho(CCchunk_intmat*mat_p, int*ortho, int*pcol_p, int*taboo); +int CCchunk_intmat_build(CCchunk_intmat* mat_p, int ncols), + CCchunk_intmat_addrow(CCchunk_intmat* mat_p, int* row), + CCchunk_intmat_ortho(CCchunk_intmat* mat_p, int* ortho, int* pcol_p, int* taboo); -void CCchunk_intmat_init(CCchunk_intmat*mat_p), CCchunk_intmat_free(CCchunk_intmat*mat_p), - CCchunk_intmat_dellastrows(CCchunk_intmat*mat_p, int ndel); +void CCchunk_intmat_init(CCchunk_intmat* mat_p), CCchunk_intmat_free(CCchunk_intmat* mat_p), + CCchunk_intmat_dellastrows(CCchunk_intmat* mat_p, int ndel); #endif /* __LOCALCUT_H_ */ diff --git a/tsp/inc/lp.h b/tsp/inc/lp.h index 3955cd6..e6227b9 100644 --- a/tsp/inc/lp.h +++ b/tsp/inc/lp.h @@ -37,37 +37,38 @@ typedef struct CClp_warmstart CClp_warmstart; struct CClp_info; typedef struct CClp_info CClp_info; -int CClp_init(CClp**lp), CClp_force_perturb(CClp*lp), CClp_tune_small(CClp*lp), - CClp_disable_presolve(CClp*lp), - CClp_loadlp(CClp*lp, const char*name, int ncols, int nrows, int objsense, double*obj, double*rhs, - char*sense, int*matbeg, int*matcnt, int*matind, double*matval, double*lb, double*ub), - CClp_create(CClp*lp, const char*name), CClp_new_row(CClp*lp, char sense, double rhs), - CClp_change_sense(CClp*lp, int row, char sense), CClp_opt(CClp*lp, int method), - CClp_limited_dualopt(CClp*lp, int lim, int*status, double*upperbound), - CClp_addrows(CClp*lp, int newrows, int newnz, double*rhs, char*sense, int*rmatbeg, int*rmatind, - double*rmatval), - CClp_addcols(CClp*lp, int newcols, int newnz, double*obj, int*cmatbeg, int*cmatind, double*cmatval, - double*lb, double*ub), - CClp_delete_row(CClp*lp, int i), CClp_delete_set_of_rows(CClp*lp, int*delstat), - CClp_delete_column(CClp*lp, int i), CClp_delete_set_of_columns(CClp*lp, int*delstat), - CClp_setbnd(CClp*lp, int col, char lower_or_upper, double bnd), - CClp_get_warmstart(CClp*lp, CClp_warmstart**w), CClp_load_warmstart(CClp*lp, CClp_warmstart*w), - CClp_build_warmstart(CClp_warmstart**w, CClp_info*i), CClp_sread_warmstart(CC_SFILE*f, CClp_warmstart**w), - CClp_swrite_warmstart(CC_SFILE*f, CClp_warmstart*w), CClp_get_info(CClp*lp, CClp_info**i), - CClp_create_info(CClp_info**i, int rcount, int ccount), CClp_is_col_active(CClp_info*i, int c), - CClp_is_row_active(CClp_info*i, int c), CClp_x(CClp*lp, double*x), CClp_rc(CClp*lp, double*rc), - CClp_pi(CClp*lp, double*pi), CClp_objval(CClp*lp, double*obj), CClp_nrows(CClp*lp), CClp_ncols(CClp*lp), - CClp_nnonzeros(CClp*lp), CClp_status(CClp*lp, int*status), - CClp_getweight(CClp*lp, int nrows, int*rmatbeg, int*rmatind, double*rmatval, double*weight), - CClp_dump_lp(CClp*lp, const char*fname), - CClp_getgoodlist(CClp*lp, int*goodlist, int*goodlen_p, double*downpen, double*uppen), - CClp_strongbranch(CClp*lp, int*candidatelist, int ncand, double*downpen, double*uppen, int iterations, +int CClp_init(CClp** lp), CClp_force_perturb(CClp* lp), CClp_tune_small(CClp* lp), + CClp_disable_presolve(CClp* lp), + CClp_loadlp(CClp* lp, const char* name, int ncols, int nrows, int objsense, double* obj, double* rhs, + char* sense, int* matbeg, int* matcnt, int* matind, double* matval, double* lb, double* ub), + CClp_create(CClp* lp, const char* name), CClp_new_row(CClp* lp, char sense, double rhs), + CClp_change_sense(CClp* lp, int row, char sense), CClp_opt(CClp* lp, int method), + CClp_limited_dualopt(CClp* lp, int lim, int* status, double* upperbound), + CClp_addrows(CClp* lp, int newrows, int newnz, double* rhs, char* sense, int* rmatbeg, int* rmatind, + double* rmatval), + CClp_addcols(CClp* lp, int newcols, int newnz, double* obj, int* cmatbeg, int* cmatind, double* cmatval, + double* lb, double* ub), + CClp_delete_row(CClp* lp, int i), CClp_delete_set_of_rows(CClp* lp, int* delstat), + CClp_delete_column(CClp* lp, int i), CClp_delete_set_of_columns(CClp* lp, int* delstat), + CClp_setbnd(CClp* lp, int col, char lower_or_upper, double bnd), + CClp_get_warmstart(CClp* lp, CClp_warmstart** w), CClp_load_warmstart(CClp* lp, CClp_warmstart* w), + CClp_build_warmstart(CClp_warmstart** w, CClp_info* i), + CClp_sread_warmstart(CC_SFILE* f, CClp_warmstart** w), + CClp_swrite_warmstart(CC_SFILE* f, CClp_warmstart* w), CClp_get_info(CClp* lp, CClp_info** i), + CClp_create_info(CClp_info** i, int rcount, int ccount), CClp_is_col_active(CClp_info* i, int c), + CClp_is_row_active(CClp_info* i, int c), CClp_x(CClp* lp, double* x), CClp_rc(CClp* lp, double* rc), + CClp_pi(CClp* lp, double* pi), CClp_objval(CClp* lp, double* obj), CClp_nrows(CClp* lp), + CClp_ncols(CClp* lp), CClp_nnonzeros(CClp* lp), CClp_status(CClp* lp, int* status), + CClp_getweight(CClp* lp, int nrows, int* rmatbeg, int* rmatind, double* rmatval, double* weight), + CClp_dump_lp(CClp* lp, const char* fname), + CClp_getgoodlist(CClp* lp, int* goodlist, int* goodlen_p, double* downpen, double* uppen), + CClp_strongbranch(CClp* lp, int* candidatelist, int ncand, double* downpen, double* uppen, int iterations, double upperbound); -void CClp_free(CClp**lp), CClp_freelp(CClp**lp), CClp_free_warmstart(CClp_warmstart**w), - CClp_set_col_active(CClp_info*i, int c), CClp_set_col_inactive(CClp_info*i, int c), - CClp_set_col_upper(CClp_info*i, int c), CClp_set_row_active(CClp_info*i, int r), - CClp_set_row_inactive(CClp_info*i, int r), CClp_free_info(CClp_info**i), CClp_pivotout(CClp*lp, int j), - CClp_pivotin(CClp*lp, int i); +void CClp_free(CClp** lp), CClp_freelp(CClp** lp), CClp_free_warmstart(CClp_warmstart** w), + CClp_set_col_active(CClp_info* i, int c), CClp_set_col_inactive(CClp_info* i, int c), + CClp_set_col_upper(CClp_info* i, int c), CClp_set_row_active(CClp_info* i, int r), + CClp_set_row_inactive(CClp_info* i, int r), CClp_free_info(CClp_info** i), CClp_pivotout(CClp* lp, int j), + CClp_pivotin(CClp* lp, int i); #endif /* __LP_H */ diff --git a/tsp/inc/pq.h b/tsp/inc/pq.h index bb59748..9ff09ed 100644 --- a/tsp/inc/pq.h +++ b/tsp/inc/pq.h @@ -90,12 +90,12 @@ typedef struct CCpq_tree { #define CCpq_add_leaflist(T, i) ((T)->elems[(i)].next = (T)->leaflist, (T)->leaflist = &((T)->elems[(i)])) #define CCpq_set_leaflist(T, l) ((T)->leaflist = l) -void CCpq_tree_init(CCpq_tree*T), CCpq_tree_free(CCpq_tree*T), CCpq_describe_solution(CCpq_tree*T), - CCpq_dump_solution(CCpq_tree*T); +void CCpq_tree_init(CCpq_tree* T), CCpq_tree_free(CCpq_tree* T), CCpq_describe_solution(CCpq_tree* T), + CCpq_dump_solution(CCpq_tree* T); -int CCpq_check(CCpq_tree*T, int*status), CCpq_apply(CCpq_tree*T, int*status), - CCpq_tree_trivial(CCpq_tree*T, int nodecount, int extern_node), - CCpq_cuttree_to_pq(struct CCtsp_cuttree*ct, CCpq_tree*pqT); +int CCpq_check(CCpq_tree* T, int* status), CCpq_apply(CCpq_tree* T, int* status), + CCpq_tree_trivial(CCpq_tree* T, int nodecount, int extern_node), + CCpq_cuttree_to_pq(struct CCtsp_cuttree* ct, CCpq_tree* pqT); CCpq_node* CCpq_find_root(CCpq_tree* T); diff --git a/tsp/inc/tinytsp.h b/tsp/inc/tinytsp.h index 405d6a0..4b77837 100644 --- a/tsp/inc/tinytsp.h +++ b/tsp/inc/tinytsp.h @@ -25,15 +25,15 @@ #define CC_TINYTSP_MAXIMIZE (-1) #define CC_TINYTSP_MINIMIZE (1) -int CCtiny_bnc_tsp(int ncount, CCdatagroup*dat, double*upbound, double*optval, int nodelimit), - CCtiny_bnc_msp(int ncount, int ecount, int*elist, int*elen, int depot, int*lower, int*upper, - double*upperbound, int objsense, double*optval, int*xsol, int checkresult, +int CCtiny_bnc_tsp(int ncount, CCdatagroup* dat, double* upbound, double* optval, int nodelimit), + CCtiny_bnc_msp(int ncount, int ecount, int* elist, int* elen, int depot, int* lower, int* upper, + double* upperbound, int objsense, double* optval, int* xsol, int checkresult, int searchlimit), - CCtiny_bnb_tsp(int nnodes, int nedges, int*elist, int*weight, int*lbound, int*ubound, double*objlimit, - int objdir, double*objval, int*xsol, int searchlimit), - CCtiny_bnb_msp(int nnodes, int nedges, int*elist, int*weight, int depot, int*lbound, int*ubound, - double*objlimit, int objdir, double*objval, int*xsol, int searchlimit), - CCtiny_benttsp_elist(int ncount, int ecount, int*elist, int*elen, double*upbound, double*optval, - int*foundtour, int anytour, int searchlimit, int silent); + CCtiny_bnb_tsp(int nnodes, int nedges, int* elist, int* weight, int* lbound, int* ubound, + double* objlimit, int objdir, double* objval, int* xsol, int searchlimit), + CCtiny_bnb_msp(int nnodes, int nedges, int* elist, int* weight, int depot, int* lbound, int* ubound, + double* objlimit, int objdir, double* objval, int* xsol, int searchlimit), + CCtiny_benttsp_elist(int ncount, int ecount, int* elist, int* elen, double* upbound, double* optval, + int* foundtour, int anytour, int searchlimit, int silent); #endif /* __TINYTSP_H */ diff --git a/tsp/inc/tsp.h b/tsp/inc/tsp.h index 4a5173e..df63f58 100644 --- a/tsp/inc/tsp.h +++ b/tsp/inc/tsp.h @@ -524,24 +524,24 @@ typedef struct CCtsp_cutselect { #define CCtsp_BBTASK_TENTATIVE_BRANCH 'j' #define CCtsp_BBREQ_TENTATIVE_BRANCHDONE 'J' -int CCtsp_bfs_brancher(char*probloc, int id, double lowerbound, CCtsp_cutselect*sel, CCtsp_cutselect*tsel, - double*upbound, int*bbcount, int usecliques, CCdatagroup*mydat, int*ptour, - CCtsp_lpcuts*pool, int ncount, int*besttour, unsigned short hostport, - double*branchzeit, int save_proof, int tentative_branch_num, int longedge_branching, - double*timebound, int*hit_timebound, int silent, CCrandstate*rstate), - CCtsp_bfs_restart(char*probloc, char*restart_name, CCtsp_cutselect*sel, CCtsp_cutselect*tsel, - double*upbound, int*bbcount, int usecliques, CCdatagroup*dat, int*ptour, - CCtsp_lpcuts*pool, int ncount, int*besttour, unsigned short hostport, double*branchzeit, - int save_proof, int tentative_branch_num, int longedge_branching, double*timebound, - int*hit_timebound, int silent, CCrandstate*rstate), +int CCtsp_bfs_brancher(char* probloc, int id, double lowerbound, CCtsp_cutselect* sel, CCtsp_cutselect* tsel, + double* upbound, int* bbcount, int usecliques, CCdatagroup* mydat, int* ptour, + CCtsp_lpcuts* pool, int ncount, int* besttour, unsigned short hostport, + double* branchzeit, int save_proof, int tentative_branch_num, int longedge_branching, + double* timebound, int* hit_timebound, int silent, CCrandstate* rstate), + CCtsp_bfs_restart(char* probloc, char* restart_name, CCtsp_cutselect* sel, CCtsp_cutselect* tsel, + double* upbound, int* bbcount, int usecliques, CCdatagroup* dat, int* ptour, + CCtsp_lpcuts* pool, int ncount, int* besttour, unsigned short hostport, + double* branchzeit, int save_proof, int tentative_branch_num, int longedge_branching, + double* timebound, int* hit_timebound, int silent, CCrandstate* rstate), #ifdef CC_NETREADY - CCtsp_grunt(char*hostname, unsigned short hostport, char*poolfname, char*cutbossname, char*probloc, - int silent, CCrandstate*rstate), + CCtsp_grunt(char* hostname, unsigned short hostport, char* poolfname, char* cutbossname, char* probloc, + int silent, CCrandstate* rstate), #endif /* CC_NETREADY */ - CCtsp_easy_dfs_brancher(CCtsp_lp*lp, CCtsp_cutselect*sel, int depth, double*upbound, int*bbcount, - int usecliques, int*besttour, int longedge_branching, int simple_branching, - int silent, CCrandstate*rstate), - CCtsp_do_interactive_branch(CCtsp_lp*lp, int silent, CCrandstate*rstate); + CCtsp_easy_dfs_brancher(CCtsp_lp* lp, CCtsp_cutselect* sel, int depth, double* upbound, int* bbcount, + int usecliques, int* besttour, int longedge_branching, int simple_branching, + int silent, CCrandstate* rstate), + CCtsp_do_interactive_branch(CCtsp_lp* lp, int silent, CCrandstate* rstate); /****************************************************************************/ /* */ @@ -558,10 +558,10 @@ int CCtsp_block_combs(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecou /* */ /****************************************************************************/ -int CCtsp_fastblossom(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x), - CCtsp_ghfastblossom(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x), - CCtsp_exactblossom(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x, - CCrandstate*rstate); +int CCtsp_fastblossom(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x), + CCtsp_ghfastblossom(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x), + CCtsp_exactblossom(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x, + CCrandstate* rstate); /****************************************************************************/ /* */ @@ -569,30 +569,32 @@ int CCtsp_fastblossom(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount /* */ /****************************************************************************/ -int CCtsp_find_branch(CCtsp_lp*lp, int nwant, int*ngot, CCtsp_branchobj**bobj, double*val, int**cyc, +int CCtsp_find_branch(CCtsp_lp* lp, int nwant, int* ngot, CCtsp_branchobj** bobj, double* val, int** cyc, int usecliques, int longedge_branching, int silent), - CCtsp_find_fast_branch(CCtsp_lp*lp, int*ngot, CCtsp_branchobj**bobj, double*val, int**cyc, int usecliques, - int longedge_branching, int silent), - CCtsp_find_branch_edge(CCtsp_lp*lp, int*n0, int*n1, double*val, int**cyc, int branchtype, int silent), - CCtsp_check_integral(CCtsp_lp*lp, double*val, int**cyc, int*yesno, int silent), - CCtsp_find_branch_cliques(CCtsp_lp*lp, int nwant, int longedge_branching, int*ngot, - CCtsp_lpclique**bcliques, double**bval, int silent), - CCtsp_execute_branch(CCtsp_lp*lp, CCtsp_branchobj*b, int silent, CCrandstate*rstate), - CCtsp_execute_unbranch(CCtsp_lp*lp, CClp_warmstart*warmstart, int silent, CCrandstate*rstate), - CCtsp_add_branchhistory_to_lp(CCtsp_lp*lp), - CCtsp_bb_find_branch(char*probname, int probnum, int ncount, CCdatagroup*dat, int*ptour, - double*upperbound, CCtsp_lpcuts*pool, int nwant, int*ngot, CCtsp_branchobj**b, - int usecliques, int longedge_branching, int*prune, int*foundtour, int*besttour, - int silent, CCrandstate*rstate), - CCtsp_splitprob(CCtsp_lp*lp, CCtsp_branchobj*b, int child0, int child1, int silent, CCrandstate*rstate), - CCtsp_bb_splitprob(char*probname, int probnum, int ncount, CCdatagroup*dat, int*ptour, double initial_ub, - CCtsp_lpcuts*pool, CCtsp_branchobj*b, int child0, int child1, double*val0, double*val1, - int*prune0, int*prune1, int silent, CCrandstate*rstate), - CCtsp_dumptour(int ncount, CCdatagroup*dat, int*perm, char*probname, int*tour, char*fname, int writeedges, - int silent); - -void CCtsp_init_branchobj(CCtsp_branchobj*b), CCtsp_free_branchobj(CCtsp_branchobj*b), - CCtsp_print_branchhistory(CCtsp_lp*lp); + CCtsp_find_fast_branch(CCtsp_lp* lp, int* ngot, CCtsp_branchobj** bobj, double* val, int** cyc, + int usecliques, int longedge_branching, int silent), + CCtsp_find_branch_edge(CCtsp_lp* lp, int* n0, int* n1, double* val, int** cyc, int branchtype, + int silent), + CCtsp_check_integral(CCtsp_lp* lp, double* val, int** cyc, int* yesno, int silent), + CCtsp_find_branch_cliques(CCtsp_lp* lp, int nwant, int longedge_branching, int* ngot, + CCtsp_lpclique** bcliques, double** bval, int silent), + CCtsp_execute_branch(CCtsp_lp* lp, CCtsp_branchobj* b, int silent, CCrandstate* rstate), + CCtsp_execute_unbranch(CCtsp_lp* lp, CClp_warmstart* warmstart, int silent, CCrandstate* rstate), + CCtsp_add_branchhistory_to_lp(CCtsp_lp* lp), + CCtsp_bb_find_branch(char* probname, int probnum, int ncount, CCdatagroup* dat, int* ptour, + double* upperbound, CCtsp_lpcuts* pool, int nwant, int* ngot, CCtsp_branchobj** b, + int usecliques, int longedge_branching, int* prune, int* foundtour, int* besttour, + int silent, CCrandstate* rstate), + CCtsp_splitprob(CCtsp_lp* lp, CCtsp_branchobj* b, int child0, int child1, int silent, + CCrandstate* rstate), + CCtsp_bb_splitprob(char* probname, int probnum, int ncount, CCdatagroup* dat, int* ptour, + double initial_ub, CCtsp_lpcuts* pool, CCtsp_branchobj* b, int child0, int child1, + double* val0, double* val1, int* prune0, int* prune1, int silent, CCrandstate* rstate), + CCtsp_dumptour(int ncount, CCdatagroup* dat, int* perm, char* probname, int* tour, char* fname, + int writeedges, int silent); + +void CCtsp_init_branchobj(CCtsp_branchobj* b), CCtsp_free_branchobj(CCtsp_branchobj* b), + CCtsp_print_branchhistory(CCtsp_lp* lp); /****************************************************************************/ /* */ @@ -600,22 +602,22 @@ void CCtsp_init_branchobj(CCtsp_branchobj*b), CCtsp_free_branchobj(CCtsp_brancho /* */ /****************************************************************************/ -int CCtsp_init_cliquehash(CCtsp_lpcuts*cuts, int size), - CCtsp_register_clique(CCtsp_lpcuts*cuts, CCtsp_lpclique*c); +int CCtsp_init_cliquehash(CCtsp_lpcuts* cuts, int size), + CCtsp_register_clique(CCtsp_lpcuts* cuts, CCtsp_lpclique* c); unsigned int CCtsp_hashclique(CCtsp_lpclique* c); -void CCtsp_free_cliquehash(CCtsp_lpcuts*cuts), CCtsp_unregister_clique(CCtsp_lpcuts*cuts, int c), - CCtsp_clique_eq(CCtsp_lpclique*c, CCtsp_lpclique*d, int*yes_no); +void CCtsp_free_cliquehash(CCtsp_lpcuts* cuts), CCtsp_unregister_clique(CCtsp_lpcuts* cuts, int c), + CCtsp_clique_eq(CCtsp_lpclique* c, CCtsp_lpclique* d, int* yes_no); -int CCtsp_init_dominohash(CCtsp_lpcuts*cuts, int size), - CCtsp_register_domino(CCtsp_lpcuts*cuts, CCtsp_lpdomino*c); +int CCtsp_init_dominohash(CCtsp_lpcuts* cuts, int size), + CCtsp_register_domino(CCtsp_lpcuts* cuts, CCtsp_lpdomino* c); unsigned int CCtsp_hashdomino(CCtsp_lpdomino* d); -void CCtsp_free_dominohash(CCtsp_lpcuts*cuts), - CCtsp_domino_eq(CCtsp_lpdomino*c, CCtsp_lpdomino*d, int*yes_no), - CCtsp_unregister_domino(CCtsp_lpcuts*cuts, int c); +void CCtsp_free_dominohash(CCtsp_lpcuts* cuts), + CCtsp_domino_eq(CCtsp_lpdomino* c, CCtsp_lpdomino* d, int* yes_no), + CCtsp_unregister_domino(CCtsp_lpcuts* cuts, int c); /****************************************************************************/ /* */ @@ -633,41 +635,41 @@ typedef struct CCtsp_cutinfo { #ifdef __cplusplus extern "C" { #endif -int CCtsp_clique_to_array(CCtsp_lpclique*c, int**ar, int*count), - CCtsp_clique_delta(CCtsp_lpgraph*g, double*x, CCtsp_lpclique*c, double*delta), - CCtsp_copy_lpcut_in(CCtsp_lpcut_in*c, CCtsp_lpcut_in*nw), - CCtsp_segment_to_subtour(CCtsp_lpcut_in**cut, int a, int b, int ncount), - CCtsp_array_to_subtour(CCtsp_lpcut_in**cut, int*ar, int acount, int ncount), - CCtsp_array_to_lpclique(int*ar, int acount, CCtsp_lpclique*cliq), - CCtsp_seglist_to_lpclique(int nseg, int*list, CCtsp_lpclique*cliq), - CCtsp_shrunk_set_to_lpclique(int cnt, int*set, int*wset, CC_SRKexpinfo*expand, CCtsp_lpclique*cliq), - CCtsp_add_nodes_to_lpclique(CCtsp_lpclique*cin, CCtsp_lpclique*cout, int addcount, int*adda), - CCtsp_delete_nodes_from_lpclique(CCtsp_lpclique*cin, CCtsp_lpclique*cout, int delcount, int*del), - CCtsp_lpcut_to_lpcut_in(CCtsp_lpcuts*cuts, CCtsp_lpcut*c, CCtsp_lpcut_in*nw), - CCtsp_copy_lpclique(CCtsp_lpclique*c, CCtsp_lpclique*nw), - CCtsp_copy_lpdomino(CCtsp_lpdomino*c, CCtsp_lpdomino*nw), - CCtsp_create_lpcliques(CCtsp_lpcut_in*c, int cliquecount), CCtsp_max_node(CCtsp_lpcut_in*c), - CCtsp_build_dp_cut(CCtsp_lpcut_in**cut, int ndomino, int*Acount, int**A, int*Bcount, int**B, - int handlecount, int*handle); +int CCtsp_clique_to_array(CCtsp_lpclique* c, int** ar, int* count), + CCtsp_clique_delta(CCtsp_lpgraph* g, double* x, CCtsp_lpclique* c, double* delta), + CCtsp_copy_lpcut_in(CCtsp_lpcut_in* c, CCtsp_lpcut_in* nw), + CCtsp_segment_to_subtour(CCtsp_lpcut_in** cut, int a, int b, int ncount), + CCtsp_array_to_subtour(CCtsp_lpcut_in** cut, int* ar, int acount, int ncount), + CCtsp_array_to_lpclique(int* ar, int acount, CCtsp_lpclique* cliq), + CCtsp_seglist_to_lpclique(int nseg, int* list, CCtsp_lpclique* cliq), + CCtsp_shrunk_set_to_lpclique(int cnt, int* set, int* wset, CC_SRKexpinfo* expand, CCtsp_lpclique* cliq), + CCtsp_add_nodes_to_lpclique(CCtsp_lpclique* cin, CCtsp_lpclique* cout, int addcount, int* adda), + CCtsp_delete_nodes_from_lpclique(CCtsp_lpclique* cin, CCtsp_lpclique* cout, int delcount, int* del), + CCtsp_lpcut_to_lpcut_in(CCtsp_lpcuts* cuts, CCtsp_lpcut* c, CCtsp_lpcut_in* nw), + CCtsp_copy_lpclique(CCtsp_lpclique* c, CCtsp_lpclique* nw), + CCtsp_copy_lpdomino(CCtsp_lpdomino* c, CCtsp_lpdomino* nw), + CCtsp_create_lpcliques(CCtsp_lpcut_in* c, int cliquecount), CCtsp_max_node(CCtsp_lpcut_in* c), + CCtsp_build_dp_cut(CCtsp_lpcut_in** cut, int ndomino, int* Acount, int** A, int* Bcount, int** B, + int handlecount, int* handle); #ifdef __cplusplus } #endif -void CCtsp_mark_clique(CCtsp_lpclique*c, int*marks, int marker), - CCtsp_mark_domino(CCtsp_lpdomino*c, int*marks, int marker), - CCtsp_mark_clique_and_neighbors(CCtsp_lpgraph*g, CCtsp_lpclique*c, int*marks, int marker), - CCtsp_mark_domino_and_neighbors(CCtsp_lpgraph*g, CCtsp_lpdomino*c, int*marks, int marker), - CCtsp_mark_clique_and_neighbors_double(CCtsp_lpgraph*g, CCtsp_lpclique*c, double*marks, double marker), - CCtsp_mark_cut(CCtsp_lpcut_in*c, int*marks, int marker), - CCtsp_mark_cut_and_neighbors(CCtsp_lpgraph*g, CCtsp_lpcut_in*c, int*marks, int marker), - CCtsp_is_clique_marked(CCtsp_lpclique*c, int*marks, int marker, int*yes_no), - CCtsp_clique_count(CCtsp_lpclique*c, int*count), - CCtsp_clique_marked_count(CCtsp_lpclique*c, int*marks, int marker, int*count), - CCtsp_init_lpcut_in(CCtsp_lpcut_in*c), CCtsp_init_lpcut(CCtsp_lpcut*c), - CCtsp_init_lpclique(CCtsp_lpclique*c), CCtsp_init_lpdomino(CCtsp_lpdomino*c), - CCtsp_print_lpcut_in(CCtsp_lpcut_in*c), CCtsp_print_lpclique(CCtsp_lpclique*c), - CCtsp_print_lpdomino(CCtsp_lpdomino*d), - CCtsp_lpclique_compare(CCtsp_lpclique*a, CCtsp_lpclique*b, int*diff); +void CCtsp_mark_clique(CCtsp_lpclique* c, int* marks, int marker), + CCtsp_mark_domino(CCtsp_lpdomino* c, int* marks, int marker), + CCtsp_mark_clique_and_neighbors(CCtsp_lpgraph* g, CCtsp_lpclique* c, int* marks, int marker), + CCtsp_mark_domino_and_neighbors(CCtsp_lpgraph* g, CCtsp_lpdomino* c, int* marks, int marker), + CCtsp_mark_clique_and_neighbors_double(CCtsp_lpgraph* g, CCtsp_lpclique* c, double* marks, double marker), + CCtsp_mark_cut(CCtsp_lpcut_in* c, int* marks, int marker), + CCtsp_mark_cut_and_neighbors(CCtsp_lpgraph* g, CCtsp_lpcut_in* c, int* marks, int marker), + CCtsp_is_clique_marked(CCtsp_lpclique* c, int* marks, int marker, int* yes_no), + CCtsp_clique_count(CCtsp_lpclique* c, int* count), + CCtsp_clique_marked_count(CCtsp_lpclique* c, int* marks, int marker, int* count), + CCtsp_init_lpcut_in(CCtsp_lpcut_in* c), CCtsp_init_lpcut(CCtsp_lpcut* c), + CCtsp_init_lpclique(CCtsp_lpclique* c), CCtsp_init_lpdomino(CCtsp_lpdomino* c), + CCtsp_print_lpcut_in(CCtsp_lpcut_in* c), CCtsp_print_lpclique(CCtsp_lpclique* c), + CCtsp_print_lpdomino(CCtsp_lpdomino* d), + CCtsp_lpclique_compare(CCtsp_lpclique* a, CCtsp_lpclique* b, int* diff); /****************************************************************************/ /* */ @@ -675,27 +677,27 @@ void CCtsp_mark_clique(CCtsp_lpclique*c, int*marks, int marker), /* */ /****************************************************************************/ -int CCtsp_cutting_multiple_loop(CCtsp_lp*lp, CCtsp_cutselect*sel, int savelp, int maxlocal, int update_tol, - int silent, CCrandstate*rstate), - CCtsp_cutting_loop(CCtsp_lp*lp, CCtsp_cutselect*sel, int savelp, int silent, CCrandstate*rstate), - CCtsp_subtour_loop(CCtsp_lp*lp, int silent, CCrandstate*rstate), - CCtsp_blossom_loop(CCtsp_lp*lp, int silent, CCrandstate*rstate), - CCtsp_subtour_and_blossom_loop(CCtsp_lp*lp, int silent, CCrandstate*rstate), - CCtsp_pricing_loop(CCtsp_lp*lp, double*bnd, int silent, CCrandstate*rstate), - CCtsp_call_x_heuristic(CCtsp_lp*lp, double*val, int*outcyc, int silent, CCrandstate*rstate), - CCtsp_bb_cutting(char*probname, int probnum, int prob_newnum, int ncount, CCdatagroup*dat, int*ptour, - double*upbound, CCtsp_lpcuts*pool, CCtsp_cutselect*sel, double*val, int*prune, - int*foundtour, int*besttour, int level, int silent, CCrandstate*rstate), - CCtsp_cutselect_set_tols(CCtsp_cutselect*s, CCtsp_lp*lp, int level, int silent); - -void CCtsp_init_cutselect(CCtsp_cutselect*s), CCtsp_cutselect_dominos(CCtsp_cutselect*s, int domsel), - CCtsp_cutselect_tighten(CCtsp_cutselect*s, int tighten), - CCtsp_cutselect_chunksize(CCtsp_cutselect*s, int chunksize), - CCtsp_cutselect_filecuts(CCtsp_cutselect*s, char*fname), - CCtsp_cutselect_remotepool(CCtsp_cutselect*s, char*cutbossname), - CCtsp_cutselect_domboss(CCtsp_cutselect*s, char*dombossname), - CCtsp_init_tentative_cutselect(CCtsp_cutselect*s), CCtsp_init_simple_cutselect(CCtsp_cutselect*s), - CCtsp_init_fast_cutselect(CCtsp_cutselect*s); +int CCtsp_cutting_multiple_loop(CCtsp_lp* lp, CCtsp_cutselect* sel, int savelp, int maxlocal, int update_tol, + int silent, CCrandstate* rstate), + CCtsp_cutting_loop(CCtsp_lp* lp, CCtsp_cutselect* sel, int savelp, int silent, CCrandstate* rstate), + CCtsp_subtour_loop(CCtsp_lp* lp, int silent, CCrandstate* rstate), + CCtsp_blossom_loop(CCtsp_lp* lp, int silent, CCrandstate* rstate), + CCtsp_subtour_and_blossom_loop(CCtsp_lp* lp, int silent, CCrandstate* rstate), + CCtsp_pricing_loop(CCtsp_lp* lp, double* bnd, int silent, CCrandstate* rstate), + CCtsp_call_x_heuristic(CCtsp_lp* lp, double* val, int* outcyc, int silent, CCrandstate* rstate), + CCtsp_bb_cutting(char* probname, int probnum, int prob_newnum, int ncount, CCdatagroup* dat, int* ptour, + double* upbound, CCtsp_lpcuts* pool, CCtsp_cutselect* sel, double* val, int* prune, + int* foundtour, int* besttour, int level, int silent, CCrandstate* rstate), + CCtsp_cutselect_set_tols(CCtsp_cutselect* s, CCtsp_lp* lp, int level, int silent); + +void CCtsp_init_cutselect(CCtsp_cutselect* s), CCtsp_cutselect_dominos(CCtsp_cutselect* s, int domsel), + CCtsp_cutselect_tighten(CCtsp_cutselect* s, int tighten), + CCtsp_cutselect_chunksize(CCtsp_cutselect* s, int chunksize), + CCtsp_cutselect_filecuts(CCtsp_cutselect* s, char* fname), + CCtsp_cutselect_remotepool(CCtsp_cutselect* s, char* cutbossname), + CCtsp_cutselect_domboss(CCtsp_cutselect* s, char* dombossname), + CCtsp_init_tentative_cutselect(CCtsp_cutselect* s), CCtsp_init_simple_cutselect(CCtsp_cutselect* s), + CCtsp_init_fast_cutselect(CCtsp_cutselect* s); /****************************************************************************/ /* */ @@ -703,45 +705,46 @@ void CCtsp_init_cutselect(CCtsp_cutselect*s), CCtsp_cutselect_dominos(CCtsp_cuts /* */ /****************************************************************************/ -int CCtsp_connect_cuts(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x), - CCtsp_segment_cuts(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x), - CCtsp_shrink_subtours(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x), - CCtsp_exact_subtours(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x), - CCtsp_tighten_lp(CCtsp_lpcuts*cuts, CCtsp_tighten_info*stats, CCtsp_lpcut_in**cutsout, int*cutcount, - int ncount, int ecount, int*elist, double*x, double testtol, int maxcuts, double*viol, - CCrandstate*rstate), - CCtsp_double_decker_lp(CCtsp_lpcuts*cuts, CCtsp_tighten_info*stats, CCtsp_lpcut_in**cutsout, int*cutcount, - int ncount, int ecount, int*elist, double*x, double testtol, int maxcuts, - double*viol, CCrandstate*rstate), - CCtsp_cliquetree_lp(CCtsp_lpcuts*cuts, CCtsp_tighten_info*stats, CCtsp_lpcut_in**cutsout, int*cutcount, - int ncount, int ecount, int*elist, double*x, double testtol, int maxcuts, double*viol, - CCrandstate*rstate), - CCtsp_star_lp(CCtsp_lpcuts*cuts, CCtsp_tighten_info*stats, CCtsp_lpcut_in**cutsout, int*cutcount, - int ncount, int ecount, int*elist, double*x, double testtol, int maxcuts, double*viol, - CCrandstate*rstate), - CCtsp_handling_lp(CCtsp_lpcuts*cuts, CCtsp_tighten_info*stats, CCtsp_lpcut_in**cutsout, int*cutcount, - int ncount, int ecount, int*elist, double*x, double testtol, int maxcuts, double*viol, - CCrandstate*rstate), - CCtsp_teething_lp(CCtsp_lpcuts*cuts, CCtsp_tighten_info*stats, CCtsp_lpcut_in**cutsout, int*cutcount, - int ncount, int ecount, int*elist, double*x, double testtol, int maxcuts, double*viol, - CCrandstate*rstate), - CCtsp_domino_trial(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x, - CCrandstate*rstate), - CCtsp_file_cuts(char*cutfile, CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int*tour), - CCtsp_file_cuts_write(const char*cutfile, CCtsp_lpcuts*cuts, int*tour), - CCtsp_test_pure_comb(int ncount, CCtsp_lpcut_in*c, int*yes_no, int*handle), - CCtsp_test_pseudocomb(int ncount, CCtsp_lpcut_in*c, int handle, int*yes_no), - CCtsp_test_teeth_disjoint(int ncount, CCtsp_lpcut_in*c, int handle, int*yes_no), - CCtsp_find_pure_handle(int ncount, CCtsp_lpcut_in*c, int*handle), - CCtsp_truncate_cutlist(CCtsp_lpcut_in**cuts, int ncount, int ecount, int*elist, double*x, int maxcuts, - CCrandstate*rstate), - CCtsp_buildcut_begin(CCtsp_cutinfo*cuts, int init_cliquecount), - CCtsp_buildcut_addclique(CCtsp_cutinfo*cuts, int*arr, int size), - CCtsp_buildcut_finish(CCtsp_cutinfo*cuts, int rhs), - CCtsp_new_domino(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x, - const char*bossname), - CCtsp_shrink_domino(CCtsp_lpcut_in**cuts, int*cutcount, int ncount, int ecount, int*elist, double*x, - int quickshrink, int rand_minor, CCrandstate*rstate, const char*bossname); +int CCtsp_connect_cuts(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x), + CCtsp_segment_cuts(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x), + CCtsp_shrink_subtours(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, + double* x), + CCtsp_exact_subtours(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x), + CCtsp_tighten_lp(CCtsp_lpcuts* cuts, CCtsp_tighten_info* stats, CCtsp_lpcut_in** cutsout, int* cutcount, + int ncount, int ecount, int* elist, double* x, double testtol, int maxcuts, double* viol, + CCrandstate* rstate), + CCtsp_double_decker_lp(CCtsp_lpcuts* cuts, CCtsp_tighten_info* stats, CCtsp_lpcut_in** cutsout, + int* cutcount, int ncount, int ecount, int* elist, double* x, double testtol, + int maxcuts, double* viol, CCrandstate* rstate), + CCtsp_cliquetree_lp(CCtsp_lpcuts* cuts, CCtsp_tighten_info* stats, CCtsp_lpcut_in** cutsout, + int* cutcount, int ncount, int ecount, int* elist, double* x, double testtol, + int maxcuts, double* viol, CCrandstate* rstate), + CCtsp_star_lp(CCtsp_lpcuts* cuts, CCtsp_tighten_info* stats, CCtsp_lpcut_in** cutsout, int* cutcount, + int ncount, int ecount, int* elist, double* x, double testtol, int maxcuts, double* viol, + CCrandstate* rstate), + CCtsp_handling_lp(CCtsp_lpcuts* cuts, CCtsp_tighten_info* stats, CCtsp_lpcut_in** cutsout, int* cutcount, + int ncount, int ecount, int* elist, double* x, double testtol, int maxcuts, + double* viol, CCrandstate* rstate), + CCtsp_teething_lp(CCtsp_lpcuts* cuts, CCtsp_tighten_info* stats, CCtsp_lpcut_in** cutsout, int* cutcount, + int ncount, int ecount, int* elist, double* x, double testtol, int maxcuts, + double* viol, CCrandstate* rstate), + CCtsp_domino_trial(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x, + CCrandstate* rstate), + CCtsp_file_cuts(char* cutfile, CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int* tour), + CCtsp_file_cuts_write(const char* cutfile, CCtsp_lpcuts* cuts, int* tour), + CCtsp_test_pure_comb(int ncount, CCtsp_lpcut_in* c, int* yes_no, int* handle), + CCtsp_test_pseudocomb(int ncount, CCtsp_lpcut_in* c, int handle, int* yes_no), + CCtsp_test_teeth_disjoint(int ncount, CCtsp_lpcut_in* c, int handle, int* yes_no), + CCtsp_find_pure_handle(int ncount, CCtsp_lpcut_in* c, int* handle), + CCtsp_truncate_cutlist(CCtsp_lpcut_in** cuts, int ncount, int ecount, int* elist, double* x, int maxcuts, + CCrandstate* rstate), + CCtsp_buildcut_begin(CCtsp_cutinfo* cuts, int init_cliquecount), + CCtsp_buildcut_addclique(CCtsp_cutinfo* cuts, int* arr, int size), + CCtsp_buildcut_finish(CCtsp_cutinfo* cuts, int rhs), + CCtsp_new_domino(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x, + const char* bossname), + CCtsp_shrink_domino(CCtsp_lpcut_in** cuts, int* cutcount, int ncount, int ecount, int* elist, double* x, + int quickshrink, int rand_minor, CCrandstate* rstate, const char* bossname); void CCtsp_buildcut_abort(CCtsp_cutinfo* cuts); @@ -759,50 +762,52 @@ void CCtsp_buildcut_abort(CCtsp_cutinfo* cuts); #ifdef __cplusplus extern "C" { #endif -int CCtsp_init_cutpool(int*ncount, char*poolfilename, CCtsp_lpcuts**pool), - CCtsp_write_cutpool(int ncount, const char*poolfilename, CCtsp_lpcuts*pool), - CCtsp_search_cutpool(CCtsp_lpcuts*pool, CCtsp_lpcut_in**cuts, int*cutcount, double*maxviol, int ncount, - int ecount, int*elist, double*x, int nthreads, CCrandstate*rstate), - CCtsp_search_remotepool(char*remotehost, unsigned short remoteport, CCtsp_lpcut_in**cuts, int*cutcount, - double*maxviol, int ncount, int ecount, int*elist, double*x), - CCtsp_read_cuts(CC_SFILE*f, int*ncount, CCtsp_lpcuts*cuts, int readmods, int buildhash), - CCtsp_read_lpcut_in(CC_SFILE*f, CCtsp_lpcut_in*c, int ncount), - CCtsp_read_lpclique(CC_SFILE*f, CCtsp_lpclique*c, int ncount), - CCtsp_read_lpdomino(CC_SFILE*f, CCtsp_lpdomino*d, int ncount), - CCtsp_write_cuts(CC_SFILE*f, int ncount, CCtsp_lpcuts*cuts, int writemods), - CCtsp_send_newcuts(int ncount, CCtsp_lpcuts*pool, char*remotehost, unsigned short remoteport), - CCtsp_write_lpcut_in(CC_SFILE*f, CCtsp_lpcut_in*c, int ncount), - CCtsp_write_lpcut(CC_SFILE*f, CCtsp_lpcuts*cuts, CCtsp_lpcut*c, int ncount), - CCtsp_write_lpclique(CC_SFILE*f, CCtsp_lpclique*c, int ncount), - CCtsp_write_lpdomino(CC_SFILE*f, CCtsp_lpdomino*c, int ncount), - CCtsp_copy_cuts(CC_SFILE*f, CC_SFILE*t, int copymods), - CCtsp_search_cutpool_cliques(CCtsp_lpcuts*pool, CCtsp_lpclique**cliques, int*cliquecount, int ncount, - int ecount, int*elist, double*x, double maxdelta, int maxcliques, - double**cliquevals, CCrandstate*rstate), - CCtsp_branch_cutpool_cliques(CCtsp_lpcuts*pool, CCtsp_lpclique**cliques, int*cliquecount, int ncount, - int ecount, int*elist, double*x, int nwant, double**cliquevals, int silent), - CCtsp_get_clique_prices(CCtsp_lpcuts*pool, int**p_cliquenums, double**p_cliquevals, double mindelta, - double maxdelta, int*p_cliquecount, int ncount, int ecount, int*elist, double*x), - CCtsp_get_clique(CCtsp_lpcuts*pool, int cliquenum, CCtsp_lpclique**p_clique), - CCtsp_add_to_cutpool(CCtsp_lpcuts*pool, CCtsp_lpcuts*cuts, CCtsp_lpcut*c), - CCtsp_add_to_dominopool(CCtsp_lpcuts*pool, CCtsp_lpcuts*cuts, CCtsp_lpcut*c), - CCtsp_add_to_cutpool_lpcut_in(CCtsp_lpcuts*pool, CCtsp_lpcut_in*cut), - CCtsp_display_cutpool(CCtsp_lpcuts*pool), - CCtsp_price_cuts(CCtsp_lpcuts*pool, int ncount, int ecount, int*elist, double*x, double*cutval), - CCtsp_price_cuts_threaded(CCtsp_lpcuts*pool, int ncount, int ecount, int*elist, double*x, double*cutval, - int numthreads), - CCtsp_register_cliques(CCtsp_lpcuts*cuts, CCtsp_lpcut_in*c, CCtsp_lpcut*nw), - CCtsp_register_dominos(CCtsp_lpcuts*cuts, CCtsp_lpcut_in*c, CCtsp_lpcut*nw), - CCtsp_add_cut_to_cutlist(CCtsp_lpcuts*cuts, CCtsp_lpcut*c); +int CCtsp_init_cutpool(int* ncount, char* poolfilename, CCtsp_lpcuts** pool), + CCtsp_write_cutpool(int ncount, const char* poolfilename, CCtsp_lpcuts* pool), + CCtsp_search_cutpool(CCtsp_lpcuts* pool, CCtsp_lpcut_in** cuts, int* cutcount, double* maxviol, + int ncount, int ecount, int* elist, double* x, int nthreads, CCrandstate* rstate), + CCtsp_search_remotepool(char* remotehost, unsigned short remoteport, CCtsp_lpcut_in** cuts, int* cutcount, + double* maxviol, int ncount, int ecount, int* elist, double* x), + CCtsp_read_cuts(CC_SFILE* f, int* ncount, CCtsp_lpcuts* cuts, int readmods, int buildhash), + CCtsp_read_lpcut_in(CC_SFILE* f, CCtsp_lpcut_in* c, int ncount), + CCtsp_read_lpclique(CC_SFILE* f, CCtsp_lpclique* c, int ncount), + CCtsp_read_lpdomino(CC_SFILE* f, CCtsp_lpdomino* d, int ncount), + CCtsp_write_cuts(CC_SFILE* f, int ncount, CCtsp_lpcuts* cuts, int writemods), + CCtsp_send_newcuts(int ncount, CCtsp_lpcuts* pool, char* remotehost, unsigned short remoteport), + CCtsp_write_lpcut_in(CC_SFILE* f, CCtsp_lpcut_in* c, int ncount), + CCtsp_write_lpcut(CC_SFILE* f, CCtsp_lpcuts* cuts, CCtsp_lpcut* c, int ncount), + CCtsp_write_lpclique(CC_SFILE* f, CCtsp_lpclique* c, int ncount), + CCtsp_write_lpdomino(CC_SFILE* f, CCtsp_lpdomino* c, int ncount), + CCtsp_copy_cuts(CC_SFILE* f, CC_SFILE* t, int copymods), + CCtsp_search_cutpool_cliques(CCtsp_lpcuts* pool, CCtsp_lpclique** cliques, int* cliquecount, int ncount, + int ecount, int* elist, double* x, double maxdelta, int maxcliques, + double** cliquevals, CCrandstate* rstate), + CCtsp_branch_cutpool_cliques(CCtsp_lpcuts* pool, CCtsp_lpclique** cliques, int* cliquecount, int ncount, + int ecount, int* elist, double* x, int nwant, double** cliquevals, + int silent), + CCtsp_get_clique_prices(CCtsp_lpcuts* pool, int** p_cliquenums, double** p_cliquevals, double mindelta, + double maxdelta, int* p_cliquecount, int ncount, int ecount, int* elist, + double* x), + CCtsp_get_clique(CCtsp_lpcuts* pool, int cliquenum, CCtsp_lpclique** p_clique), + CCtsp_add_to_cutpool(CCtsp_lpcuts* pool, CCtsp_lpcuts* cuts, CCtsp_lpcut* c), + CCtsp_add_to_dominopool(CCtsp_lpcuts* pool, CCtsp_lpcuts* cuts, CCtsp_lpcut* c), + CCtsp_add_to_cutpool_lpcut_in(CCtsp_lpcuts* pool, CCtsp_lpcut_in* cut), + CCtsp_display_cutpool(CCtsp_lpcuts* pool), + CCtsp_price_cuts(CCtsp_lpcuts* pool, int ncount, int ecount, int* elist, double* x, double* cutval), + CCtsp_price_cuts_threaded(CCtsp_lpcuts* pool, int ncount, int ecount, int* elist, double* x, + double* cutval, int numthreads), + CCtsp_register_cliques(CCtsp_lpcuts* cuts, CCtsp_lpcut_in* c, CCtsp_lpcut* nw), + CCtsp_register_dominos(CCtsp_lpcuts* cuts, CCtsp_lpcut_in* c, CCtsp_lpcut* nw), + CCtsp_add_cut_to_cutlist(CCtsp_lpcuts* cuts, CCtsp_lpcut* c); #ifdef __cplusplus } #endif -void CCtsp_free_cutpool(CCtsp_lpcuts**pool), CCtsp_free_lpcut_in(CCtsp_lpcut_in*c), - CCtsp_free_lpclique(CCtsp_lpclique*c), CCtsp_free_lpdomino(CCtsp_lpdomino*c), - CCtsp_unregister_cliques(CCtsp_lpcuts*cuts, CCtsp_lpcut*c), - CCtsp_unregister_dominos(CCtsp_lpcuts*cuts, CCtsp_lpcut*c), - CCtsp_delete_cut_from_cutlist(CCtsp_lpcuts*cuts, int ind); +void CCtsp_free_cutpool(CCtsp_lpcuts** pool), CCtsp_free_lpcut_in(CCtsp_lpcut_in* c), + CCtsp_free_lpclique(CCtsp_lpclique* c), CCtsp_free_lpdomino(CCtsp_lpdomino* c), + CCtsp_unregister_cliques(CCtsp_lpcuts* cuts, CCtsp_lpcut* c), + CCtsp_unregister_dominos(CCtsp_lpcuts* cuts, CCtsp_lpcut* c), + CCtsp_delete_cut_from_cutlist(CCtsp_lpcuts* cuts, int ind); /****************************************************************************/ /* */ @@ -810,12 +815,14 @@ void CCtsp_free_cutpool(CCtsp_lpcuts**pool), CCtsp_free_lpcut_in(CCtsp_lpcut_in* /* */ /****************************************************************************/ -int CCtsp_test_pure_double_decker(CCtsp_lpcut_in*c, int*yes_no, int*handle1, int*handle2), - CCtsp_comb_to_double_decker(CCtsp_lpgraph*g, CC_GCgraph*h, double*x, CCtsp_lpcut_in*c, CCtsp_lpcut_in**d), - CCtsp_comb_to_star(CCtsp_lpgraph*g, CC_GCgraph*h, double*x, CCtsp_lpcut_in*c, CCtsp_lpcut_in**d), - CCtsp_test_pure_simple_cliquetree(int ncount, CCtsp_lpcut_in*c, int*yes_no), - CCtsp_comb_to_cliquetree(CCtsp_lpgraph*g, CC_GCgraph*h, double*x, CCtsp_lpcut_in*c, CCtsp_lpcut_in**d), - CCtsp_comb_handling(CCtsp_lpgraph*g, CC_GCgraph*h, double*x, CCtsp_lpcut_in*c, CCtsp_lpcut_in**d); +int CCtsp_test_pure_double_decker(CCtsp_lpcut_in* c, int* yes_no, int* handle1, int* handle2), + CCtsp_comb_to_double_decker(CCtsp_lpgraph* g, CC_GCgraph* h, double* x, CCtsp_lpcut_in* c, + CCtsp_lpcut_in** d), + CCtsp_comb_to_star(CCtsp_lpgraph* g, CC_GCgraph* h, double* x, CCtsp_lpcut_in* c, CCtsp_lpcut_in** d), + CCtsp_test_pure_simple_cliquetree(int ncount, CCtsp_lpcut_in* c, int* yes_no), + CCtsp_comb_to_cliquetree(CCtsp_lpgraph* g, CC_GCgraph* h, double* x, CCtsp_lpcut_in* c, + CCtsp_lpcut_in** d), + CCtsp_comb_handling(CCtsp_lpgraph* g, CC_GCgraph* h, double* x, CCtsp_lpcut_in* c, CCtsp_lpcut_in** d); /****************************************************************************/ /* */ @@ -823,10 +830,10 @@ int CCtsp_test_pure_double_decker(CCtsp_lpcut_in*c, int*yes_no, int*handle1, int /* */ /****************************************************************************/ -int CCtsp_exact_price(CCtsp_lp*lp, CCbigguy*bound, int complete_price, int phase1, int silent), - CCtsp_edge_elimination(CCtsp_lp*lp, int eliminate_sparse, int silent), CCtsp_exact_dual(CCtsp_lp*lp), - CCtsp_verify_infeasible_lp(CCtsp_lp*lp, int*yesno, int silent), - CCtsp_verify_lp_prune(CCtsp_lp*lp, int*yesno, int silent); +int CCtsp_exact_price(CCtsp_lp* lp, CCbigguy* bound, int complete_price, int phase1, int silent), + CCtsp_edge_elimination(CCtsp_lp* lp, int eliminate_sparse, int silent), CCtsp_exact_dual(CCtsp_lp* lp), + CCtsp_verify_infeasible_lp(CCtsp_lp* lp, int* yesno, int silent), + CCtsp_verify_lp_prune(CCtsp_lp* lp, int* yesno, int silent); void CCtsp_free_bigdual(CCtsp_bigdual** d); @@ -842,13 +849,13 @@ void CCtsp_free_bigdual(CCtsp_bigdual** d); void CCtsp_free_edgegenerator(CCtsp_edgegenerator* eg); -int CCtsp_init_edgegenerator(CCtsp_edgegenerator*eg, int ncount, CCdatagroup*dg, CCtsp_genadj*adj, - int nneighbors, int silent, CCrandstate*rstate), - CCtsp_reset_edgegenerator(CCtsp_edgegenerator*eg, double*node_piest, int silent), - CCtsp_generate_edges(CCtsp_edgegenerator*eg, int nwant, int*pngot, int*elist, int*elen, int*finished, - int silent, CCrandstate*rstate), - CCtsp_edgelist_to_genadj(int ncount, int ecount, int*elist, int*elen, CCtsp_genadj**adj, - CCtsp_genadjobj**adjobjspace); +int CCtsp_init_edgegenerator(CCtsp_edgegenerator* eg, int ncount, CCdatagroup* dg, CCtsp_genadj* adj, + int nneighbors, int silent, CCrandstate* rstate), + CCtsp_reset_edgegenerator(CCtsp_edgegenerator* eg, double* node_piest, int silent), + CCtsp_generate_edges(CCtsp_edgegenerator* eg, int nwant, int* pngot, int* elist, int* elen, int* finished, + int silent, CCrandstate* rstate), + CCtsp_edgelist_to_genadj(int ncount, int ecount, int* elist, int* elen, CCtsp_genadj** adj, + CCtsp_genadjobj** adjobjspace); /****************************************************************************/ /* */ @@ -921,52 +928,52 @@ typedef struct CCtsp_PROB_FILE { } offsets; } CCtsp_PROB_FILE; -CCtsp_PROB_FILE *CCtsp_prob_read(char*f, int n), *CCtsp_prob_read_name(char*f), - *CCtsp_prob_write(char*f, int n), *CCtsp_prob_write_name(char*fname); - -int CCtsp_prob_file_delete(char*f, int n), CCtsp_prob_getname(CCtsp_PROB_FILE*p, char*name), - CCtsp_prob_getid(CCtsp_PROB_FILE*p, int*id), CCtsp_prob_getparent(CCtsp_PROB_FILE*p, int*parent), - CCtsp_prob_getub(CCtsp_PROB_FILE*p, double*ub), CCtsp_prob_getlb(CCtsp_PROB_FILE*p, double*lb), - CCtsp_prob_getexactlb(CCtsp_PROB_FILE*p, CCbigguy*lb), - CCtsp_prob_getnnodes(CCtsp_PROB_FILE*p, int*nnodes), - CCtsp_prob_getchildren(CCtsp_PROB_FILE*p, int*child0, int*child1), - CCtsp_prob_getreal(CCtsp_PROB_FILE*p, int*real), - CCtsp_prob_getprocessed(CCtsp_PROB_FILE*p, int*processed), - CCtsp_prob_getinfeasible(CCtsp_PROB_FILE*p, int*infeasible), - CCtsp_prob_gettour(CCtsp_PROB_FILE*p, int ncount, int**tour, int silent), - CCtsp_prob_getedges(CCtsp_PROB_FILE*p, int ncount, int*nedges, int**elist, int**elen, int silent), - CCtsp_prob_getcuts(CCtsp_PROB_FILE*p, int*ncount, CCtsp_lpcuts*cuts, int silent), - CCtsp_prob_getwarmstart(CCtsp_PROB_FILE*p, CClp_warmstart**w, int silent), - CCtsp_prob_getfulladj(CCtsp_PROB_FILE*p, int ncount, int*fullcount, CCtsp_genadj**adj, - CCtsp_genadjobj**adjspace, int silent), - CCtsp_prob_getfixed(CCtsp_PROB_FILE*p, int ncount, int*ecount, int**elist, int silent), - CCtsp_prob_getexactdual(CCtsp_PROB_FILE*p, int ncount, CCtsp_bigdual**d, int silent), - CCtsp_prob_gethistory(CCtsp_PROB_FILE*p, int*depth, CCtsp_branchobj**history, int silent), - CCtsp_prob_rclose(CCtsp_PROB_FILE*p), CCtsp_prob_putname(CCtsp_PROB_FILE*p, char*name), - CCtsp_prob_putid(CCtsp_PROB_FILE*p, int id), CCtsp_prob_putparent(CCtsp_PROB_FILE*p, int parent), - CCtsp_prob_putub(CCtsp_PROB_FILE*p, double ub), CCtsp_prob_putlb(CCtsp_PROB_FILE*p, double lb), - CCtsp_prob_putexactlb(CCtsp_PROB_FILE*p, CCbigguy lb), - CCtsp_prob_putnnodes(CCtsp_PROB_FILE*p, int nnodes), - CCtsp_prob_putchildren(CCtsp_PROB_FILE*p, int child0, int child1), - CCtsp_prob_putreal(CCtsp_PROB_FILE*p, int real), - CCtsp_prob_putprocessed(CCtsp_PROB_FILE*p, int processed), - CCtsp_prob_putinfeasible(CCtsp_PROB_FILE*p, int infeasible), - CCtsp_prob_puttour(CCtsp_PROB_FILE*p, int ncount, int*tour), - CCtsp_prob_putedges(CCtsp_PROB_FILE*p, int ncount, int nedges, int*elist, int*elen), - CCtsp_prob_putcuts(CCtsp_PROB_FILE*p, int ncount, CCtsp_lpcuts*cuts), - CCtsp_prob_putwarmstart(CCtsp_PROB_FILE*p, CClp_warmstart*w), - CCtsp_prob_putfulladj(CCtsp_PROB_FILE*p, int ncount, int fullcount, CCtsp_genadj*adj), - CCtsp_prob_putfixed(CCtsp_PROB_FILE*p, int ncount, int ecount, int*elist), - CCtsp_prob_putexactdual(CCtsp_PROB_FILE*p, CCtsp_bigdual*d, int ncount), - CCtsp_prob_puthistory(CCtsp_PROB_FILE*p, int depth, CCtsp_branchobj*history), - CCtsp_prob_wclose(CCtsp_PROB_FILE*p), - CCtsp_prob_copy_section(CCtsp_PROB_FILE*f, CCtsp_PROB_FILE*t, char section, int silent); +CCtsp_PROB_FILE *CCtsp_prob_read(char* f, int n), *CCtsp_prob_read_name(char* f), + *CCtsp_prob_write(char* f, int n), *CCtsp_prob_write_name(char* fname); + +int CCtsp_prob_file_delete(char* f, int n), CCtsp_prob_getname(CCtsp_PROB_FILE* p, char* name), + CCtsp_prob_getid(CCtsp_PROB_FILE* p, int* id), CCtsp_prob_getparent(CCtsp_PROB_FILE* p, int* parent), + CCtsp_prob_getub(CCtsp_PROB_FILE* p, double* ub), CCtsp_prob_getlb(CCtsp_PROB_FILE* p, double* lb), + CCtsp_prob_getexactlb(CCtsp_PROB_FILE* p, CCbigguy* lb), + CCtsp_prob_getnnodes(CCtsp_PROB_FILE* p, int* nnodes), + CCtsp_prob_getchildren(CCtsp_PROB_FILE* p, int* child0, int* child1), + CCtsp_prob_getreal(CCtsp_PROB_FILE* p, int* real), + CCtsp_prob_getprocessed(CCtsp_PROB_FILE* p, int* processed), + CCtsp_prob_getinfeasible(CCtsp_PROB_FILE* p, int* infeasible), + CCtsp_prob_gettour(CCtsp_PROB_FILE* p, int ncount, int** tour, int silent), + CCtsp_prob_getedges(CCtsp_PROB_FILE* p, int ncount, int* nedges, int** elist, int** elen, int silent), + CCtsp_prob_getcuts(CCtsp_PROB_FILE* p, int* ncount, CCtsp_lpcuts* cuts, int silent), + CCtsp_prob_getwarmstart(CCtsp_PROB_FILE* p, CClp_warmstart** w, int silent), + CCtsp_prob_getfulladj(CCtsp_PROB_FILE* p, int ncount, int* fullcount, CCtsp_genadj** adj, + CCtsp_genadjobj** adjspace, int silent), + CCtsp_prob_getfixed(CCtsp_PROB_FILE* p, int ncount, int* ecount, int** elist, int silent), + CCtsp_prob_getexactdual(CCtsp_PROB_FILE* p, int ncount, CCtsp_bigdual** d, int silent), + CCtsp_prob_gethistory(CCtsp_PROB_FILE* p, int* depth, CCtsp_branchobj** history, int silent), + CCtsp_prob_rclose(CCtsp_PROB_FILE* p), CCtsp_prob_putname(CCtsp_PROB_FILE* p, char* name), + CCtsp_prob_putid(CCtsp_PROB_FILE* p, int id), CCtsp_prob_putparent(CCtsp_PROB_FILE* p, int parent), + CCtsp_prob_putub(CCtsp_PROB_FILE* p, double ub), CCtsp_prob_putlb(CCtsp_PROB_FILE* p, double lb), + CCtsp_prob_putexactlb(CCtsp_PROB_FILE* p, CCbigguy lb), + CCtsp_prob_putnnodes(CCtsp_PROB_FILE* p, int nnodes), + CCtsp_prob_putchildren(CCtsp_PROB_FILE* p, int child0, int child1), + CCtsp_prob_putreal(CCtsp_PROB_FILE* p, int real), + CCtsp_prob_putprocessed(CCtsp_PROB_FILE* p, int processed), + CCtsp_prob_putinfeasible(CCtsp_PROB_FILE* p, int infeasible), + CCtsp_prob_puttour(CCtsp_PROB_FILE* p, int ncount, int* tour), + CCtsp_prob_putedges(CCtsp_PROB_FILE* p, int ncount, int nedges, int* elist, int* elen), + CCtsp_prob_putcuts(CCtsp_PROB_FILE* p, int ncount, CCtsp_lpcuts* cuts), + CCtsp_prob_putwarmstart(CCtsp_PROB_FILE* p, CClp_warmstart* w), + CCtsp_prob_putfulladj(CCtsp_PROB_FILE* p, int ncount, int fullcount, CCtsp_genadj* adj), + CCtsp_prob_putfixed(CCtsp_PROB_FILE* p, int ncount, int ecount, int* elist), + CCtsp_prob_putexactdual(CCtsp_PROB_FILE* p, CCtsp_bigdual* d, int ncount), + CCtsp_prob_puthistory(CCtsp_PROB_FILE* p, int depth, CCtsp_branchobj* history), + CCtsp_prob_wclose(CCtsp_PROB_FILE* p), + CCtsp_prob_copy_section(CCtsp_PROB_FILE* f, CCtsp_PROB_FILE* t, char section, int silent); char* CCtsp_problabel(const char* probloc); #ifdef CC_NETREADY -CCtsp_PROB_FILE *CCtsp_prob_read_remote(char*hname, char*pname, int n), - *CCtsp_prob_write_remote(char*hname, char*pname, int n), *CCtsp_prob_server(CC_SFILE*s); +CCtsp_PROB_FILE *CCtsp_prob_read_remote(char* hname, char* pname, int n), + *CCtsp_prob_write_remote(char* hname, char* pname, int n), *CCtsp_prob_server(CC_SFILE* s); int CCtsp_prob_delete_remote(char* hname, char* pname, int n); #endif /* CC_NETREADY */ @@ -1002,16 +1009,16 @@ int CCtsp_qsparsify(CCtsp_qsparsegroup** pqs, struct CCtsp_lpgraph* g, int* pnzl #ifdef __cplusplus extern "C" { #endif -int CCtsp_copy_skeleton(CCtsp_skeleton*old, CCtsp_skeleton*nw), - CCtsp_construct_skeleton(CCtsp_lpcut_in*c, int nodecount), - CCtsp_read_skeleton(CC_SFILE*f, CCtsp_skeleton*skel, int ncount), - CCtsp_write_skeleton(CC_SFILE*f, CCtsp_skeleton*skel, int ncount); +int CCtsp_copy_skeleton(CCtsp_skeleton* old, CCtsp_skeleton* nw), + CCtsp_construct_skeleton(CCtsp_lpcut_in* c, int nodecount), + CCtsp_read_skeleton(CC_SFILE* f, CCtsp_skeleton* skel, int ncount), + CCtsp_write_skeleton(CC_SFILE* f, CCtsp_skeleton* skel, int ncount); #ifdef __cplusplus } #endif -void CCtsp_init_skeleton(CCtsp_skeleton*skel), CCtsp_free_skeleton(CCtsp_skeleton*skel), - CCtsp_compare_skeletons(CCtsp_skeleton*a, CCtsp_skeleton*b, int*diff); +void CCtsp_init_skeleton(CCtsp_skeleton* skel), CCtsp_free_skeleton(CCtsp_skeleton* skel), + CCtsp_compare_skeletons(CCtsp_skeleton* a, CCtsp_skeleton* b, int* diff); /****************************************************************************/ /* */ @@ -1019,9 +1026,9 @@ void CCtsp_init_skeleton(CCtsp_skeleton*skel), CCtsp_free_skeleton(CCtsp_skeleto /* */ /****************************************************************************/ -int CCtsp_teething(CCtsp_lpgraph*g, double*x, CCtsp_lpcut_in*cut, CCtsp_lpcut_in**newcut), - CCtsp_teething_list(CCtsp_lpgraph*g, double*x, CCtsp_lpclique*handle, int nbig, CCtsp_lpclique**bigteeth, - CCtsp_lpcut_in**newcut); +int CCtsp_teething(CCtsp_lpgraph* g, double* x, CCtsp_lpcut_in* cut, CCtsp_lpcut_in** newcut), + CCtsp_teething_list(CCtsp_lpgraph* g, double* x, CCtsp_lpclique* handle, int nbig, + CCtsp_lpclique** bigteeth, CCtsp_lpcut_in** newcut); /****************************************************************************/ /* */ @@ -1029,12 +1036,12 @@ int CCtsp_teething(CCtsp_lpgraph*g, double*x, CCtsp_lpcut_in*cut, CCtsp_lpcut_in /* */ /****************************************************************************/ -int CCtsp_tighten_lpcut_in(CCtsp_lpgraph*g, CCtsp_lpcut_in*c, double*x, CCtsp_lpcut_in*d, - CCtsp_tighten_info*stats, double*pimprove), - CCtsp_tighten_lpcut(CCtsp_lpgraph*g, CCtsp_lpclique*cliques, CCtsp_lpcut*c, double*x, CCtsp_lpcut_in*d, - CCtsp_tighten_info*stats, double*pimprove); +int CCtsp_tighten_lpcut_in(CCtsp_lpgraph* g, CCtsp_lpcut_in* c, double* x, CCtsp_lpcut_in* d, + CCtsp_tighten_info* stats, double* pimprove), + CCtsp_tighten_lpcut(CCtsp_lpgraph* g, CCtsp_lpclique* cliques, CCtsp_lpcut* c, double* x, + CCtsp_lpcut_in* d, CCtsp_tighten_info* stats, double* pimprove); -void CCtsp_init_tighten_info(CCtsp_tighten_info*stats), CCtsp_print_tighten_info(CCtsp_tighten_info*stats); +void CCtsp_init_tighten_info(CCtsp_tighten_info* stats), CCtsp_print_tighten_info(CCtsp_tighten_info* stats); /****************************************************************************/ /* */ @@ -1042,46 +1049,48 @@ void CCtsp_init_tighten_info(CCtsp_tighten_info*stats), CCtsp_print_tighten_info /* */ /****************************************************************************/ -int CCtsp_bb_init_lp(CCtsp_lp**lp, char*probname, int probnum, int ncount, CCdatagroup*dat, int*ptour, - double initial_ub, CCtsp_lpcuts*pool, int silent, CCrandstate*rstate), - CCtsp_init_lp(CCtsp_lp**lp, char*probname, int probnum, char*probfilename, int ncount, CCdatagroup*dat, - int ecount, int*elist, int*elen, int excount, int*exlist, int*exlen, int exvalid, int*ptour, - double initial_ub, CCtsp_lpcuts*pool, CCtsp_lpcuts*dominopool, int silent, - CCrandstate*rstate), - CCtsp_build_lpgraph(CCtsp_lpgraph*g, int ncount, int ecount, int*elist, int*elen), - CCtsp_build_lpadj(CCtsp_lpgraph*g, int estart, int eend), - CCtsp_find_edge(CCtsp_lpgraph*g, int from, int to), CCtsp_inspect_full_edges(CCtsp_lp*lp), - CCtsp_resparsify_lp(CCtsp_lp*lp, int silent), - CCtsp_lpcut_nzlist(CCtsp_lpgraph*g, CCtsp_lpcut*c, CCtsp_lpclique*cliques, CCtsp_lpdomino*dominos, +int CCtsp_bb_init_lp(CCtsp_lp** lp, char* probname, int probnum, int ncount, CCdatagroup* dat, int* ptour, + double initial_ub, CCtsp_lpcuts* pool, int silent, CCrandstate* rstate), + CCtsp_init_lp(CCtsp_lp** lp, char* probname, int probnum, char* probfilename, int ncount, + CCdatagroup* dat, int ecount, int* elist, int* elen, int excount, int* exlist, int* exlen, + int exvalid, int* ptour, double initial_ub, CCtsp_lpcuts* pool, CCtsp_lpcuts* dominopool, + int silent, CCrandstate* rstate), + CCtsp_build_lpgraph(CCtsp_lpgraph* g, int ncount, int ecount, int* elist, int* elen), + CCtsp_build_lpadj(CCtsp_lpgraph* g, int estart, int eend), + CCtsp_find_edge(CCtsp_lpgraph* g, int from, int to), CCtsp_inspect_full_edges(CCtsp_lp* lp), + CCtsp_resparsify_lp(CCtsp_lp* lp, int silent), + CCtsp_lpcut_nzlist(CCtsp_lpgraph* g, CCtsp_lpcut* c, CCtsp_lpclique* cliques, CCtsp_lpdomino* dominos, int do_mods), - CCtsp_update_result(CCtsp_lp*lp), - CCtsp_get_lp_result(CCtsp_lp*lp, double*lb, double*ub, int*ecount, int**elist, double**x, double**rc, - double**node_pi, double**cut_pi), - CCtsp_lpcut_in_nzlist(CCtsp_lpgraph*g, CCtsp_lpcut_in*c), - CCtsp_process_cuts(CCtsp_lp*lp, int*pnadded, int tighten, int silent, CCrandstate*rstate), - CCtsp_infeas_recover(CCtsp_lp*lp, int silent, CCrandstate*rstate), - CCtsp_add_cut(CCtsp_lp*lp, CCtsp_lpcut_in*d, CCtsp_lprow*cr), - CCtsp_add_nzlist_to_lp(CCtsp_lp*lp, int nzlist, int rhs, char sense, CCtsp_lprow*cr), - CCtsp_addbad_variables(CCtsp_lp*lp, CCtsp_edgegenerator*eg, double*ppenalty, int*pnadded, double rcthresh, - double maxpenalty, int phase1, int*feasible, int silent, CCrandstate*rstate), - CCtsp_eliminate_variables(CCtsp_lp*lp, int eliminate_sparse, int silent), - CCtsp_add_vars_to_lp(CCtsp_lp*lp, CCtsp_predge*prlist, int n), - CCtsp_add_multiple_rows(CCtsp_lp*lp, CCtsp_lprow*cr), CCtsp_delete_cut(CCtsp_lp*lp, int i), - CCtsp_reduced_cost_nearest(CCtsp_lp*lp, int k, int*ecount, int**elist, double**elen, int sparse), - CCtsp_write_probfile_sav(CCtsp_lp*lp), CCtsp_write_probfile_id(CCtsp_lp*lp), - CCtsp_write_probroot_id(char*probloc, CCtsp_lp*lp), CCtsp_write_probleaf_id(CCtsp_lp*lp), - CCtsp_read_probfile(CCtsp_lp*lp, char*fname, char*probloc, int*ncount, int silent), - CCtsp_read_probfile_id(CCtsp_lp*lp, char*fname, int id, int*ncount, int silent), - CCtsp_dump_rc_nearest(CCtsp_lp*lp, int k, char*fname, int sparse), CCtsp_dump_x(CCtsp_lp*lp, char*fname), - CCtsp_depot_valid(CCtsp_lp*lp, int ndepot, int*yesno); + CCtsp_update_result(CCtsp_lp* lp), + CCtsp_get_lp_result(CCtsp_lp* lp, double* lb, double* ub, int* ecount, int** elist, double** x, + double** rc, double** node_pi, double** cut_pi), + CCtsp_lpcut_in_nzlist(CCtsp_lpgraph* g, CCtsp_lpcut_in* c), + CCtsp_process_cuts(CCtsp_lp* lp, int* pnadded, int tighten, int silent, CCrandstate* rstate), + CCtsp_infeas_recover(CCtsp_lp* lp, int silent, CCrandstate* rstate), + CCtsp_add_cut(CCtsp_lp* lp, CCtsp_lpcut_in* d, CCtsp_lprow* cr), + CCtsp_add_nzlist_to_lp(CCtsp_lp* lp, int nzlist, int rhs, char sense, CCtsp_lprow* cr), + CCtsp_addbad_variables(CCtsp_lp* lp, CCtsp_edgegenerator* eg, double* ppenalty, int* pnadded, + double rcthresh, double maxpenalty, int phase1, int* feasible, int silent, + CCrandstate* rstate), + CCtsp_eliminate_variables(CCtsp_lp* lp, int eliminate_sparse, int silent), + CCtsp_add_vars_to_lp(CCtsp_lp* lp, CCtsp_predge* prlist, int n), + CCtsp_add_multiple_rows(CCtsp_lp* lp, CCtsp_lprow* cr), CCtsp_delete_cut(CCtsp_lp* lp, int i), + CCtsp_reduced_cost_nearest(CCtsp_lp* lp, int k, int* ecount, int** elist, double** elen, int sparse), + CCtsp_write_probfile_sav(CCtsp_lp* lp), CCtsp_write_probfile_id(CCtsp_lp* lp), + CCtsp_write_probroot_id(char* probloc, CCtsp_lp* lp), CCtsp_write_probleaf_id(CCtsp_lp* lp), + CCtsp_read_probfile(CCtsp_lp* lp, char* fname, char* probloc, int* ncount, int silent), + CCtsp_read_probfile_id(CCtsp_lp* lp, char* fname, int id, int* ncount, int silent), + CCtsp_dump_rc_nearest(CCtsp_lp* lp, int k, char* fname, int sparse), + CCtsp_dump_x(CCtsp_lp* lp, char* fname), CCtsp_depot_valid(CCtsp_lp* lp, int ndepot, int* yesno); double CCtsp_cutprice(CCtsp_lpgraph* g, CCtsp_lpcut_in* c, double* x); -void CCtsp_init_tsp_lpcuts_struct(CCtsp_lpcuts*c), CCtsp_init_tsp_lp_struct(CCtsp_lp*lp), - CCtsp_free_tsp_lp_struct(CCtsp_lp**lp), CCtsp_init_lpgraph_struct(CCtsp_lpgraph*g), - CCtsp_free_lpgraph(CCtsp_lpgraph*g), CCtsp_init_statistics(CCtsp_statistics*stats), - CCtsp_output_statistics(CCtsp_statistics*stats), CCtsp_add_cuts_to_queue(CCtsp_lp*lp, CCtsp_lpcut_in**c), - CCtsp_init_lprow(CCtsp_lprow*cr), CCtsp_free_lprow(CCtsp_lprow*cr); +void CCtsp_init_tsp_lpcuts_struct(CCtsp_lpcuts* c), CCtsp_init_tsp_lp_struct(CCtsp_lp* lp), + CCtsp_free_tsp_lp_struct(CCtsp_lp** lp), CCtsp_init_lpgraph_struct(CCtsp_lpgraph* g), + CCtsp_free_lpgraph(CCtsp_lpgraph* g), CCtsp_init_statistics(CCtsp_statistics* stats), + CCtsp_output_statistics(CCtsp_statistics* stats), + CCtsp_add_cuts_to_queue(CCtsp_lp* lp, CCtsp_lpcut_in** c), CCtsp_init_lprow(CCtsp_lprow* cr), + CCtsp_free_lprow(CCtsp_lprow* cr); /****************************************************************************/ /* */ @@ -1089,12 +1098,12 @@ void CCtsp_init_tsp_lpcuts_struct(CCtsp_lpcuts*c), CCtsp_init_tsp_lp_struct(CCts /* */ /****************************************************************************/ -int CCtsp_solve_sparse(int ncount, int ecount, int*elist, int*elen, int*in_tour, int*out_tour, double*in_val, - double*optval, int*success, int*foundtour, char*name, double*timebound, - int*hit_timebound, int silent, CCrandstate*rstate), - CCtsp_solve_dat(int ncount, CCdatagroup*indat, int*in_tour, int*out_tour, double*in_val, double*optval, - int*success, int*foundtour, char*name, double*timebound, int*hit_timebound, int silent, - CCrandstate*rstate); +int CCtsp_solve_sparse(int ncount, int ecount, int* elist, int* elen, int* in_tour, int* out_tour, + double* in_val, double* optval, int* success, int* foundtour, char* name, + double* timebound, int* hit_timebound, int silent, CCrandstate* rstate), + CCtsp_solve_dat(int ncount, CCdatagroup* indat, int* in_tour, int* out_tour, double* in_val, + double* optval, int* success, int* foundtour, char* name, double* timebound, + int* hit_timebound, int silent, CCrandstate* rstate); /****************************************************************************/ /* */ @@ -1102,10 +1111,10 @@ int CCtsp_solve_sparse(int ncount, int ecount, int*elist, int*elen, int*in_tour, /* */ /****************************************************************************/ -int CCtsp_x_greedy_tour(CCdatagroup*dat, int ncount, int ecount, int*elist, double*x, int*cyc, double*val, - int silent), - CCtsp_x_greedy_tour_lk(CCdatagroup*dat, int ncount, int ecount, int*elist, double*x, int*cyc, double*val, - int silent, CCrandstate*rstate); +int CCtsp_x_greedy_tour(CCdatagroup* dat, int ncount, int ecount, int* elist, double* x, int* cyc, + double* val, int silent), + CCtsp_x_greedy_tour_lk(CCdatagroup* dat, int ncount, int ecount, int* elist, double* x, int* cyc, + double* val, int silent, CCrandstate* rstate); /****************************************************************************/ /* */ diff --git a/tsp/inc/util.h b/tsp/inc/util.h index 1086424..538e34a 100644 --- a/tsp/inc/util.h +++ b/tsp/inc/util.h @@ -318,12 +318,12 @@ typedef struct CCptrworld { CCbigchunkptr* chunklist; } CCptrworld; -void *CCutil_allocrus(size_t size), *CCutil_reallocrus(void*ptr, size_t size), CCutil_freerus(void*p), - CCutil_bigchunkfree(CCbigchunkptr*bp), CCptrworld_init(CCptrworld*world), - CCptrworld_add(CCptrworld*world), CCptrworld_delete(CCptrworld*world); +void *CCutil_allocrus(size_t size), *CCutil_reallocrus(void* ptr, size_t size), CCutil_freerus(void* p), + CCutil_bigchunkfree(CCbigchunkptr* bp), CCptrworld_init(CCptrworld* world), + CCptrworld_add(CCptrworld* world), CCptrworld_delete(CCptrworld* world); -int CCutil_reallocrus_scale(void**pptr, int*pnnum, int count, double scale, size_t size), - CCutil_reallocrus_count(void**pptr, int count, size_t size); +int CCutil_reallocrus_scale(void** pptr, int* pnnum, int count, double scale, size_t size), + CCutil_reallocrus_count(void** pptr, int count, size_t size); CCbigchunkptr* CCutil_bigchunkalloc(void); @@ -351,11 +351,12 @@ typedef struct CCdheap { int size; } CCdheap; -void CCutil_dheap_free(CCdheap*h), CCutil_dheap_delete(CCdheap*h, int i), - CCutil_dheap_changekey(CCdheap*h, int i, double newkey); +void CCutil_dheap_free(CCdheap* h), CCutil_dheap_delete(CCdheap* h, int i), + CCutil_dheap_changekey(CCdheap* h, int i, double newkey); -int CCutil_dheap_init(CCdheap*h, int k), CCutil_dheap_resize(CCdheap*h, int newsize), - CCutil_dheap_findmin(CCdheap*h), CCutil_dheap_deletemin(CCdheap*h), CCutil_dheap_insert(CCdheap*h, int i); +int CCutil_dheap_init(CCdheap* h, int k), CCutil_dheap_resize(CCdheap* h, int newsize), + CCutil_dheap_findmin(CCdheap* h), CCutil_dheap_deletemin(CCdheap* h), + CCutil_dheap_insert(CCdheap* h, int i); /****************************************************************************/ /* */ @@ -387,13 +388,13 @@ typedef struct CCelistlw { double* weight; } CCelistlw; -void CCelist_init(CCelist*elist), CCelistl_init(CCelistl*elist), CCelistw_init(CCelistw*elist), - CCelistlw_init(CCelistlw*elist), CCelist_free(CCelist*elist), CCelistl_free(CCelistl*elist), - CCelistw_free(CCelistw*elist), CCelistlw_free(CCelistlw*elist); +void CCelist_init(CCelist* elist), CCelistl_init(CCelistl* elist), CCelistw_init(CCelistw* elist), + CCelistlw_init(CCelistlw* elist), CCelist_free(CCelist* elist), CCelistl_free(CCelistl* elist), + CCelistw_free(CCelistw* elist), CCelistlw_free(CCelistlw* elist); -int CCelist_alloc(CCelist*elist, int ecount), CCelistl_alloc(CCelistl*elist, int ecount), - CCelistw_alloc(CCelistw*elist, int ecount), CCelistlw_alloc(CCelistlw*elist, int ecount), - CCutil_edge_to_cycle(int ncount, int*elist, int*yesno, int*cyc); +int CCelist_alloc(CCelist* elist, int ecount), CCelistl_alloc(CCelistl* elist, int ecount), + CCelistw_alloc(CCelistw* elist, int ecount), CCelistlw_alloc(CCelistlw* elist, int ecount), + CCutil_edge_to_cycle(int ncount, int* elist, int* yesno, int* cyc); /****************************************************************************/ /* */ @@ -460,9 +461,9 @@ int CCutil_dat_edgelen(int i, int j, CCdatagroup* dat); int CCutil_dat_setnorm(CCdatagroup* dat, int norm); -void CCutil_dat_getnorm(CCdatagroup*dat, int*norm), - CCutil_dsjrand_init(CCdatagroup*dat, int maxdist, int seed), CCutil_init_datagroup(CCdatagroup*dat), - CCutil_freedatagroup(CCdatagroup*dat); +void CCutil_dat_getnorm(CCdatagroup* dat, int* norm), + CCutil_dsjrand_init(CCdatagroup* dat, int maxdist, int seed), CCutil_init_datagroup(CCdatagroup* dat), + CCutil_freedatagroup(CCdatagroup* dat); #define CC_KD_NORM_TYPE 128 /* Kdtrees work */ #define CC_X_NORM_TYPE 256 /* Old nearest works */ @@ -532,14 +533,14 @@ typedef struct CCutil_edgehash { unsigned int mult; } CCutil_edgehash; -int CCutil_edgehash_init(CCutil_edgehash*h, int size), - CCutil_edgehash_add(CCutil_edgehash*h, int end1, int end2, int val), - CCutil_edgehash_set(CCutil_edgehash*h, int end1, int end2, int val), - CCutil_edgehash_del(CCutil_edgehash*h, int end1, int end2), - CCutil_edgehash_find(CCutil_edgehash*h, int end1, int end2, int*val), - CCutil_edgehash_getall(CCutil_edgehash*h, int*ecount, int**elist, int**elen); +int CCutil_edgehash_init(CCutil_edgehash* h, int size), + CCutil_edgehash_add(CCutil_edgehash* h, int end1, int end2, int val), + CCutil_edgehash_set(CCutil_edgehash* h, int end1, int end2, int val), + CCutil_edgehash_del(CCutil_edgehash* h, int end1, int end2), + CCutil_edgehash_find(CCutil_edgehash* h, int end1, int end2, int* val), + CCutil_edgehash_getall(CCutil_edgehash* h, int* ecount, int** elist, int** elen); -void CCutil_edgehash_delall(CCutil_edgehash*h), CCutil_edgehash_free(CCutil_edgehash*h); +void CCutil_edgehash_delall(CCutil_edgehash* h), CCutil_edgehash_free(CCutil_edgehash* h); /****************************************************************************/ /* */ @@ -584,25 +585,25 @@ typedef struct CCgenhash_iter { struct CCgenhash_elem* next; } CCgenhash_iter; -int CCutil_genhash_init(CCgenhash*h, int size, int (*hcmp)(void*key1, void*key2, void*u_data), - unsigned int (*hfunc)(void*key, void*u_data), void*u_data, double maxdensity, +int CCutil_genhash_init(CCgenhash* h, int size, int (*hcmp)(void* key1, void* key2, void* u_data), + unsigned int (*hfunc)(void* key, void* u_data), void* u_data, double maxdensity, double lowdensity), - CCutil_genhash_insert(CCgenhash*h, void*key, void*data), - CCutil_genhash_insert_h(CCgenhash*h, unsigned int hashval, void*key, void*data), - CCutil_genhash_replace(CCgenhash*h, void*key, void*data), - CCutil_genhash_replace_h(CCgenhash*h, unsigned int hashval, void*key, void*data), - CCutil_genhash_delete(CCgenhash*h, void*key), - CCutil_genhash_delete_h(CCgenhash*h, unsigned int hashval, void*key); + CCutil_genhash_insert(CCgenhash* h, void* key, void* data), + CCutil_genhash_insert_h(CCgenhash* h, unsigned int hashval, void* key, void* data), + CCutil_genhash_replace(CCgenhash* h, void* key, void* data), + CCutil_genhash_replace_h(CCgenhash* h, unsigned int hashval, void* key, void* data), + CCutil_genhash_delete(CCgenhash* h, void* key), + CCutil_genhash_delete_h(CCgenhash* h, unsigned int hashval, void* key); unsigned int CCutil_genhash_hash(CCgenhash* h, void* key); -void *CCutil_genhash_lookup(CCgenhash*h, void*key), - *CCutil_genhash_lookup_h(CCgenhash*h, unsigned int hashval, void*key), - *CCutil_genhash_next(CCgenhash*h, CCgenhash_iter*iter, void**key, int*keysize); +void *CCutil_genhash_lookup(CCgenhash* h, void* key), + *CCutil_genhash_lookup_h(CCgenhash* h, unsigned int hashval, void* key), + *CCutil_genhash_next(CCgenhash* h, CCgenhash_iter* iter, void** key, int* keysize); -void CCutil_genhash_u_data(CCgenhash*h, void*u_data), - CCutil_genhash_free(CCgenhash*h, void (*freefunc)(void*key, void*data, void*u_data)), - CCutil_genhash_start(CCgenhash*h, CCgenhash_iter*iter); +void CCutil_genhash_u_data(CCgenhash* h, void* u_data), + CCutil_genhash_free(CCgenhash* h, void (*freefunc)(void* key, void* data, void* u_data)), + CCutil_genhash_start(CCgenhash* h, CCgenhash_iter* iter); /****************************************************************************/ /* */ @@ -615,39 +616,41 @@ void CCutil_genhash_u_data(CCgenhash*h, void*u_data), void CCutil_cycle_len(int ncount, CCdatagroup* dat, int* cycle, double* len); -int CCutil_getdata(char*datname, int binary_in, int innorm, int*ncount, CCdatagroup*dat, int gridsize, - int allow_dups, CCrandstate*rstate), - CCutil_writedata(char*datname, int binary_out, int ncount, CCdatagroup*dat), - CCutil_putmaster(char*mastername, int ncount, CCdatagroup*dat, int*perm), - CCutil_writemaster(CC_SFILE*out, int ncount, CCdatagroup*dat, int*perm), - CCutil_getmaster(char*mastername, int*ncount, CCdatagroup*dat, int**perm), - CCutil_readmaster(CC_SFILE*in, int*ncount, CCdatagroup*dat, int**perm), - CCutil_getnodeweights(char*weightname, int ncount, int weight_limit, double**wcoord, CCrandstate*rstate), - CCutil_gettsplib(char*datname, int*ncount, CCdatagroup*dat), - CCutil_writetsplib(const char*fname, int ncount, CCdatagroup*dat), - CCutil_datagroup_perm(int ncount, CCdatagroup*dat, int*perm), - CCutil_copy_datagroup(int ncount, CCdatagroup*indat, CCdatagroup*outdat), - CCutil_getedgelist(int ncount, char*fname, int*ecount, int**elist, int**elen, int binary_in), - CCutil_getedgelist_n(int*ncount, char*fname, int*ecount, int**elist, int**elen, int binary_in), - CCutil_genedgelist(int ncount, int ecount, int**elist, int**elen, CCdatagroup*dat, int maxlen, - CCrandstate*rstate), - CCutil_getcycle_tsplib(int ncount, char*cyclename, int*outcycle), - CCutil_getcycle_edgelist(int ncount, char*cyclename, int*outcycle, int binary_in), - CCutil_getcycle(int ncount, char*cyclename, int*outcycle, int binary_in), - CCutil_getedges_double(int*ncount, char*fname, int*ecount, int**elist, double**elen, int binary_in), - CCutil_writeedges(int ncount, char*outedgename, int ecount, int*elist, CCdatagroup*dat, int binary_out), - CCutil_writecycle_edgelist(int ncount, char*outedgename, int*cycle, CCdatagroup*dat, int binary_out), - CCutil_writecycle(int ncount, char*outcyclename, int*cycle, int binary_out), - CCutil_writeedges_int(int ncount, char*outedgename, int ecount, int*elist, int*elen, int binary_out), - CCutil_writeedges_double(int ncount, char*outedgename, int ecount, int*elist, double*elen, +int CCutil_getdata(char* datname, int binary_in, int innorm, int* ncount, CCdatagroup* dat, int gridsize, + int allow_dups, CCrandstate* rstate), + CCutil_writedata(char* datname, int binary_out, int ncount, CCdatagroup* dat), + CCutil_putmaster(char* mastername, int ncount, CCdatagroup* dat, int* perm), + CCutil_writemaster(CC_SFILE* out, int ncount, CCdatagroup* dat, int* perm), + CCutil_getmaster(char* mastername, int* ncount, CCdatagroup* dat, int** perm), + CCutil_readmaster(CC_SFILE* in, int* ncount, CCdatagroup* dat, int** perm), + CCutil_getnodeweights(char* weightname, int ncount, int weight_limit, double** wcoord, + CCrandstate* rstate), + CCutil_gettsplib(char* datname, int* ncount, CCdatagroup* dat), + CCutil_writetsplib(const char* fname, int ncount, CCdatagroup* dat), + CCutil_datagroup_perm(int ncount, CCdatagroup* dat, int* perm), + CCutil_copy_datagroup(int ncount, CCdatagroup* indat, CCdatagroup* outdat), + CCutil_getedgelist(int ncount, char* fname, int* ecount, int** elist, int** elen, int binary_in), + CCutil_getedgelist_n(int* ncount, char* fname, int* ecount, int** elist, int** elen, int binary_in), + CCutil_genedgelist(int ncount, int ecount, int** elist, int** elen, CCdatagroup* dat, int maxlen, + CCrandstate* rstate), + CCutil_getcycle_tsplib(int ncount, char* cyclename, int* outcycle), + CCutil_getcycle_edgelist(int ncount, char* cyclename, int* outcycle, int binary_in), + CCutil_getcycle(int ncount, char* cyclename, int* outcycle, int binary_in), + CCutil_getedges_double(int* ncount, char* fname, int* ecount, int** elist, double** elen, int binary_in), + CCutil_writeedges(int ncount, char* outedgename, int ecount, int* elist, CCdatagroup* dat, + int binary_out), + CCutil_writecycle_edgelist(int ncount, char* outedgename, int* cycle, CCdatagroup* dat, int binary_out), + CCutil_writecycle(int ncount, char* outcyclename, int* cycle, int binary_out), + CCutil_writeedges_int(int ncount, char* outedgename, int ecount, int* elist, int* elen, int binary_out), + CCutil_writeedges_double(int ncount, char* outedgename, int ecount, int* elist, double* elen, int binary_out), - CCutil_tri2dat(int ncount, int*elen, CCdatagroup*dat), - CCutil_graph2dat_matrix(int ncount, int ecount, int*elist, int*elen, int defaultlen, CCdatagroup*dat), - CCutil_graph2dat_sparse(int ncount, int ecount, int*elist, int*elen, int defaultlen, CCdatagroup*dat), - CCutil_get_sparse_dat_edges(int ncount, CCdatagroup*dat, int*ecount, int**elist, int**elen), - CCutil_sparse_strip_edges(CCdatagroup*dat, int in_ecount, int*in_elist, int*in_elen, int*ecount, - int**elist, int**elen), - CCutil_sparse_real_tour(int ncount, CCdatagroup*dat, int*cyc, int*yesno); + CCutil_tri2dat(int ncount, int* elen, CCdatagroup* dat), + CCutil_graph2dat_matrix(int ncount, int ecount, int* elist, int* elen, int defaultlen, CCdatagroup* dat), + CCutil_graph2dat_sparse(int ncount, int ecount, int* elist, int* elen, int defaultlen, CCdatagroup* dat), + CCutil_get_sparse_dat_edges(int ncount, CCdatagroup* dat, int* ecount, int** elist, int** elen), + CCutil_sparse_strip_edges(CCdatagroup* dat, int in_ecount, int* in_elist, int* in_elen, int* ecount, + int** elist, int** elen), + CCutil_sparse_real_tour(int ncount, CCdatagroup* dat, int* cyc, int* yesno); /****************************************************************************/ /* */ @@ -660,18 +663,18 @@ typedef struct CCpriority { union CCpri_data { void* data; int next; - } * pri_info; + }* pri_info; int space; int freelist; } CCpriority; -void CCutil_priority_free(CCpriority*pri), CCutil_priority_delete(CCpriority*pri, int handle), - CCutil_priority_changekey(CCpriority*pri, int handle, double newkey), - *CCutil_priority_findmin(CCpriority*pri, double*keyval), - *CCutil_priority_deletemin(CCpriority*pri, double*keyval); +void CCutil_priority_free(CCpriority* pri), CCutil_priority_delete(CCpriority* pri, int handle), + CCutil_priority_changekey(CCpriority* pri, int handle, double newkey), + *CCutil_priority_findmin(CCpriority* pri, double* keyval), + *CCutil_priority_deletemin(CCpriority* pri, double* keyval); -int CCutil_priority_init(CCpriority*pri, int k), - CCutil_priority_insert(CCpriority*pri, void*data, double keyval); +int CCutil_priority_init(CCpriority* pri, int k), + CCutil_priority_insert(CCpriority* pri, void* data, double keyval); /****************************************************************************/ /* */ @@ -682,21 +685,21 @@ int CCutil_priority_init(CCpriority*pri, int k), CC_SFILE *CCutil_sopen(const char* f, const char* s), *CCutil_sdopen(int d, const char* s); -int CCutil_swrite(CC_SFILE*f, char*buf, int size), CCutil_swrite_bits(CC_SFILE*f, int x, int xbits), - CCutil_swrite_ubits(CC_SFILE*f, unsigned int x, int xbits), CCutil_swrite_char(CC_SFILE*f, char x), - CCutil_swrite_string(CC_SFILE*f, const char*x), CCutil_swrite_short(CC_SFILE*f, short x), - CCutil_swrite_ushort(CC_SFILE*f, unsigned short x), CCutil_swrite_int(CC_SFILE*f, int x), - CCutil_swrite_uint(CC_SFILE*f, unsigned int x), CCutil_swrite_double(CC_SFILE*f, double x), - CCutil_sread(CC_SFILE*f, char*buf, int size), CCutil_sread_bits(CC_SFILE*f, int*x, int xbits), - CCutil_sread_ubits(CC_SFILE*f, unsigned int*x, int xbits), CCutil_sread_char(CC_SFILE*f, char*x), - CCutil_sread_string(CC_SFILE*f, char*x, int maxlen), CCutil_sread_short(CC_SFILE*f, short*x), - CCutil_sread_ushort(CC_SFILE*f, unsigned short*x), CCutil_sread_short_r(CC_SFILE*f, short*x), - CCutil_sread_int(CC_SFILE*f, int*x), CCutil_sread_uint(CC_SFILE*f, unsigned int*x), - CCutil_sread_int_r(CC_SFILE*f, int*x), CCutil_sread_double(CC_SFILE*f, double*x), - CCutil_sread_double_r(CC_SFILE*f, double*x), CCutil_sflush(CC_SFILE*f), CCutil_stell(CC_SFILE*f), - CCutil_sseek(CC_SFILE*f, int offset), CCutil_srewind(CC_SFILE*f), CCutil_sclose(CC_SFILE*f), - CCutil_sbits(unsigned int x), CCutil_sdelete_file(const char*fname), - CCutil_sdelete_file_backup(const char*fname); +int CCutil_swrite(CC_SFILE* f, char* buf, int size), CCutil_swrite_bits(CC_SFILE* f, int x, int xbits), + CCutil_swrite_ubits(CC_SFILE* f, unsigned int x, int xbits), CCutil_swrite_char(CC_SFILE* f, char x), + CCutil_swrite_string(CC_SFILE* f, const char* x), CCutil_swrite_short(CC_SFILE* f, short x), + CCutil_swrite_ushort(CC_SFILE* f, unsigned short x), CCutil_swrite_int(CC_SFILE* f, int x), + CCutil_swrite_uint(CC_SFILE* f, unsigned int x), CCutil_swrite_double(CC_SFILE* f, double x), + CCutil_sread(CC_SFILE* f, char* buf, int size), CCutil_sread_bits(CC_SFILE* f, int* x, int xbits), + CCutil_sread_ubits(CC_SFILE* f, unsigned int* x, int xbits), CCutil_sread_char(CC_SFILE* f, char* x), + CCutil_sread_string(CC_SFILE* f, char* x, int maxlen), CCutil_sread_short(CC_SFILE* f, short* x), + CCutil_sread_ushort(CC_SFILE* f, unsigned short* x), CCutil_sread_short_r(CC_SFILE* f, short* x), + CCutil_sread_int(CC_SFILE* f, int* x), CCutil_sread_uint(CC_SFILE* f, unsigned int* x), + CCutil_sread_int_r(CC_SFILE* f, int* x), CCutil_sread_double(CC_SFILE* f, double* x), + CCutil_sread_double_r(CC_SFILE* f, double* x), CCutil_sflush(CC_SFILE* f), CCutil_stell(CC_SFILE* f), + CCutil_sseek(CC_SFILE* f, int offset), CCutil_srewind(CC_SFILE* f), CCutil_sclose(CC_SFILE* f), + CCutil_sbits(unsigned int x), CCutil_sdelete_file(const char* fname), + CCutil_sdelete_file_backup(const char* fname); #ifdef CC_NETREADY CC_SFILE @@ -770,9 +773,9 @@ void CCutil_signal_init(void), CCutil_handler_fatal(int signum), CCutil_handler_ /* */ /****************************************************************************/ -void CCutil_int_array_quicksort(int*len, int n), CCutil_int_perm_quicksort(int*perm, int*len, int n), - CCutil_double_perm_quicksort(int*perm, double*len, int n), - CCutil_rselect(int*arr, int l, int r, int m, double*coord, CCrandstate*rstate); +void CCutil_int_array_quicksort(int* len, int n), CCutil_int_perm_quicksort(int* perm, int* len, int n), + CCutil_double_perm_quicksort(int* perm, double* len, int n), + CCutil_rselect(int* arr, int l, int r, int m, double* coord, CCrandstate* rstate); char* CCutil_linked_radixsort(char* data, char* datanext, char* dataval, int valsize); @@ -804,15 +807,15 @@ typedef struct CCsubdiv_lkh { int status; } CCsubdiv_lkh; -int CCutil_karp_partition(int ncount, CCdatagroup*dat, int partsize, int*p_scount, CCsubdiv**p_slist, - int***partlist, CCrandstate*rstate), - CCutil_write_subdivision_index(char*problabel, int ncount, int scount, CCsubdiv*slist), - CCutil_read_subdivision_index(char*index_name, char**p_problabel, int*p_ncount, int*p_scount, - CCsubdiv**p_slist), - CCutil_write_subdivision_lkh_index(char*problabel, int ncount, int scount, CCsubdiv_lkh*slist, +int CCutil_karp_partition(int ncount, CCdatagroup* dat, int partsize, int* p_scount, CCsubdiv** p_slist, + int*** partlist, CCrandstate* rstate), + CCutil_write_subdivision_index(char* problabel, int ncount, int scount, CCsubdiv* slist), + CCutil_read_subdivision_index(char* index_name, char** p_problabel, int* p_ncount, int* p_scount, + CCsubdiv** p_slist), + CCutil_write_subdivision_lkh_index(char* problabel, int ncount, int scount, CCsubdiv_lkh* slist, double tourlen), - CCutil_read_subdivision_lkh_index(char*index_name, char**p_problabel, int*p_ncount, int*p_scount, - CCsubdiv_lkh**p_slist, double*p_tourlen); + CCutil_read_subdivision_lkh_index(char* index_name, char** p_problabel, int* p_ncount, int* p_scount, + CCsubdiv_lkh** p_slist, double* p_tourlen); /****************************************************************************/ /* */ @@ -842,16 +845,16 @@ double CCutil_normrand(CCrandstate* r); /* */ /****************************************************************************/ -char *CCutil_strchr(char*s, int c), *CCutil_strrchr(char*s, int c), *CCutil_strdup(const char*s), - *CCutil_strdup2(const char*s); +char *CCutil_strchr(char* s, int c), *CCutil_strrchr(char* s, int c), *CCutil_strdup(const char* s), + *CCutil_strdup2(const char* s); -const char *CCutil_strchr_c(const char*s, int c), *CCutil_strrchr_c(const char*s, int c); +const char *CCutil_strchr_c(const char* s, int c), *CCutil_strrchr_c(const char* s, int c); unsigned int CCutil_nextprime(unsigned int x); -int CCutil_our_gcd(int a, int b), CCutil_our_lcm(int a, int b), CCutil_print_command(int ac, char**av); +int CCutil_our_gcd(int a, int b), CCutil_our_lcm(int a, int b), CCutil_print_command(int ac, char** av); -void CCutil_readstr(FILE*f, char*s, int len), CCutil_printlabel(void); +void CCutil_readstr(FILE* f, char* s, int len), CCutil_printlabel(void); /****************************************************************************/ /* */ @@ -866,10 +869,10 @@ typedef struct CCutil_timer { int count; } CCutil_timer; -double CCutil_zeit(void), CCutil_real_zeit(void), CCutil_stop_timer(CCutil_timer*t, int printit), - CCutil_total_timer(CCutil_timer*t, int printit); +double CCutil_zeit(void), CCutil_real_zeit(void), CCutil_stop_timer(CCutil_timer* t, int printit), + CCutil_total_timer(CCutil_timer* t, int printit); -void CCutil_init_timer(CCutil_timer*t, const char*name), CCutil_start_timer(CCutil_timer*t), - CCutil_suspend_timer(CCutil_timer*t), CCutil_resume_timer(CCutil_timer*t); +void CCutil_init_timer(CCutil_timer* t, const char* name), CCutil_start_timer(CCutil_timer* t), + CCutil_suspend_timer(CCutil_timer* t), CCutil_resume_timer(CCutil_timer* t); #endif /* __UTIL_H */ diff --git a/tsp/inc/verify.h b/tsp/inc/verify.h index ebd724b..5527a97 100644 --- a/tsp/inc/verify.h +++ b/tsp/inc/verify.h @@ -35,9 +35,9 @@ typedef struct CCverify_cutclass { int* family_start; } CCverify_cutclass; -int CCverify_cut(CCtsp_lpcut_in*cut, int check_types, int*type), - CCverify_classify(CCtsp_lpcut_in*cut, int check_types, CCverify_cutclass*class); +int CCverify_cut(CCtsp_lpcut_in* cut, int check_types, int* type), + CCverify_classify(CCtsp_lpcut_in* cut, int check_types, CCverify_cutclass* class); -void CCverify_initcutclass(CCverify_cutclass*class), CCverify_freecutclass(CCverify_cutclass*class); +void CCverify_initcutclass(CCverify_cutclass* class), CCverify_freecutclass(CCverify_cutclass* class); #endif /* __VERIFY_H */ diff --git a/tsp/src/allocrus.c b/tsp/src/allocrus.c index 67ccf87..54d2f1e 100644 --- a/tsp/src/allocrus.c +++ b/tsp/src/allocrus.c @@ -86,57 +86,51 @@ typedef struct CCbigchunk { char space[CC_BIGCHUNK]; CCbigchunkptr ptr; } CCbigchunk; - -void *CCutil_allocrus (size_t size) -{ - void *mem = (void *) NULL; + +void* CCutil_allocrus(size_t size) { + void* mem = (void*)NULL; if (size == 0) { - fprintf (stderr, "Warning: 0 bytes allocated\n"); + fprintf(stderr, "Warning: 0 bytes allocated\n"); } - mem = (void *) malloc (size); - if (mem == (void *) NULL) { - fprintf (stderr, "Out of memory. Asked for %d bytes\n", (int) size); + mem = (void*)malloc(size); + if (mem == (void*)NULL) { + fprintf(stderr, "Out of memory. Asked for %d bytes\n", (int)size); } return mem; } -void CCutil_freerus (void *p) -{ +void CCutil_freerus(void* p) { if (!p) { - fprintf (stderr, "Warning: null pointer freed\n"); + fprintf(stderr, "Warning: null pointer freed\n"); return; } - free (p); + free(p); } -void *CCutil_reallocrus (void *ptr, size_t size) -{ - void *newptr; +void* CCutil_reallocrus(void* ptr, size_t size) { + void* newptr; if (!ptr) { - return CCutil_allocrus (size); + return CCutil_allocrus(size); } else { - newptr = (void *) realloc (ptr, size); + newptr = (void*)realloc(ptr, size); if (!newptr) { - fprintf (stderr, "Out of memory. Tried to grow to %d bytes\n", - (int) size); + fprintf(stderr, "Out of memory. Tried to grow to %d bytes\n", (int)size); } return newptr; } } -int CCutil_reallocrus_scale (void **pptr, int *pnnum, int count, double scale, - size_t size) -{ - int newsize = (int) (((double) *pnnum) * scale); - void *p; +int CCutil_reallocrus_scale(void** pptr, int* pnnum, int count, double scale, size_t size) { + int newsize = (int)(((double)*pnnum) * scale); + void* p; - if (newsize < *pnnum+1000) newsize = *pnnum+1000; + if (newsize < *pnnum + 1000) newsize = *pnnum + 1000; if (newsize < count) newsize = count; - p = CCutil_reallocrus (*pptr, newsize * size); + p = CCutil_reallocrus(*pptr, newsize * size); if (!p) { return 1; } else { @@ -146,9 +140,8 @@ int CCutil_reallocrus_scale (void **pptr, int *pnnum, int count, double scale, } } -int CCutil_reallocrus_count (void **pptr, int count, size_t size) -{ - void *p = CCutil_reallocrus (*pptr, count * size); +int CCutil_reallocrus_count(void** pptr, int count, size_t size) { + void* p = CCutil_reallocrus(*pptr, count * size); if (!p) { return 1; @@ -158,52 +151,44 @@ int CCutil_reallocrus_count (void **pptr, int count, size_t size) } } +CCbigchunkptr* CCutil_bigchunkalloc(void) { + CCbigchunk* p = CC_SAFE_MALLOC(1, CCbigchunk); -CCbigchunkptr *CCutil_bigchunkalloc (void) -{ - CCbigchunk *p = CC_SAFE_MALLOC (1, CCbigchunk); - - if (p == (CCbigchunk *) NULL) { - fprintf (stderr, "Out of memory in CCutil_bigchunkalloc\n"); - return (CCbigchunkptr *) NULL; + if (p == (CCbigchunk*)NULL) { + fprintf(stderr, "Out of memory in CCutil_bigchunkalloc\n"); + return (CCbigchunkptr*)NULL; } p->ptr.this_chunk = p; - p->ptr.this_one = (void *) p->space; + p->ptr.this_one = (void*)p->space; return &(p->ptr); } -void CCutil_bigchunkfree (CCbigchunkptr *bp) -{ +void CCutil_bigchunkfree(CCbigchunkptr* bp) { /* This copy is necessary since CC_FREE zeros its first argument */ - CCbigchunk *p = bp->this_chunk; - - CC_FREE (p, CCbigchunk); + CCbigchunk* p = bp->this_chunk; + + CC_FREE(p, CCbigchunk); } -void CCptrworld_init (CCptrworld *world) -{ +void CCptrworld_init(CCptrworld* world) { world->refcount = 1; - world->freelist = (void *) NULL; - world->chunklist = (CCbigchunkptr *) NULL; + world->freelist = (void*)NULL; + world->chunklist = (CCbigchunkptr*)NULL; } -void CCptrworld_add (CCptrworld *world) -{ - world->refcount++; -} +void CCptrworld_add(CCptrworld* world) { world->refcount++; } -void CCptrworld_delete (CCptrworld *world) -{ +void CCptrworld_delete(CCptrworld* world) { world->refcount--; if (world->refcount <= 0) { CCbigchunkptr *bp, *bpnext; - for (bp = world->chunklist ; bp; bp = bpnext) { + for (bp = world->chunklist; bp; bp = bpnext) { bpnext = bp->next; - CCutil_bigchunkfree (bp); + CCutil_bigchunkfree(bp); } - world->chunklist = (CCbigchunkptr *) NULL; - world->freelist = (void *) NULL; + world->chunklist = (CCbigchunkptr*)NULL; + world->freelist = (void*)NULL; world->refcount = 0; } } diff --git a/tsp/src/branch.c b/tsp/src/branch.c index 655b301..ec3a6a1 100644 --- a/tsp/src/branch.c +++ b/tsp/src/branch.c @@ -127,91 +127,90 @@ /* */ /****************************************************************************/ +#include "cut.h" +#include "lp.h" #include "machdefs.h" -#include "util.h" #include "macrorus.h" #include "tsp.h" -#include "lp.h" -#include "cut.h" +#include "util.h" -#undef DEBUG -#undef LONGEDGE_TRIANGLES +#undef DEBUG +#undef LONGEDGE_TRIANGLES -#define TSP_BRANCH_STRONG_ALL_CHOICES (-1) -#define TSP_BRANCH_STRONG_ITERATIONS (100) /* 100 */ -#define TSP_BRANCH_STRONG_EXTRA_ITERATIONS (500) /* 500 */ -#define TSP_BRANCH_STRONG_CHOICES_MULT (5) /* 5 */ -#define TSP_BRANCH_STRONG_LP_CHOICES_MULT (2) /* 2 */ +#define TSP_BRANCH_STRONG_ALL_CHOICES (-1) +#define TSP_BRANCH_STRONG_ITERATIONS (100) /* 100 */ +#define TSP_BRANCH_STRONG_EXTRA_ITERATIONS (500) /* 500 */ +#define TSP_BRANCH_STRONG_CHOICES_MULT (5) /* 5 */ +#define TSP_BRANCH_STRONG_LP_CHOICES_MULT (2) /* 2 */ -#define TSP_STRONG_CUT_CHOICES_MULT (25) /* 50 */ -#define TSP_STRONG_CUT_LP_CHOICES_MULT (5) /* 5 */ -#define TSP_STRONG_CUT_CANDIDATES (1000) /* 1000 */ -#define TSP_STRONG_CUT_CANDIDATES_MULT (100) /* 100 */ +#define TSP_STRONG_CUT_CHOICES_MULT (25) /* 50 */ +#define TSP_STRONG_CUT_LP_CHOICES_MULT (5) /* 5 */ +#define TSP_STRONG_CUT_CANDIDATES (1000) /* 1000 */ +#define TSP_STRONG_CUT_CANDIDATES_MULT (100) /* 100 */ #define TSP_BRANCH_STRONG_FIRST_WEIGHT (10.0) -#define TSP_BRANCH_STRONG_WEIGHT (100.0) +#define TSP_BRANCH_STRONG_WEIGHT (100.0) #define TSP_BRANCH_STRONG_CUT_NORM_WEIGHT (100.0) -#define TSP_BRANCH_STRONG_FIRST_VAL(v0,v1) \ - (((v0) < (v1) ? (TSP_BRANCH_STRONG_FIRST_WEIGHT * (v0) + (v1)) \ - : (TSP_BRANCH_STRONG_FIRST_WEIGHT * (v1) + (v0))) \ - / (TSP_BRANCH_STRONG_FIRST_WEIGHT + 1.0)) +#define TSP_BRANCH_STRONG_FIRST_VAL(v0, v1) \ + (((v0) < (v1) ? (TSP_BRANCH_STRONG_FIRST_WEIGHT * (v0) + (v1)) \ + : (TSP_BRANCH_STRONG_FIRST_WEIGHT * (v1) + (v0))) / \ + (TSP_BRANCH_STRONG_FIRST_WEIGHT + 1.0)) -#define TSP_BRANCH_STRONG_VAL(v0,v1) \ - (((v0) < (v1) ? (TSP_BRANCH_STRONG_WEIGHT * (v0) + (v1)) \ - : (TSP_BRANCH_STRONG_WEIGHT * (v1) + (v0))) \ - / (TSP_BRANCH_STRONG_WEIGHT + 1.0)) +#define TSP_BRANCH_STRONG_VAL(v0, v1) \ + (((v0) < (v1) ? (TSP_BRANCH_STRONG_WEIGHT * (v0) + (v1)) : (TSP_BRANCH_STRONG_WEIGHT * (v1) + (v0))) / \ + (TSP_BRANCH_STRONG_WEIGHT + 1.0)) -#define TSP_BRANCH_STRONG_CUT_NORM_VAL(v0,v1) \ - (((v0) < (v1) ? (TSP_BRANCH_STRONG_CUT_NORM_WEIGHT * (v0) + (v1)) \ - : (TSP_BRANCH_STRONG_CUT_NORM_WEIGHT * (v1) + (v0))) \ - / (TSP_BRANCH_STRONG_CUT_NORM_WEIGHT + 1.0)) +#define TSP_BRANCH_STRONG_CUT_NORM_VAL(v0, v1) \ + (((v0) < (v1) ? (TSP_BRANCH_STRONG_CUT_NORM_WEIGHT * (v0) + (v1)) \ + : (TSP_BRANCH_STRONG_CUT_NORM_WEIGHT * (v1) + (v0))) / \ + (TSP_BRANCH_STRONG_CUT_NORM_WEIGHT + 1.0)) /* a clique must be this far from 2.0 and 4.0 to be used in a branch */ #define TSP_BRANCH_CLIQUE_TOL 0.01 typedef struct sbitem { - int name; - int name2; - int name3; - int name4; + int name; + int name2; + int name3; + int name4; double val; } sbitem; typedef struct ds_node { - struct ds_node *parent; + struct ds_node* parent; int rank; } ds_node; -#define LE_OTHEREND(e,n) (((e)->ends[0] == (n)) ? ((e)->ends[1]) : ((e)->ends[0])) +#define LE_OTHEREND(e, n) (((e)->ends[0] == (n)) ? ((e)->ends[1]) : ((e)->ends[0])) typedef struct le_adj { - struct le_edge *this; - struct le_adj *next; + struct le_edge* this; + struct le_adj* next; } le_adj; typedef struct le_node { int number; int mark; - struct le_node *next_member; - struct le_edge *edgein; - le_adj *adj; + struct le_node* next_member; + struct le_edge* edgein; + le_adj* adj; } le_node; typedef struct le_edge { int len; int live; double x; - struct le_node *ends[2]; + struct le_node* ends[2]; } le_edge; typedef struct le_graph { int nnodes; int nedges; - le_node *nodes; - le_edge *edges; - le_adj *adjs; + le_node* nodes; + le_edge* edges; + le_adj* adjs; } le_graph; typedef struct le_penalty { @@ -232,140 +231,113 @@ typedef struct le_penalty { int ncnt; int nodes[4]; } le_penalty; - - + typedef struct le_info { double maxup; double maxdown; int nwant; - CCtsp_lpclique *clist; - double *cval; - le_penalty *penalties; - int *workarr; + CCtsp_lpclique* clist; + double* cval; + le_penalty* penalties; + int* workarr; } le_info; -static int - checkclique (CCtsp_lp *lp, CCtsp_lpclique *cliq, double delta, int *mark, - double *downpen, double *uppen), - CC_UNUSED checkclique2 (CCtsp_lp *lp, CCtsp_lpclique *cliq, double *x, - double delta, int *mark, double *downpen, double *uppen), - newclique (int nwant, CCtsp_lpclique *clist, double *cval, - CCtsp_lpclique *c, double down, double up), - newclique2 (int nwant, CCtsp_lpclique *clist, double *cval, - int ncnt, le_node **nodes, double down, double up, int *workarr, - le_penalty *pen, le_penalty *penalties), - build_le_graph (le_graph *g, int nnodes, int nedges, int *elist, - int *elen, double *x), - le_findmax (int ncnt, le_node **nodes, le_info *le_dat), - le_getcliques (int ncnt, le_node **nodes, le_info *le_dat), - le_foreach_clique (le_graph *g, int (*func)(int ncnt, - le_node **nodes, le_info *le_dat), le_info *le_dat), - CC_UNUSED le_foreach_clique2 (le_graph *g, CCdatagroup *dat, - int (*func)(int ncnt, le_node **nodes, le_info *le_dat), - le_info *le_dat), - merge_edge_clique (CCtsp_lp *lp, int nwant, int *ngot, - CCtsp_branchobj **bobj, int ecount, int *elist, double *eval, - int ccount, CCtsp_lpclique *clist, double *cval), - find_strong_branch (CCtsp_lp *lp, int *n0, int *n1, int silent), - find_strongbranch_edges (CCtsp_lp *lp, int nwant, int *ngot, int **elist, - double **eval, int silent), - find_candidate_edges (CCtsp_lp *lp, int nwant, int *ngot, int **list, - int silent), - find_all_candidate_edges (CCtsp_lp *lp, int *ngot, int **list), - find_candidate_cliques (CCtsp_lp *lp, int nwant, int *ngot, - CCtsp_lpclique **list, int use_getweight, int silent), - find_branched_clique (CCtsp_lp *lp, CCtsp_lpclique *c, char sense, int rhs, - int *cutnum), - CC_UNUSED find_longedge_cliques (CCtsp_lp *lp, int nwant, int *ngot, - CCtsp_lpclique **list, int silent), - find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, - CCtsp_lpclique **list, int silent), - branch_side (CCtsp_lp *lp, CCtsp_branchobj *b, int side, int child, - double *val, int *prune, int silent, CCrandstate *rstate), - test_cut_branch (CCtsp_lp *lp, CCtsp_lpclique *c, double *down, - double *up, int iter, int silent, CClp_warmstart *warmstart); - -static void - ds_makeset (ds_node *v), - print_branchobj (CCtsp_branchobj *b), - init_le_graph (le_graph *g), - free_le_graph (le_graph *g), - le_contract_work (le_node *m, le_node *newn, le_adj **p_newadj), - le_contract_finish (le_node *newn, le_adj *adj), - le_cliquevals (int ncnt, le_node **nodes, double *p_delta, - int *p_inlen, int *p_outlen, le_penalty *pen), - init_sblist (sbitem *list, int count), - insert_sblist (sbitem *list, double val, int name), - insert_sblist4 (sbitem *list, double val, int name, int name2, int name3, - int name4); - -static le_node - *le_contract (le_node *end0, le_node *end1); - -static ds_node - *ds_find (ds_node *v), - *ds_link (ds_node *x, ds_node *y); - - -void CCtsp_init_branchobj (CCtsp_branchobj *b) -{ - b->depth = 0; - b->rhs = 0; - b->ends[0] = -1; - b->ends[1] = -1; - b->sense = 'X'; - b->clique = (CCtsp_lpclique *) NULL; +static int checkclique(CCtsp_lp* lp, CCtsp_lpclique* cliq, double delta, int* mark, double* downpen, + double* uppen), + CC_UNUSED checkclique2(CCtsp_lp* lp, CCtsp_lpclique* cliq, double* x, double delta, int* mark, + double* downpen, double* uppen), + newclique(int nwant, CCtsp_lpclique* clist, double* cval, CCtsp_lpclique* c, double down, double up), + newclique2(int nwant, CCtsp_lpclique* clist, double* cval, int ncnt, le_node** nodes, double down, + double up, int* workarr, le_penalty* pen, le_penalty* penalties), + build_le_graph(le_graph* g, int nnodes, int nedges, int* elist, int* elen, double* x), + le_findmax(int ncnt, le_node** nodes, le_info* le_dat), + le_getcliques(int ncnt, le_node** nodes, le_info* le_dat), + le_foreach_clique(le_graph* g, int (*func)(int ncnt, le_node** nodes, le_info* le_dat), le_info* le_dat), + CC_UNUSED le_foreach_clique2(le_graph* g, CCdatagroup* dat, + int (*func)(int ncnt, le_node** nodes, le_info* le_dat), le_info* le_dat), + merge_edge_clique(CCtsp_lp* lp, int nwant, int* ngot, CCtsp_branchobj** bobj, int ecount, int* elist, + double* eval, int ccount, CCtsp_lpclique* clist, double* cval), + find_strong_branch(CCtsp_lp* lp, int* n0, int* n1, int silent), + find_strongbranch_edges(CCtsp_lp* lp, int nwant, int* ngot, int** elist, double** eval, int silent), + find_candidate_edges(CCtsp_lp* lp, int nwant, int* ngot, int** list, int silent), + find_all_candidate_edges(CCtsp_lp* lp, int* ngot, int** list), + find_candidate_cliques(CCtsp_lp* lp, int nwant, int* ngot, CCtsp_lpclique** list, int use_getweight, + int silent), + find_branched_clique(CCtsp_lp* lp, CCtsp_lpclique* c, char sense, int rhs, int* cutnum), + CC_UNUSED find_longedge_cliques(CCtsp_lp* lp, int nwant, int* ngot, CCtsp_lpclique** list, int silent), + find_longedge_cliques2(CCtsp_lp* lp, int nwant, int* ngot, CCtsp_lpclique** list, int silent), + branch_side(CCtsp_lp* lp, CCtsp_branchobj* b, int side, int child, double* val, int* prune, int silent, + CCrandstate* rstate), + test_cut_branch(CCtsp_lp* lp, CCtsp_lpclique* c, double* down, double* up, int iter, int silent, + CClp_warmstart* warmstart); + +static void ds_makeset(ds_node* v), print_branchobj(CCtsp_branchobj* b), init_le_graph(le_graph* g), + free_le_graph(le_graph* g), le_contract_work(le_node* m, le_node* newn, le_adj** p_newadj), + le_contract_finish(le_node* newn, le_adj* adj), + le_cliquevals(int ncnt, le_node** nodes, double* p_delta, int* p_inlen, int* p_outlen, le_penalty* pen), + init_sblist(sbitem* list, int count), insert_sblist(sbitem* list, double val, int name), + insert_sblist4(sbitem* list, double val, int name, int name2, int name3, int name4); + +static le_node* le_contract(le_node* end0, le_node* end1); + +static ds_node *ds_find(ds_node* v), *ds_link(ds_node* x, ds_node* y); + +void CCtsp_init_branchobj(CCtsp_branchobj* b) { + b->depth = 0; + b->rhs = 0; + b->ends[0] = -1; + b->ends[1] = -1; + b->sense = 'X'; + b->clique = (CCtsp_lpclique*)NULL; } -void CCtsp_free_branchobj (CCtsp_branchobj *b) -{ +void CCtsp_free_branchobj(CCtsp_branchobj* b) { if (!b) return; - b->depth = 0; - b->rhs = 0; - b->ends[0] = -1; - b->ends[1] = -1; - b->sense = 'X'; + b->depth = 0; + b->rhs = 0; + b->ends[0] = -1; + b->ends[1] = -1; + b->sense = 'X'; if (b->clique) { - CCtsp_free_lpclique (b->clique); - CC_FREE (b->clique, CCtsp_lpclique); + CCtsp_free_lpclique(b->clique); + CC_FREE(b->clique, CCtsp_lpclique); } } -void CCtsp_print_branchhistory (CCtsp_lp *lp) -{ +void CCtsp_print_branchhistory(CCtsp_lp* lp) { int j; - printf ("Branch History\n"); fflush (stdout); + printf("Branch History\n"); + fflush(stdout); if (lp->branchdepth == 0) { - printf (" Root Node\n"); + printf(" Root Node\n"); } else { for (j = 0; j < lp->branchdepth; j++) { - printf (" "); - print_branchobj (&lp->branchhistory[j]); + printf(" "); + print_branchobj(&lp->branchhistory[j]); } } - fflush (stdout); + fflush(stdout); } -static void print_branchobj (CCtsp_branchobj *b) -{ +static void print_branchobj(CCtsp_branchobj* b) { int i; - printf ("Depth %d: ", b->depth); + printf("Depth %d: ", b->depth); if (b->ends[0] != -1) { - printf ("Edge (%d,%d) set to %d\n", b->ends[0], b->ends[1], b->rhs); + printf("Edge (%d,%d) set to %d\n", b->ends[0], b->ends[1], b->rhs); } else { - printf ("Clique "); + printf("Clique "); for (i = 0; i < b->clique->segcount; i++) { - printf ("%d->%d ", b->clique->nodes[i].lo, b->clique->nodes[i].hi); + printf("%d->%d ", b->clique->nodes[i].lo, b->clique->nodes[i].hi); } if (b->sense == 'L') { - printf ("at most %d\n", b->rhs); + printf("at most %d\n", b->rhs); } else { - printf ("at least %d\n", b->rhs); + printf("at least %d\n", b->rhs); } } - fflush (stdout); + fflush(stdout); } /* @@ -604,29 +576,26 @@ int CCtsp_find_fast_branch (CCtsp_lp *lp, int *ngot, CCtsp_branchobj **bobj, /* disjoint sets ala Tarjan (from Data Structures and Network Algorithms by Robert Tarjan) */ -static void ds_makeset (ds_node *v) -{ +static void ds_makeset(ds_node* v) { v->parent = v; v->rank = 0; } -static ds_node *ds_find (ds_node *v) -{ - ds_node *p = v->parent; +static ds_node* ds_find(ds_node* v) { + ds_node* p = v->parent; - return v == p ? v : (v->parent = ds_find (p)); + return v == p ? v : (v->parent = ds_find(p)); } -static ds_node *ds_link (ds_node *x, ds_node *y) -{ - ds_node *t; +static ds_node* ds_link(ds_node* x, ds_node* y) { + ds_node* t; - x = ds_find (x); - y = ds_find (y); + x = ds_find(x); + y = ds_find(y); if (x != y) { if (x->rank > y->rank) { - CC_SWAP (x,y,t); + CC_SWAP(x, y, t); } else if (x->rank == y->rank) { y->rank++; } @@ -635,33 +604,30 @@ static ds_node *ds_link (ds_node *x, ds_node *y) return y; } -static int checkclique (CCtsp_lp *lp, CCtsp_lpclique *cliq, double delta, - int *mark, double *downpen, double *uppen) -{ +static int checkclique(CCtsp_lp* lp, CCtsp_lpclique* cliq, double delta, int* mark, double* downpen, + double* uppen) { int i; int j; int k; int m; int e = 0; - CCtsp_lpnode *nodes = lp->graph.nodes; - CCtsp_lpedge *edges = lp->graph.edges; + CCtsp_lpnode* nodes = lp->graph.nodes; + CCtsp_lpedge* edges = lp->graph.edges; int noutside = 0; int ninside = 0; int ncomp = 0; - int *inside = (int *) NULL; - int *outside = (int *) NULL; - int *inlen = (int *) NULL; - int *outlen = (int *) NULL; - int *inperm = (int *) NULL; - int *outperm = (int *) NULL; - ds_node *innodes = (ds_node *) NULL; + int* inside = (int*)NULL; + int* outside = (int*)NULL; + int* inlen = (int*)NULL; + int* outlen = (int*)NULL; + int* inperm = (int*)NULL; + int* outperm = (int*)NULL; + ds_node* innodes = (ds_node*)NULL; int rval; - CC_FOREACH_NODE_IN_CLIQUE (i, *cliq, j) { - mark[i] = 1; - } - CC_FOREACH_NODE_IN_CLIQUE (i, *cliq, j) { - for (k=0; kgraph.ncount, ds_node); - if (inside == (int *) NULL || outside == (int *) NULL || - inlen == (int *) NULL || outlen == (int *) NULL || - inperm == (int *) NULL || outperm == (int *) NULL || - innodes == (ds_node *) NULL) { - fprintf (stderr, "Out of memory in checkclique\n"); - rval = 1; goto CLEANUP; + inside = CC_SAFE_MALLOC(ninside, int); + outside = CC_SAFE_MALLOC(noutside, int); + inlen = CC_SAFE_MALLOC(ninside, int); + outlen = CC_SAFE_MALLOC(noutside, int); + inperm = CC_SAFE_MALLOC(ninside, int); + outperm = CC_SAFE_MALLOC(noutside, int); + innodes = CC_SAFE_MALLOC(lp->graph.ncount, ds_node); + if (inside == (int*)NULL || outside == (int*)NULL || inlen == (int*)NULL || outlen == (int*)NULL || + inperm == (int*)NULL || outperm == (int*)NULL || innodes == (ds_node*)NULL) { + fprintf(stderr, "Out of memory in checkclique\n"); + rval = 1; + goto CLEANUP; } ninside = 0; noutside = 0; - CC_FOREACH_NODE_IN_CLIQUE (i, *cliq, j) { - ds_makeset (&innodes[i]); + CC_FOREACH_NODE_IN_CLIQUE(i, *cliq, j) { + ds_makeset(&innodes[i]); ncomp++; - for (k=0; k 1; i++) { + for (i = 0; i < ninside && ncomp > 1; i++) { e = inside[inperm[i]]; - if (ds_find (&innodes[edges[e].ends[0]]) != - ds_find (&innodes[edges[e].ends[1]])) { + if (ds_find(&innodes[edges[e].ends[0]]) != ds_find(&innodes[edges[e].ends[1]])) { ncomp--; - ds_link (&innodes[edges[e].ends[0]], &innodes[edges[e].ends[1]]); + ds_link(&innodes[edges[e].ends[0]], &innodes[edges[e].ends[1]]); } } - if (downpen != (double *) NULL) { + if (downpen != (double*)NULL) { *downpen = (((delta - 2.0) / 2.0) * edges[e].len); } #ifdef DEBUG - printf ("clique "); - CCtsp_print_lpclique (cliq); - printf ("delta %.6f outlen %d inlen %d uppen %.6f downpen %.6f\n", - delta, outlen[outperm[0]], edges[e].len, *uppen, *downpen); + printf("clique "); + CCtsp_print_lpclique(cliq); + printf("delta %.6f outlen %d inlen %d uppen %.6f downpen %.6f\n", delta, outlen[outperm[0]], edges[e].len, + *uppen, *downpen); #endif /* DEBUG */ - + rval = 0; - CLEANUP: - CC_IFFREE (inside, int); - CC_IFFREE (outside, int); - CC_IFFREE (inlen, int); - CC_IFFREE (outlen, int); - CC_IFFREE (inperm, int); - CC_IFFREE (outperm, int); - CC_IFFREE (innodes, ds_node); +CLEANUP: + CC_IFFREE(inside, int); + CC_IFFREE(outside, int); + CC_IFFREE(inlen, int); + CC_IFFREE(outlen, int); + CC_IFFREE(inperm, int); + CC_IFFREE(outperm, int); + CC_IFFREE(innodes, ds_node); return rval; } -static int CC_UNUSED checkclique2 (CCtsp_lp *lp, CCtsp_lpclique *cliq, - double *x, double delta, int *mark, double *downpen, double *uppen) -{ +static int CC_UNUSED checkclique2(CCtsp_lp* lp, CCtsp_lpclique* cliq, double* x, double delta, int* mark, + double* downpen, double* uppen) { int i; int j; int k; int m; int e = 0; - CCtsp_lpnode *nodes = lp->graph.nodes; - CCtsp_lpedge *edges = lp->graph.edges; + CCtsp_lpnode* nodes = lp->graph.nodes; + CCtsp_lpedge* edges = lp->graph.edges; int noutside = 0; int ninside = 0; int ncomp = 0; - int *inside = (int *) NULL; - int *outside = (int *) NULL; - double *inlen = (double *) NULL; - double *outlen = (double *) NULL; - int *inperm = (int *) NULL; - int *outperm = (int *) NULL; - ds_node *innodes = (ds_node *) NULL; + int* inside = (int*)NULL; + int* outside = (int*)NULL; + double* inlen = (double*)NULL; + double* outlen = (double*)NULL; + int* inperm = (int*)NULL; + int* outperm = (int*)NULL; + ds_node* innodes = (ds_node*)NULL; double sum; double cost; int rval; - CC_FOREACH_NODE_IN_CLIQUE (i, *cliq, j) { - mark[i] = 1; - } - CC_FOREACH_NODE_IN_CLIQUE (i, *cliq, j) { - for (k=0; kgraph.ncount, ds_node); - if (inside == (int *) NULL || outside == (int *) NULL || - inlen == (double *) NULL || outlen == (double *) NULL || - inperm == (int *) NULL || outperm == (int *) NULL || - innodes == (ds_node *) NULL) { - fprintf (stderr, "Out of memory in checkclique2\n"); - rval = 1; goto CLEANUP; + inside = CC_SAFE_MALLOC(ninside, int); + outside = CC_SAFE_MALLOC(noutside, int); + inlen = CC_SAFE_MALLOC(ninside, double); + outlen = CC_SAFE_MALLOC(noutside, double); + inperm = CC_SAFE_MALLOC(ninside, int); + outperm = CC_SAFE_MALLOC(noutside, int); + innodes = CC_SAFE_MALLOC(lp->graph.ncount, ds_node); + if (inside == (int*)NULL || outside == (int*)NULL || inlen == (double*)NULL || outlen == (double*)NULL || + inperm == (int*)NULL || outperm == (int*)NULL || innodes == (ds_node*)NULL) { + fprintf(stderr, "Out of memory in checkclique2\n"); + rval = 1; + goto CLEANUP; } ninside = 0; noutside = 0; - CC_FOREACH_NODE_IN_CLIQUE (i, *cliq, j) { - ds_makeset (&innodes[i]); + CC_FOREACH_NODE_IN_CLIQUE(i, *cliq, j) { + ds_makeset(&innodes[i]); ncomp++; - for (k=0; k 1; i++) { + for (i = 0; i < ninside && ncomp > 1; i++) { e = inside[inperm[i]]; - if (ds_find (&innodes[edges[e].ends[0]]) != - ds_find (&innodes[edges[e].ends[1]])) { + if (ds_find(&innodes[edges[e].ends[0]]) != ds_find(&innodes[edges[e].ends[1]])) { ncomp--; - ds_link (&innodes[edges[e].ends[0]], &innodes[edges[e].ends[1]]); + ds_link(&innodes[edges[e].ends[0]], &innodes[edges[e].ends[1]]); } } - if (downpen != (double *) NULL) { + if (downpen != (double*)NULL) { *downpen = ((1.0 - x[e]) * edges[e].len); } - + rval = 0; - CLEANUP: - CC_IFFREE (inside, int); - CC_IFFREE (outside, int); - CC_IFFREE (inlen, double); - CC_IFFREE (outlen, double); - CC_IFFREE (inperm, int); - CC_IFFREE (outperm, int); - CC_IFFREE (innodes, ds_node); +CLEANUP: + CC_IFFREE(inside, int); + CC_IFFREE(outside, int); + CC_IFFREE(inlen, double); + CC_IFFREE(outlen, double); + CC_IFFREE(inperm, int); + CC_IFFREE(outperm, int); + CC_IFFREE(innodes, ds_node); return rval; } -static int newclique (int nwant, CCtsp_lpclique *clist, double *cval, - CCtsp_lpclique *c, double down, double up) -{ +static int newclique(int nwant, CCtsp_lpclique* clist, double* cval, CCtsp_lpclique* c, double down, + double up) { double angle = atan2(down, up); - int bin = (int) (nwant * angle * 2.0 / M_PI); + int bin = (int)(nwant * angle * 2.0 / M_PI); double val = down * down + up * up; int rval; - if (bin == nwant) bin = nwant-1; + if (bin == nwant) bin = nwant - 1; if (val > cval[bin]) { cval[bin] = val; - CCtsp_free_lpclique (&clist[bin]); - rval = CCtsp_copy_lpclique (c, &clist[bin]); + CCtsp_free_lpclique(&clist[bin]); + rval = CCtsp_copy_lpclique(c, &clist[bin]); if (rval) { - fprintf (stderr, "CCtsp_copy_lpclique failed\n"); + fprintf(stderr, "CCtsp_copy_lpclique failed\n"); return rval; } } @@ -935,7 +889,7 @@ static int CC_UNUSED find_longedge_cliques (CCtsp_lp *lp, int nwant, int *ngot, if (!silent) { printf ("Finding long-edge cliques\n"); fflush (stdout); } - + if (nwant <= 0) { fprintf (stderr, "find_longedge_cliques called with no nwant\n"); rval = 1; goto CLEANUP; @@ -988,7 +942,7 @@ static int CC_UNUSED find_longedge_cliques (CCtsp_lp *lp, int nwant, int *ngot, CCutil_double_perm_quicksort (perm, len, ncount); CCutil_int_array_quicksort (perm + ncount - nbig, nbig); - + big = CC_SAFE_MALLOC (nbig, int); if (big == (int *) NULL) { fprintf (stderr, "Out of memory in find_longedge_cliques\n"); @@ -1078,7 +1032,7 @@ static int CC_UNUSED find_longedge_cliques (CCtsp_lp *lp, int nwant, int *ngot, cval[i] = -1.0; CCtsp_init_lpclique (&clist[i]); } - + for (i=0; innodes = 0; g->nedges = 0; - g->nodes = (le_node *) NULL; - g->edges = (le_edge *) NULL; - g->adjs = (le_adj *) NULL; + g->nodes = (le_node*)NULL; + g->edges = (le_edge*)NULL; + g->adjs = (le_adj*)NULL; } -static void free_le_graph (le_graph *g) -{ - CC_IFFREE (g->nodes, le_node); - CC_IFFREE (g->edges, le_edge); - CC_IFFREE (g->adjs, le_adj); +static void free_le_graph(le_graph* g) { + CC_IFFREE(g->nodes, le_node); + CC_IFFREE(g->edges, le_edge); + CC_IFFREE(g->adjs, le_adj); } -static int build_le_graph (le_graph *g, int nnodes, int nedges, int *elist, - int *elen, double *x) -{ +static int build_le_graph(le_graph* g, int nnodes, int nedges, int* elist, int* elen, double* x) { int rval; int i; int j; - le_node *n; - le_node *nodes; - le_edge *edges; - int *perm = (int *) NULL; - - init_le_graph (g); + le_node* n; + le_node* nodes; + le_edge* edges; + int* perm = (int*)NULL; + + init_le_graph(g); g->nnodes = nnodes; g->nedges = nedges; - g->nodes = CC_SAFE_MALLOC (nnodes, le_node); - g->edges = CC_SAFE_MALLOC (nedges, le_edge); - g->adjs = CC_SAFE_MALLOC (nedges*2, le_adj); - perm = CC_SAFE_MALLOC (nedges, int); - if (g->nodes == (le_node *) NULL || - g->edges == (le_edge *) NULL || - g->adjs == (le_adj *) NULL || - perm == (int *) NULL) { - fprintf (stderr, "Out of memory in build_le_graph\n"); - rval = 1; goto CLEANUP; + g->nodes = CC_SAFE_MALLOC(nnodes, le_node); + g->edges = CC_SAFE_MALLOC(nedges, le_edge); + g->adjs = CC_SAFE_MALLOC(nedges * 2, le_adj); + perm = CC_SAFE_MALLOC(nedges, int); + if (g->nodes == (le_node*)NULL || g->edges == (le_edge*)NULL || g->adjs == (le_adj*)NULL || + perm == (int*)NULL) { + fprintf(stderr, "Out of memory in build_le_graph\n"); + rval = 1; + goto CLEANUP; } nodes = g->nodes; edges = g->edges; - for (i=0; imark++; edges[i].ends[1]->mark++; } - j=0; - for (i=0; iadjs + j; j += nodes[i].mark; nodes[i].mark = 0; } - for (i=0; iadj[n->mark].this = &edges[i]; - n->adj[n->mark].next = &(n->adj[n->mark+1]); + n->adj[n->mark].next = &(n->adj[n->mark + 1]); n->mark++; n = edges[i].ends[1]; n->adj[n->mark].this = &edges[i]; - n->adj[n->mark].next = &(n->adj[n->mark+1]); + n->adj[n->mark].next = &(n->adj[n->mark + 1]); n->mark++; } - for (i=0; iadj; a; a = anext) { e = a->this; anext = a->next; @@ -1339,7 +1287,7 @@ static void le_contract_work (le_node *m, le_node *newn, le_adj **p_newadj) e->ends[1] = newn; n = e->ends[0]; } - if (n->edgein == (le_edge *) NULL) { + if (n->edgein == (le_edge*)NULL) { a->next = newadj; newadj = a; n->edgein = e; @@ -1359,13 +1307,12 @@ static void le_contract_work (le_node *m, le_node *newn, le_adj **p_newadj) *p_newadj = newadj; } -static void le_contract_finish (le_node *newn, le_adj *adj) -{ - le_adj *a; - le_adj *anext; - le_node *n; - le_edge *e; - le_adj *newadj = (le_adj *) NULL; +static void le_contract_finish(le_node* newn, le_adj* adj) { + le_adj* a; + le_adj* anext; + le_node* n; + le_edge* e; + le_adj* newadj = (le_adj*)NULL; for (a = adj; a; a = anext) { e = a->this; @@ -1375,15 +1322,14 @@ static void le_contract_finish (le_node *newn, le_adj *adj) n = LE_OTHEREND(e, newn); e = n->edgein; a->this = e; - n->edgein = (le_edge *) NULL; + n->edgein = (le_edge*)NULL; } newn->adj = newadj; } - -static le_node *le_contract (le_node *end0, le_node *end1) -{ - le_adj *newadj; - le_node *n; + +static le_node* le_contract(le_node* end0, le_node* end1) { + le_adj* newadj; + le_node* n; le_edge dummy; dummy.x = 0.0; @@ -1391,40 +1337,38 @@ static le_node *le_contract (le_node *end0, le_node *end1) end0->edgein = &dummy; end1->edgein = &dummy; - newadj = (le_adj *) NULL; + newadj = (le_adj*)NULL; - le_contract_work (end0, end0, &newadj); - le_contract_work (end1, end0, &newadj); - le_contract_finish (end0, newadj); + le_contract_work(end0, end0, &newadj); + le_contract_work(end1, end0, &newadj); + le_contract_finish(end0, newadj); n = end0->next_member; end0->next_member = end1->next_member; end1->next_member = n; - end0->edgein = (le_edge *) NULL; + end0->edgein = (le_edge*)NULL; return end0; } -static int newclique2 (int nwant, CCtsp_lpclique *clist, double *cval, - int ncnt, le_node **nodes, double down, double up, int *workarr, - le_penalty *pen, le_penalty *penalties) -{ +static int newclique2(int nwant, CCtsp_lpclique* clist, double* cval, int ncnt, le_node** nodes, double down, + double up, int* workarr, le_penalty* pen, le_penalty* penalties) { double angle = atan2(down, up); - int bin = (int) (nwant * angle * 2.0 / M_PI); + int bin = (int)(nwant * angle * 2.0 / M_PI); double val = down * down + up * up; int rval; - le_node *n; + le_node* n; int cnt; int i; - if (bin == nwant) bin = nwant-1; + if (bin == nwant) bin = nwant - 1; if (val > cval[bin]) { cval[bin] = val; - CCtsp_free_lpclique (&clist[bin]); + CCtsp_free_lpclique(&clist[bin]); cnt = 0; - for (i=0; inumber; @@ -1432,9 +1376,9 @@ static int newclique2 (int nwant, CCtsp_lpclique *clist, double *cval, } while (n != nodes[i]); } - rval = CCtsp_array_to_lpclique (workarr, cnt, &clist[bin]); + rval = CCtsp_array_to_lpclique(workarr, cnt, &clist[bin]); if (rval) { - fprintf (stderr, "CCtsp_array_to_lpclique failed\n"); + fprintf(stderr, "CCtsp_array_to_lpclique failed\n"); return rval; } penalties[bin] = *pen; @@ -1442,9 +1386,8 @@ static int newclique2 (int nwant, CCtsp_lpclique *clist, double *cval, return 0; } -static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, - int *p_inlen, int *p_outlen, le_penalty *pen) -{ +static void le_cliquevals(int ncnt, le_node** nodes, double* p_delta, int* p_inlen, int* p_outlen, + le_penalty* pen) { double delta = 0.0; double delta_bad = 0.0; double indelta; @@ -1464,10 +1407,10 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, int gotmin_bad; int gotmout; int i; - le_node *n; - le_adj *a; - le_edge *e; - le_node *m; + le_node* n; + le_adj* a; + le_edge* e; + le_node* m; double bestdiff = 0.0; double bestdiff2 = 0.0; double sumtwo = 0.0; @@ -1487,18 +1430,18 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, double ucost; double umove; - for (i=0; imark = 1; } - - for (i=0; iadj; a; a = a->next) { e = a->this; if (e->live) { - m = LE_OTHEREND (e, n); + m = LE_OTHEREND(e, n); if (m->mark) { if (!gotmin_bad || e->len < minlen_bad) { minlen_bad = e->len; @@ -1519,7 +1462,7 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, } } - for (i=0; iadj; a; a = a->next) { e = a->this; if (e->live) { - m = LE_OTHEREND (e, n); + m = LE_OTHEREND(e, n); if (m->mark) { indelta += e->x; if (!gotmin || e->len < minlen) { @@ -1553,10 +1496,14 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, inlen = minlen; gotin = 1; } - if (indelta >= 2.0) twomove = 0.0; - else twomove = (2.0 - indelta); - if (indelta >= 1.0) onemove = 0.0; - else onemove = (1.0 - indelta); + if (indelta >= 2.0) + twomove = 0.0; + else + twomove = (2.0 - indelta); + if (indelta >= 1.0) + onemove = 0.0; + else + onemove = (1.0 - indelta); sumtwo += twomove * minlen; summove += twomove; diffmove = (twomove - onemove); @@ -1572,8 +1519,10 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, bestmove2 = diffmove; } } - if (outdelta >= 2.0) umove = 0.0; - else umove = (2.0 - outdelta); + if (outdelta >= 2.0) + umove = 0.0; + else + umove = (2.0 - outdelta); ucost = umove * moutlen; if (!gotuc2 || ucost < bestucost2) { if (!gotuc || ucost < bestucost) { @@ -1588,7 +1537,6 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, gotuc2 = 1; } } - } sumtwo -= bestdiff + bestdiff2; summove -= bestmove + bestmove2; @@ -1596,7 +1544,7 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, ucost = bestucost + bestucost2; umove = bestumove + bestumove2; - for (i=0; imark = 0; } @@ -1612,42 +1560,42 @@ static void le_cliquevals (int ncnt, le_node **nodes, double *p_delta, pen->uppen2 = (4.0 - delta) * (outlen - inlen * 0.5); pen->downpen2 = (delta - 2.0) * (inlen * 0.5 - outlen); pen->downpen3 = sumtwo; - if (summove == 0.0) pen->downpen4 = sumtwo; - else pen->downpen4 = sumtwo * (delta - 2.0) / summove; + if (summove == 0.0) + pen->downpen4 = sumtwo; + else + pen->downpen4 = sumtwo * (delta - 2.0) / summove; pen->uppen3 = ucost; - if (umove == 0.0) pen->uppen4 = ucost; - else pen->uppen4 = ucost * (4.0 - delta) / umove; + if (umove == 0.0) + pen->uppen4 = ucost; + else + pen->uppen4 = ucost * (4.0 - delta) / umove; pen->ncnt = ncnt; - for (i=0; inodes[i] = nodes[i]->number; } } -/* - *p_delta = delta_bad; - *p_inlen = inlen_bad; - *p_outlen = outlen_bad; - */ - + /* + *p_delta = delta_bad; + *p_inlen = inlen_bad; + *p_outlen = outlen_bad; + */ *p_delta = delta; *p_inlen = inlen; *p_outlen = outlen; - } -static int le_findmax (int ncnt, le_node **nodes, le_info *le_dat) -{ +static int le_findmax(int ncnt, le_node** nodes, le_info* le_dat) { double delta = 0.0; int inlen = 0; int outlen = 0; double downpen; double uppen; - le_cliquevals (ncnt, nodes, &delta, &inlen, &outlen, (le_penalty *) NULL); + le_cliquevals(ncnt, nodes, &delta, &inlen, &outlen, (le_penalty*)NULL); - if (delta <= (2.0 + TSP_BRANCH_CLIQUE_TOL) || - delta >= (4.0 - TSP_BRANCH_CLIQUE_TOL)) return 0; + if (delta <= (2.0 + TSP_BRANCH_CLIQUE_TOL) || delta >= (4.0 - TSP_BRANCH_CLIQUE_TOL)) return 0; uppen = (4.0 - delta) * outlen; downpen = (delta - 2.0) * inlen; @@ -1658,8 +1606,7 @@ static int le_findmax (int ncnt, le_node **nodes, le_info *le_dat) return 0; } -static int le_getcliques (int ncnt, le_node **nodes, le_info *le_dat) -{ +static int le_getcliques(int ncnt, le_node** nodes, le_info* le_dat) { double delta = 0.0; int inlen = 0; int outlen = 0; @@ -1668,25 +1615,24 @@ static int le_getcliques (int ncnt, le_node **nodes, le_info *le_dat) int rval = 0; le_penalty pen; - le_cliquevals (ncnt, nodes, &delta, &inlen, &outlen, &pen); - - if (delta <= (2.0 + TSP_BRANCH_CLIQUE_TOL) || - delta >= (4.0 - TSP_BRANCH_CLIQUE_TOL)) return 0; - + le_cliquevals(ncnt, nodes, &delta, &inlen, &outlen, &pen); + + if (delta <= (2.0 + TSP_BRANCH_CLIQUE_TOL) || delta >= (4.0 - TSP_BRANCH_CLIQUE_TOL)) return 0; + uppen = (4.0 - delta) * outlen; downpen = (delta - 2.0) * inlen; #ifdef DEBUG { - le_node *n; + le_node* n; CCtsp_lpclique cliq; - int *arr = (int *) NULL; + int* arr = (int*)NULL; int cnt = 0; int i; - CCtsp_init_lpclique (&cliq); + CCtsp_init_lpclique(&cliq); - for (i=0; inumber; @@ -1708,77 +1654,75 @@ static int le_getcliques (int ncnt, le_node **nodes, le_info *le_dat) } while (n != nodes[i]); } - rval = CCtsp_array_to_lpclique (arr, cnt, &cliq); + rval = CCtsp_array_to_lpclique(arr, cnt, &cliq); if (rval) { - CC_IFFREE (arr, int); - CCtsp_free_lpclique (&cliq); + CC_IFFREE(arr, int); + CCtsp_free_lpclique(&cliq); return rval; } - - printf ("clique "); - CCtsp_print_lpclique (&cliq); - printf ("delta %.6f outlen %d inlen %d uppen %.6f downpen %.6f\n", - delta, outlen, inlen, uppen, downpen); - fflush (stdout); - CCtsp_free_lpclique (&cliq); - CC_IFFREE (arr, int); + + printf("clique "); + CCtsp_print_lpclique(&cliq); + printf("delta %.6f outlen %d inlen %d uppen %.6f downpen %.6f\n", delta, outlen, inlen, uppen, + downpen); + fflush(stdout); + CCtsp_free_lpclique(&cliq); + CC_IFFREE(arr, int); } #endif /* DEBUG */ uppen /= le_dat->maxup; downpen /= le_dat->maxdown; - rval = newclique2 (le_dat->nwant, le_dat->clist, le_dat->cval, ncnt, nodes, - downpen, uppen, le_dat->workarr, &pen, - le_dat->penalties); + rval = newclique2(le_dat->nwant, le_dat->clist, le_dat->cval, ncnt, nodes, downpen, uppen, + le_dat->workarr, &pen, le_dat->penalties); if (rval) { - fprintf (stderr, "newclique2 failed\n"); + fprintf(stderr, "newclique2 failed\n"); return rval; } return rval; } -static int le_foreach_clique (le_graph *g, int (*func)(int ncnt, - le_node **nodes, le_info *le_dat), le_info *le_dat) -{ +static int le_foreach_clique(le_graph* g, int (*func)(int ncnt, le_node** nodes, le_info* le_dat), + le_info* le_dat) { int i; int nedges = g->nedges; int nnodes = g->nnodes; - le_edge *edges = g->edges; - le_node *n; - le_adj *a; + le_edge* edges = g->edges; + le_node* n; + le_adj* a; #ifdef LONGEDGE_TRIANGLES - le_adj *b; - le_node *m; + le_adj* b; + le_node* m; #endif int rval; - le_node *cnodes[3]; + le_node* cnodes[3]; - for (i=0; inodes[i]; cnodes[0] = n; for (a = n->adj; a; a = a->next) { if (a->this->live) { - cnodes[1] = LE_OTHEREND (a->this, n); + cnodes[1] = LE_OTHEREND(a->this, n); for (b = a->next; b; b = b->next) { if (b->this->live) { - cnodes[2] = LE_OTHEREND (b->this, n); + cnodes[2] = LE_OTHEREND(b->this, n); } rval = (*func)(3, cnodes, le_dat); if (rval) { - fprintf (stderr, "le_foreach_clique callback failed\n"); + fprintf(stderr, "le_foreach_clique callback failed\n"); return rval; } } @@ -1786,47 +1730,46 @@ static int le_foreach_clique (le_graph *g, int (*func)(int ncnt, } } #endif - - for (i=0; i= 4; i++) { + + for (i = 0; i < nedges && nnodes >= 4; i++) { if (edges[i].live) { if (edges[i].ends[0] == edges[i].ends[1]) { - fprintf (stderr, "Whoops, trying to contract self-loop\n"); + fprintf(stderr, "Whoops, trying to contract self-loop\n"); continue; } #ifdef DEBUG - printf ("contracting %d: %d - %d\n", - i, edges[i].ends[0]->number, edges[i].ends[1]->number); + printf("contracting %d: %d - %d\n", i, edges[i].ends[0]->number, edges[i].ends[1]->number); #endif /* DEBUG */ - n = le_contract (edges[i].ends[0], edges[i].ends[1]); + n = le_contract(edges[i].ends[0], edges[i].ends[1]); for (a = n->adj; a; a = a->next) { if (a->this->live) { cnodes[0] = a->this->ends[0]; cnodes[1] = a->this->ends[1]; rval = (*func)(2, cnodes, le_dat); if (rval) { - fprintf (stderr, "le_foreach_clique callback failed\n"); + fprintf(stderr, "le_foreach_clique callback failed\n"); return rval; } #ifdef LONGEDGE_TRIANGLES if (nnodes >= 5) { for (b = a->next; b; b = b->next) { if (b->this->live) { - cnodes[2] = LE_OTHEREND (b->this, n); - rval = (*func) (3, cnodes, le_dat); + cnodes[2] = LE_OTHEREND(b->this, n); + rval = (*func)(3, cnodes, le_dat); if (rval) { - fprintf (stderr, "le_foreach_clique callback failed\n"); + fprintf(stderr, "le_foreach_clique callback failed\n"); return rval; } } } - m = LE_OTHEREND (a->this, n); + m = LE_OTHEREND(a->this, n); for (b = m->adj; b; b = b->next) { if (b->this->live) { - cnodes[2] = LE_OTHEREND (b->this, m); + cnodes[2] = LE_OTHEREND(b->this, m); if (cnodes[2] != n) { - rval = (*func) (3, cnodes, le_dat); + rval = (*func)(3, cnodes, le_dat); if (rval) { - fprintf (stderr, "le_foreach_clique callback failed\n"); + fprintf(stderr, "le_foreach_clique callback failed\n"); return rval; } } @@ -1834,67 +1777,64 @@ static int le_foreach_clique (le_graph *g, int (*func)(int ncnt, } } #endif - } } nnodes--; } } - + return 0; } -static int CC_UNUSED le_foreach_clique2 (le_graph *g, CCdatagroup *dat, - int (*func)(int ncnt, le_node **nodes, le_info *le_dat), - le_info *le_dat) -{ +static int CC_UNUSED le_foreach_clique2(le_graph* g, CCdatagroup* dat, + int (*func)(int ncnt, le_node** nodes, le_info* le_dat), + le_info* le_dat) { int i; int nedges = g->nedges; int nnodes = g->nnodes; - le_edge *edges = g->edges; - le_node *n; - le_adj *a; - int *len = (int *) NULL; - int *perm = (int *) NULL; - le_node *cnodes[2]; + le_edge* edges = g->edges; + le_node* n; + le_adj* a; + int* len = (int*)NULL; + int* perm = (int*)NULL; + le_node* cnodes[2]; int rval = 0; - len = CC_SAFE_MALLOC (nnodes, int); - perm = CC_SAFE_MALLOC (nnodes, int); - if (len == (int *) NULL || - perm == (int *) NULL) { - fprintf (stderr, "Out of memory in le_foreach_clique2\n"); - rval = 1; goto CLEANUP; + len = CC_SAFE_MALLOC(nnodes, int); + perm = CC_SAFE_MALLOC(nnodes, int); + if (len == (int*)NULL || perm == (int*)NULL) { + fprintf(stderr, "Out of memory in le_foreach_clique2\n"); + rval = 1; + goto CLEANUP; } - len[0] = CCutil_dat_edgelen (0, nnodes-1, dat); - for (i=1; innodes && nnodes >= 4; i++) { + for (i = 0; i < g->nnodes && nnodes >= 4; i++) { if (edges[i].live && edges[i].ends[0] != edges[i].ends[1]) { #ifdef DEBUG - printf ("contracting %d: %d - %d\n", - i, edges[i].ends[0]->number, edges[i].ends[1]->number); + printf("contracting %d: %d - %d\n", i, edges[i].ends[0]->number, edges[i].ends[1]->number); #endif /* DEBUG */ - n = le_contract (edges[i].ends[0], edges[i].ends[1]); + n = le_contract(edges[i].ends[0], edges[i].ends[1]); for (a = n->adj; a; a = a->next) { cnodes[0] = a->this->ends[0]; cnodes[1] = a->this->ends[1]; rval = (*func)(2, cnodes, le_dat); if (rval) { - fprintf (stderr, "le_foreach_clique callback failed\n"); + fprintf(stderr, "le_foreach_clique callback failed\n"); goto CLEANUP; } } @@ -1902,14 +1842,13 @@ static int CC_UNUSED le_foreach_clique2 (le_graph *g, CCdatagroup *dat, } } - CLEANUP: - CC_IFFREE (len, int); - CC_IFFREE (perm, int); - +CLEANUP: + CC_IFFREE(len, int); + CC_IFFREE(perm, int); + return rval; } - /* static int find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, CCtsp_lpclique **list, int silent) @@ -1938,7 +1877,7 @@ static int find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, if (!silent) { printf ("Finding long-edge cliques\n"); fflush (stdout); } - + if (nwant <= 0) { fprintf (stderr, "find_longedge_cliques called with no nwant\n"); rval = 1; goto CLEANUP; @@ -1976,7 +1915,7 @@ static int find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, le_dat.maxup = 0.0; le_dat.maxdown = 0.0; - + rval = le_foreach_clique (&g, le_findmax, &le_dat); if (rval) { fprintf (stderr, "le_foreach_clique failed\n"); @@ -1991,15 +1930,15 @@ static int find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, // } free_le_graph (&g); - + if (le_dat.maxdown == 0.0) le_dat.maxdown = 1.0; if (le_dat.maxup == 0.0) le_dat.maxup = 1.0; -#endif +#endif le_dat.maxdown = 10.0; le_dat.maxup = 3.0; - + clist = CC_SAFE_MALLOC (nwant, CCtsp_lpclique); cval = CC_SAFE_MALLOC (nwant, double); penalties = CC_SAFE_MALLOC (nwant, le_penalty); @@ -2022,7 +1961,7 @@ static int find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, le_dat.penalties = penalties; le_dat.cval = cval; le_dat.workarr = workarr; - + rval = build_le_graph (&g, ncount, xcount, xlist, len, x); if (rval) { fprintf (stderr, "build_le_graph failed\n"); @@ -2062,12 +2001,10 @@ static int find_longedge_cliques2 (CCtsp_lp *lp, int nwant, int *ngot, int j; printf ("%d: (%.6f) ", i, cval[i]); CCtsp_print_lpclique (&clist[i]); - printf ("%d: delta %.6f inlen %d outlen %d uppen_bad %.6f downpen_bad %.6f uppen %.6f downpen %.6f uppen2 %.6f downpen2 %.6f uppen3 %.6f downpen3 %.6f uppen4 %.6f downpen4 %.6f\n", - i, penalties[i].delta, penalties[i].inlen, penalties[i].outlen, - penalties[i].uppen_bad, penalties[i].downpen_bad, - penalties[i].uppen, penalties[i].downpen, - penalties[i].uppen2, penalties[i].downpen2, - penalties[i].uppen3, penalties[i].downpen3, + printf ("%d: delta %.6f inlen %d outlen %d uppen_bad %.6f downpen_bad %.6f uppen %.6f downpen +%.6f uppen2 %.6f downpen2 %.6f uppen3 %.6f downpen3 %.6f uppen4 %.6f downpen4 %.6f\n", i, penalties[i].delta, +penalties[i].inlen, penalties[i].outlen, penalties[i].uppen_bad, penalties[i].downpen_bad, penalties[i].uppen, +penalties[i].downpen, penalties[i].uppen2, penalties[i].downpen2, penalties[i].uppen3, penalties[i].downpen3, penalties[i].uppen4, penalties[i].downpen4); printf ("%d: nodes", i); for (j=0; jends[0] = lp->graph.edges[elist[slist[i].name]].ends[0]; b->ends[1] = lp->graph.edges[elist[slist[i].name]].ends[1]; } else { - b->clique = CC_SAFE_MALLOC (1, CCtsp_lpclique); + b->clique = CC_SAFE_MALLOC(1, CCtsp_lpclique); if (!b->clique) { - fprintf (stderr, "out of memory in merge_edge_clique\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "out of memory in merge_edge_clique\n"); + rval = 1; + goto CLEANUP; } else { - rval = CCtsp_copy_lpclique (&clist[slist[i].name - ecount], - b->clique); + rval = CCtsp_copy_lpclique(&clist[slist[i].name - ecount], b->clique); } if (!b->clique || rval) { - fprintf (stderr, "CCtsp_copy_clique failed\n"); + fprintf(stderr, "CCtsp_copy_clique failed\n"); for (i = 0; i < k; i++) { if ((*bobj)[i].clique) { - CCtsp_free_lpclique ((*bobj)[i].clique); - CC_IFFREE ((*bobj)[i].clique, CCtsp_lpclique); + CCtsp_free_lpclique((*bobj)[i].clique); + CC_IFFREE((*bobj)[i].clique, CCtsp_lpclique); } } - CC_IFFREE (b->clique, CCtsp_lpclique); - CC_FREE (*bobj, CCtsp_branchobj); + CC_IFFREE(b->clique, CCtsp_lpclique); + CC_FREE(*bobj, CCtsp_branchobj); goto CLEANUP; } } @@ -2191,7 +2130,7 @@ static int merge_edge_clique (CCtsp_lp *lp, int nwant, int *ngot, CLEANUP: - CC_IFFREE (slist, sbitem); + CC_IFFREE(slist, sbitem); return rval; } @@ -2364,7 +2303,7 @@ int CCtsp_find_branch_edge (CCtsp_lp *lp, int *n0, int *n1, double *val, fprintf (stderr, "All edges are either branched or fixed\n"); rval = 1; goto CLEANUP; } - + switch (branchtype) { case CCtsp_BRANCH_MIDDLE: *n0 = xlist[2*besti]; @@ -2435,7 +2374,6 @@ static int find_strong_branch (CCtsp_lp *lp, int *n0, int *n1, int silent) } */ - /* static int find_strongbranch_edges (CCtsp_lp *lp, int nwant, int *ngot, int **elist, double **eval, int silent) @@ -2521,7 +2459,7 @@ static int find_strongbranch_edges (CCtsp_lp *lp, int nwant, int *ngot, printf ("Average Edge Value: %f\n", meanval / ((double) ncand)); fflush (stdout); } - + for (i = lpwant - 1, lpcand = 0; i >= 0; i--) { if (slist[i].name != -1) { if (!silent) { @@ -2534,7 +2472,7 @@ static int find_strongbranch_edges (CCtsp_lp *lp, int nwant, int *ngot, candlist[lpcand++] = slist[i].name; } } - + if (lpcand == 0 && !silent) { printf ("WARNING: no edges appeared in strongbranch\n"); goto CLEANUP; @@ -2571,7 +2509,7 @@ static int find_strongbranch_edges (CCtsp_lp *lp, int nwant, int *ngot, printf ("Average Edge Value: %f\n", meanval / ((double) lpcand)); fflush (stdout); } - + for (i = nwant - 1, k = 0; i >= 0; i--) { if (slist[i].name != -1) { k++; @@ -2778,13 +2716,12 @@ static int find_all_candidate_edges (CCtsp_lp *lp, int *ngot, int **list) } */ -static void init_sblist (sbitem *list, int count) -{ +static void init_sblist(sbitem* list, int count) { int i; for (i = 0; i < count; i++) { - list[i].val = -1.0; - list[i].name = -1; + list[i].val = -1.0; + list[i].name = -1; list[i].name2 = -1; list[i].name3 = -1; list[i].name4 = -1; @@ -2792,22 +2729,17 @@ static void init_sblist (sbitem *list, int count) list[count].val = CCtsp_LP_MAXDOUBLE; } -static void insert_sblist (sbitem *list, double val, int name) -{ - insert_sblist4 (list, val, name, -1, -1, -1); -} +static void insert_sblist(sbitem* list, double val, int name) { insert_sblist4(list, val, name, -1, -1, -1); } -static void insert_sblist4 (sbitem *list, double val, int name, int name2, - int name3, int name4) -{ +static void insert_sblist4(sbitem* list, double val, int name, int name2, int name3, int name4) { int k; if (list[0].val < val) { - for (k = 0; list[k+1].val < val; k++) { - list[k] = list[k+1]; + for (k = 0; list[k + 1].val < val; k++) { + list[k] = list[k + 1]; } - list[k].val = val; - list[k].name = name; + list[k].val = val; + list[k].name = name; list[k].name2 = name2; list[k].name3 = name3; list[k].name4 = name4; @@ -2831,7 +2763,7 @@ int CCtsp_find_branch_cliques (CCtsp_lp *lp, int nwant, int longedge_branching, CClp_warmstart *warmstart = (CClp_warmstart *) NULL; CCutil_init_timer (&timer, "Strong cut branch"); - + *ngot = 0; *bcliques = (CCtsp_lpclique *) NULL; if (bval) { @@ -3173,9 +3105,8 @@ static int find_candidate_cliques (CCtsp_lp *lp, int nwant, int *ngot, } */ -static int test_cut_branch (CCtsp_lp *lp, CCtsp_lpclique *c, double *down, - double *up, int iter, int silent, CClp_warmstart *warmstart) -{ +static int test_cut_branch(CCtsp_lp* lp, CCtsp_lpclique* c, double* down, double* up, int iter, int silent, + CClp_warmstart* warmstart) { CCtsp_lprow cr; CCtsp_lpcut_in cu; int nzlist, status; @@ -3185,162 +3116,179 @@ static int test_cut_branch (CCtsp_lp *lp, CCtsp_lpclique *c, double *down, /* series of calls, the calling program should call optimize. */ *down = -CCtsp_LP_MAXDOUBLE; - *up = -CCtsp_LP_MAXDOUBLE; - CCtsp_init_lprow (&cr); + *up = -CCtsp_LP_MAXDOUBLE; + CCtsp_init_lprow(&cr); - CCtsp_init_lpcut_in (&cu); + CCtsp_init_lpcut_in(&cu); cu.cliquecount = 1; cu.cliques = c; - cu.rhs = 2; + cu.rhs = 2; - nzlist = CCtsp_lpcut_in_nzlist (&lp->graph, &cu); - rval = CCtsp_add_nzlist_to_lp (lp, nzlist, 2, 'L', &cr); + nzlist = CCtsp_lpcut_in_nzlist(&lp->graph, &cu); + rval = CCtsp_add_nzlist_to_lp(lp, nzlist, 2, 'L', &cr); if (rval) { - fprintf (stderr, "CCtsp_add_nzlist_to_lp failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_add_nzlist_to_lp failed\n"); + goto CLEANUP; } - rval = CCtsp_add_multiple_rows (lp, &cr); + rval = CCtsp_add_multiple_rows(lp, &cr); if (rval) { - fprintf (stderr, "CCtsp_add_multiple_rows failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_add_multiple_rows failed\n"); + goto CLEANUP; } - CCutil_start_timer (&lp->stats.strongbranch_opt); - - rval = CClp_limited_dualopt (lp->lp, iter, &status, &lp->upperbound); + CCutil_start_timer(&lp->stats.strongbranch_opt); + + rval = CClp_limited_dualopt(lp->lp, iter, &status, &lp->upperbound); if (rval) { - fprintf (stderr, "CClp_limited_dualopt failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_limited_dualopt failed\n"); + goto CLEANUP; } - CCutil_stop_timer (&lp->stats.strongbranch_opt, 0); + CCutil_stop_timer(&lp->stats.strongbranch_opt, 0); if (status == CClp_INFEASIBLE) { if (!silent) { - printf ("Down side of cut branch is infeasible\n"); - fflush (stdout); + printf("Down side of cut branch is infeasible\n"); + fflush(stdout); } *down = lp->upperbound; } else if (status == CClp_UNKNOWN) { if (!silent) { - printf ("Down side information is not available\n"); - fflush (stdout); + printf("Down side information is not available\n"); + fflush(stdout); } *down = lp->lowerbound; } else { - rval = CClp_objval (lp->lp, down); + rval = CClp_objval(lp->lp, down); if (rval) { - fprintf (stderr, "CClp_objval failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_objval failed\n"); + goto CLEANUP; } if (*down > lp->upperbound) *down = lp->upperbound; } - rval = CCtsp_delete_cut (lp, lp->cuts.cutcount); + rval = CCtsp_delete_cut(lp, lp->cuts.cutcount); if (rval) { - fprintf (stderr, "CCtsp_delete_cut failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_delete_cut failed\n"); + goto CLEANUP; } - rval = CClp_load_warmstart (lp->lp, warmstart); + rval = CClp_load_warmstart(lp->lp, warmstart); if (rval) { - fprintf (stderr, "CClp_load_warmstart failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_load_warmstart failed\n"); + goto CLEANUP; } cr.sense[0] = 'G'; cr.rhs[0] = 4.0; - rval = CCtsp_add_multiple_rows (lp, &cr); + rval = CCtsp_add_multiple_rows(lp, &cr); if (rval) { - fprintf (stderr, "CCtsp_add_multiple_rows failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_add_multiple_rows failed\n"); + goto CLEANUP; } - CCutil_start_timer (&lp->stats.strongbranch_opt); - rval = CClp_limited_dualopt (lp->lp, iter, &status, &lp->upperbound); + CCutil_start_timer(&lp->stats.strongbranch_opt); + rval = CClp_limited_dualopt(lp->lp, iter, &status, &lp->upperbound); if (rval) { - fprintf (stderr, "CClp_limited_dualopt failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_limited_dualopt failed\n"); + goto CLEANUP; } - CCutil_stop_timer (&lp->stats.strongbranch_opt, 0); + CCutil_stop_timer(&lp->stats.strongbranch_opt, 0); if (status == CClp_INFEASIBLE) { if (!silent) { - printf ("Up side of cut branch is infeasible\n"); fflush (stdout); + printf("Up side of cut branch is infeasible\n"); + fflush(stdout); } *up = lp->upperbound; } else if (status == CClp_UNKNOWN) { if (!silent) { - printf ("Up side information is not available\n"); fflush (stdout); + printf("Up side information is not available\n"); + fflush(stdout); } *up = lp->lowerbound; } else { - rval = CClp_objval (lp->lp, up); + rval = CClp_objval(lp->lp, up); if (rval) { - fprintf (stderr, "CClp_objval failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_objval failed\n"); + goto CLEANUP; } if (*up > lp->upperbound) *up = lp->upperbound; } - rval = CCtsp_delete_cut (lp, lp->cuts.cutcount); + rval = CCtsp_delete_cut(lp, lp->cuts.cutcount); if (rval) { - fprintf (stderr, "CCtsp_delete_cut failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_delete_cut failed\n"); + goto CLEANUP; } - rval = CClp_load_warmstart (lp->lp, warmstart); + rval = CClp_load_warmstart(lp->lp, warmstart); if (rval) { - fprintf (stderr, "CClp_load_warmstart failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_load_warmstart failed\n"); + goto CLEANUP; } CLEANUP: - CCtsp_free_lprow (&cr); + CCtsp_free_lprow(&cr); return rval; } -int CCtsp_execute_branch (CCtsp_lp *lp, CCtsp_branchobj *b, int silent, - CCrandstate *rstate) -{ - int n0 = -1; - int n1 = -1; - CCtsp_lpclique *c = (CCtsp_lpclique *) NULL; - int rval = 0; +int CCtsp_execute_branch(CCtsp_lp* lp, CCtsp_branchobj* b, int silent, CCrandstate* rstate) { + int n0 = -1; + int n1 = -1; + CCtsp_lpclique* c = (CCtsp_lpclique*)NULL; + int rval = 0; int i, j; if (!b) { - fprintf (stderr, "CCtsp_execute_branch called without a CCtsp_branchobj\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_execute_branch called without a CCtsp_branchobj\n"); + rval = 1; + goto CLEANUP; } if (b->ends[0] != -1) { n0 = b->ends[0]; n1 = b->ends[1]; if (!silent) { - printf ("Branch Edge (%d,%d), to value %d\n", n0, n1, b->rhs); - fflush (stdout); + printf("Branch Edge (%d,%d), to value %d\n", n0, n1, b->rhs); + fflush(stdout); } - if (n0 >= lp->graph.ncount || n0 < 0 || - n1 >= lp->graph.ncount || n1 < 0) { - fprintf (stderr, "CCtsp_execute_branch has invalid nodes\n"); - rval = 1; goto CLEANUP; + if (n0 >= lp->graph.ncount || n0 < 0 || n1 >= lp->graph.ncount || n1 < 0) { + fprintf(stderr, "CCtsp_execute_branch has invalid nodes\n"); + rval = 1; + goto CLEANUP; } if (n0 > n1) { - CC_SWAP (n0, n1, j); + CC_SWAP(n0, n1, j); } - j = CCtsp_find_edge (&lp->graph, n0, n1); - if (j < 0) { - fprintf (stderr, "branching edge is not in the LP edgeset\n"); - rval = 1; goto CLEANUP; + j = CCtsp_find_edge(&lp->graph, n0, n1); + if (j < 0) { + fprintf(stderr, "branching edge is not in the LP edgeset\n"); + rval = 1; + goto CLEANUP; } if (lp->graph.edges[j].fixed) { - fprintf (stderr, "branching edge is fixed to 1 in the LP\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "branching edge is fixed to 1 in the LP\n"); + rval = 1; + goto CLEANUP; } if (lp->graph.edges[j].branch) { - fprintf (stderr, "branching edge has already been branched\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "branching edge has already been branched\n"); + rval = 1; + goto CLEANUP; } if (b->rhs) { - rval = CClp_setbnd (lp->lp, j, 'L', 1.0); + rval = CClp_setbnd(lp->lp, j, 'L', 1.0); if (rval) { - fprintf (stderr, "CClp_setbnd failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CClp_setbnd failed\n"); + rval = 1; + goto CLEANUP; } lp->graph.edges[j].branch = lp->branchdepth + 1; } else { - rval = CClp_setbnd (lp->lp, j, 'U', 0.0); + rval = CClp_setbnd(lp->lp, j, 'U', 0.0); if (rval) { - fprintf (stderr, "CClp_setbnd failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CClp_setbnd failed\n"); + rval = 1; + goto CLEANUP; } lp->graph.edges[j].branch = -(lp->branchdepth + 1); } @@ -3349,128 +3297,138 @@ int CCtsp_execute_branch (CCtsp_lp *lp, CCtsp_branchobj *b, int silent, CCtsp_lpcut_in d; if (!b->clique) { - fprintf (stderr, "CCtsp_branchobj has no edge or clique\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_branchobj has no edge or clique\n"); + rval = 1; + goto CLEANUP; } if (!silent) { - printf ("Branch Clique "); fflush (stdout); + printf("Branch Clique "); + fflush(stdout); for (i = 0; i < b->clique->segcount; i++) { - printf ("%d->%d ", b->clique->nodes[i].lo, - b->clique->nodes[i].hi); - fflush (stdout); + printf("%d->%d ", b->clique->nodes[i].lo, b->clique->nodes[i].hi); + fflush(stdout); } if (b->sense == 'G') { - printf ("to at least %d\n", b->rhs); + printf("to at least %d\n", b->rhs); } else { - printf ("to at most %d\n", b->rhs); + printf("to at most %d\n", b->rhs); } - fflush (stdout); + fflush(stdout); } - c = CC_SAFE_MALLOC (1, CCtsp_lpclique); + c = CC_SAFE_MALLOC(1, CCtsp_lpclique); if (!c) { - fprintf (stderr, "out of memory in CCtsp_execute_branch\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "out of memory in CCtsp_execute_branch\n"); + rval = 1; + goto CLEANUP; } - rval = CCtsp_copy_lpclique (b->clique, c); + rval = CCtsp_copy_lpclique(b->clique, c); if (rval) { - fprintf (stderr, "CCtsp_copy_lpclique failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_copy_lpclique failed\n"); + rval = 1; + goto CLEANUP; } - CCtsp_init_lpcut_in (&d); + CCtsp_init_lpcut_in(&d); d.cliquecount = 1; d.rhs = b->rhs; d.sense = b->sense; d.branch = 1; d.cliques = c; - rval = CCtsp_construct_skeleton (&d, lp->graph.ncount); + rval = CCtsp_construct_skeleton(&d, lp->graph.ncount); if (rval) { - fprintf (stderr, "CCtsp_construct_skeleton failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_construct_skeleton failed\n"); + rval = 1; + goto CLEANUP; } - - CCtsp_init_lprow (&cr); - rval = CCtsp_add_cut (lp, &d, &cr); + + CCtsp_init_lprow(&cr); + rval = CCtsp_add_cut(lp, &d, &cr); if (rval) { - fprintf (stderr, "CCtsp_add_cut failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_add_cut failed\n"); + rval = 1; + goto CLEANUP; } - rval = CCtsp_add_multiple_rows (lp, &cr); + rval = CCtsp_add_multiple_rows(lp, &cr); if (rval) { - fprintf (stderr, "CCtsp_add_multiple_rows failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_add_multiple_rows failed\n"); + rval = 1; + goto CLEANUP; } - CCtsp_free_lprow (&cr); - CCtsp_free_lpcut_in (&d); + CCtsp_free_lprow(&cr); + CCtsp_free_lpcut_in(&d); } - rval = CClp_opt (lp->lp, CClp_METHOD_DUAL); + rval = CClp_opt(lp->lp, CClp_METHOD_DUAL); if (rval == 2) { - rval = CCtsp_infeas_recover (lp, silent, rstate); + rval = CCtsp_infeas_recover(lp, silent, rstate); if (rval == 2) { int tval; if (!silent) { - printf ("Problem is really infeasible (CCtsp_execute_branch)\n"); - fflush (stdout); + printf("Problem is really infeasible (CCtsp_execute_branch)\n"); + fflush(stdout); } -/* Bico Added on February 3, 1998 */ - tval = CCtsp_update_result (lp); + /* Bico Added on February 3, 1998 */ + tval = CCtsp_update_result(lp); if (tval) { - fprintf (stderr, "CCtsp_update_result failed - ignoring\n"); + fprintf(stderr, "CCtsp_update_result failed - ignoring\n"); /* rval = 1; goto CLEANUP; Bico Deleted on October 10, 2003 */ } - CCtsp_free_bigdual (&lp->exact_dual); -/* End Bico */ + CCtsp_free_bigdual(&lp->exact_dual); + /* End Bico */ goto CLEANUP; } else if (rval) { - fprintf (stderr, "CCtsp_infeas_recover failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_infeas_recover failed\n"); + rval = 1; + goto CLEANUP; } } else if (rval) { - fprintf (stderr, "CClp_opt failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CClp_opt failed\n"); + rval = 1; + goto CLEANUP; } - rval = CCtsp_update_result (lp); + rval = CCtsp_update_result(lp); if (rval) { - fprintf (stderr, "CCtsp_update_result failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_update_result failed\n"); + rval = 1; + goto CLEANUP; } - CCtsp_free_bigdual (&lp->exact_dual); + CCtsp_free_bigdual(&lp->exact_dual); CLEANUP: if (rval == 0 || rval == 2) { int sval = 0; - sval = CCutil_reallocrus_count ((void **) &(lp->branchhistory), - lp->branchdepth + 1, sizeof (CCtsp_branchobj)); + sval = CCutil_reallocrus_count((void**)&(lp->branchhistory), lp->branchdepth + 1, + sizeof(CCtsp_branchobj)); if (sval) { - fprintf (stderr, "CCutil_reallocrus_count failed\n"); return 1; + fprintf(stderr, "CCutil_reallocrus_count failed\n"); + return 1; } - CCtsp_init_branchobj (&lp->branchhistory[lp->branchdepth]); - lp->branchhistory[lp->branchdepth].depth = lp->branchdepth + 1; + CCtsp_init_branchobj(&lp->branchhistory[lp->branchdepth]); + lp->branchhistory[lp->branchdepth].depth = lp->branchdepth + 1; lp->branchhistory[lp->branchdepth].ends[0] = n0; lp->branchhistory[lp->branchdepth].ends[1] = n1; - lp->branchhistory[lp->branchdepth].rhs = b->rhs; + lp->branchhistory[lp->branchdepth].rhs = b->rhs; if (b->clique) { - c = CC_SAFE_MALLOC (1, CCtsp_lpclique); + c = CC_SAFE_MALLOC(1, CCtsp_lpclique); if (!c) { - fprintf (stderr, "out of memory in CCtsp_execute_branch\n"); + fprintf(stderr, "out of memory in CCtsp_execute_branch\n"); return 1; } - sval = CCtsp_copy_lpclique (b->clique, c); + sval = CCtsp_copy_lpclique(b->clique, c); if (sval) { - fprintf (stderr, "CCtsp_copy_lpclique failed\n"); return 1; + fprintf(stderr, "CCtsp_copy_lpclique failed\n"); + return 1; } lp->branchhistory[lp->branchdepth].clique = c; } else { - lp->branchhistory[lp->branchdepth].clique = - (CCtsp_lpclique *) NULL; + lp->branchhistory[lp->branchdepth].clique = (CCtsp_lpclique*)NULL; } lp->branchhistory[lp->branchdepth].sense = b->sense; lp->branchdepth++; @@ -3478,201 +3436,219 @@ int CCtsp_execute_branch (CCtsp_lp *lp, CCtsp_branchobj *b, int silent, return rval; } -int CCtsp_execute_unbranch (CCtsp_lp *lp, CClp_warmstart *warmstart, - int silent, CCrandstate *rstate) -{ +int CCtsp_execute_unbranch(CCtsp_lp* lp, CClp_warmstart* warmstart, int silent, CCrandstate* rstate) { int rval = 0; int n0, n1; int num; int depth = lp->branchdepth; - CCtsp_branchobj *b; + CCtsp_branchobj* b; int j; if (depth <= 0) { - fprintf (stderr, "CCtsp_execute_unbranch called at depth 0\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_execute_unbranch called at depth 0\n"); + rval = 1; + goto CLEANUP; } if (lp->branchhistory[depth - 1].depth != depth) { - fprintf (stderr, "branchhistory is corrupted\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "branchhistory is corrupted\n"); + rval = 1; + goto CLEANUP; } b = &lp->branchhistory[depth - 1]; if (lp->branchhistory[depth - 1].ends[0] != -1) { - n0 = b->ends[0]; - n1 = b->ends[1]; + n0 = b->ends[0]; + n1 = b->ends[1]; if (!silent) { - printf ("Unbranch Edge (%d,%d), from value %d\n", n0, n1, b->rhs); - fflush (stdout); + printf("Unbranch Edge (%d,%d), from value %d\n", n0, n1, b->rhs); + fflush(stdout); } if (n0 > n1) { - CC_SWAP (n0, n1, j); + CC_SWAP(n0, n1, j); } - j = CCtsp_find_edge (&lp->graph, n0, n1); - if (j < 0) { - fprintf (stderr, "ERROR: unbranching 1-edge is not in LP\n"); - rval = 1; goto CLEANUP; + j = CCtsp_find_edge(&lp->graph, n0, n1); + if (j < 0) { + fprintf(stderr, "ERROR: unbranching 1-edge is not in LP\n"); + rval = 1; + goto CLEANUP; } if (b->rhs) { if (lp->graph.edges[j].branch <= 0) { - fprintf (stderr, "unbranching 1-edge not branched to 1\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "unbranching 1-edge not branched to 1\n"); + rval = 1; + goto CLEANUP; } - rval = CClp_setbnd (lp->lp, j, 'L', 0.0); + rval = CClp_setbnd(lp->lp, j, 'L', 0.0); if (rval) { - fprintf (stderr, "CClp_setbnd failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CClp_setbnd failed\n"); + rval = 1; + goto CLEANUP; } } else { if (lp->graph.edges[j].branch >= 0) { - fprintf (stderr, "unbranching 0-edge not branched to 0\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "unbranching 0-edge not branched to 0\n"); + rval = 1; + goto CLEANUP; } - rval = CClp_setbnd (lp->lp, j, 'U', 1.0); + rval = CClp_setbnd(lp->lp, j, 'U', 1.0); if (rval) { - fprintf (stderr, "CClp_setbnd failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CClp_setbnd failed\n"); + rval = 1; + goto CLEANUP; } } lp->graph.edges[j].branch = 0; } else { if (!b->clique) { - fprintf (stderr, "branchhistory has no edge or clique\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "branchhistory has no edge or clique\n"); + rval = 1; + goto CLEANUP; } - rval = find_branched_clique (lp, b->clique, b->sense, b->rhs, &num); + rval = find_branched_clique(lp, b->clique, b->sense, b->rhs, &num); if (rval) { - fprintf (stderr, "find_branched_clique failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "find_branched_clique failed\n"); + rval = 1; + goto CLEANUP; } if (!silent) { - printf ("The unbranching clique is cut %d\n", num); fflush (stdout); - } + printf("The unbranching clique is cut %d\n", num); + fflush(stdout); + } if (lp->cuts.cuts[num].branch == 0) { - fprintf (stderr, "the unbranching clique is not set to branch\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "the unbranching clique is not set to branch\n"); + rval = 1; + goto CLEANUP; } if (!silent) { int q; - CCtsp_lpcut *cu = &lp->cuts.cuts[num]; - CCtsp_lpclique *t; + CCtsp_lpcut* cu = &lp->cuts.cuts[num]; + CCtsp_lpclique* t; - printf ("Sense: %c RHS: %d Cliques: %d Branch: %d\n", - cu->sense, cu->rhs, cu->cliquecount, cu->branch); + printf("Sense: %c RHS: %d Cliques: %d Branch: %d\n", cu->sense, cu->rhs, cu->cliquecount, + cu->branch); t = &lp->cuts.cliques[cu->cliques[0]]; - printf ("Clique: "); + printf("Clique: "); for (q = 0; q < t->segcount; q++) { - printf ("%d->%d ", t->nodes[q].lo, t->nodes[q].hi); + printf("%d->%d ", t->nodes[q].lo, t->nodes[q].hi); } - printf ("\n"); fflush (stdout); + printf("\n"); + fflush(stdout); } - rval = CCtsp_delete_cut (lp, num); + rval = CCtsp_delete_cut(lp, num); if (rval) { - fprintf (stderr, "CCtsp_delete_cut failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_delete_cut failed\n"); + rval = 1; + goto CLEANUP; } - CCtsp_delete_cut_from_cutlist (&lp->cuts, num); + CCtsp_delete_cut_from_cutlist(&lp->cuts, num); } if (warmstart) { - rval = CClp_load_warmstart (lp->lp, warmstart); + rval = CClp_load_warmstart(lp->lp, warmstart); if (rval) { - fprintf (stderr, "CClp_load_warmstart failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CClp_load_warmstart failed\n"); + rval = 1; + goto CLEANUP; } } - rval = CClp_opt (lp->lp, CClp_METHOD_DUAL); + rval = CClp_opt(lp->lp, CClp_METHOD_DUAL); -/* Bico Added on February 3, 1998 */ + /* Bico Added on February 3, 1998 */ if (rval == 2) { - fprintf (stderr, "infeasible lp in CCtsp_execute_unbranch\n"); - rval = CCtsp_infeas_recover (lp, silent, rstate); + fprintf(stderr, "infeasible lp in CCtsp_execute_unbranch\n"); + rval = CCtsp_infeas_recover(lp, silent, rstate); if (rval == 2) { int tval; if (!silent) { - printf ("Problem is really infeasible (CCtsp_execute_unbranch)\n"); - fflush (stdout); + printf("Problem is really infeasible (CCtsp_execute_unbranch)\n"); + fflush(stdout); } - tval = CCtsp_update_result (lp); + tval = CCtsp_update_result(lp); if (tval) { - fprintf (stderr, "CCtsp_update_result failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_update_result failed\n"); + rval = 1; + goto CLEANUP; } - CCtsp_free_bigdual (&lp->exact_dual); + CCtsp_free_bigdual(&lp->exact_dual); goto CLEANUP; } else if (rval) { - fprintf (stderr, "CCtsp_infeas_recover failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_infeas_recover failed\n"); + rval = 1; + goto CLEANUP; } -/* End Bico */ + /* End Bico */ } else if (rval) { - fprintf (stderr, "CClp_opt failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_opt failed\n"); + goto CLEANUP; } - rval = CCtsp_update_result (lp); + rval = CCtsp_update_result(lp); if (rval) { - fprintf (stderr, "CCtsp_update_result failed\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "CCtsp_update_result failed\n"); + rval = 1; + goto CLEANUP; } - CCtsp_free_bigdual (&lp->exact_dual); + CCtsp_free_bigdual(&lp->exact_dual); CLEANUP: if (!rval || rval == 2) { - CCtsp_free_branchobj (&lp->branchhistory[lp->branchdepth - 1]); + CCtsp_free_branchobj(&lp->branchhistory[lp->branchdepth - 1]); lp->branchdepth--; } return rval; } -int CCtsp_add_branchhistory_to_lp (CCtsp_lp *lp) -{ +int CCtsp_add_branchhistory_to_lp(CCtsp_lp* lp) { int i, k, num; int rval = 0; - CCtsp_branchobj *b; + CCtsp_branchobj* b; for (i = 0; i < lp->branchdepth; i++) { b = &lp->branchhistory[i]; if (b->ends[0] != -1) { if (lp->graph.ecount == 0) { - printf ("No graph - can't add edge %d,%d = %d from branch history\n", - b->ends[0], b->ends[1], b->rhs); + printf("No graph - can't add edge %d,%d = %d from branch history\n", b->ends[0], b->ends[1], + b->rhs); } else { - k = CCtsp_find_edge (&lp->graph, b->ends[0], b->ends[1]); + k = CCtsp_find_edge(&lp->graph, b->ends[0], b->ends[1]); if (k == -1) { - fprintf (stderr, "edge in branch history is not in LP\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "edge in branch history is not in LP\n"); + rval = 1; + goto CLEANUP; } if (lp->graph.edges[k].fixed || lp->graph.edges[k].branch) { - fprintf (stderr, "edge in branch history is fixed/branched\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "edge in branch history is fixed/branched\n"); + rval = 1; + goto CLEANUP; } if (b->rhs) { - rval = CClp_setbnd (lp->lp, k, 'L', 1.0); + rval = CClp_setbnd(lp->lp, k, 'L', 1.0); if (rval) { - fprintf (stderr, "CClp_setbnd failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_setbnd failed\n"); + goto CLEANUP; } lp->graph.edges[k].branch = b->depth; } else { - rval = CClp_setbnd (lp->lp, k, 'U', 0.0); + rval = CClp_setbnd(lp->lp, k, 'U', 0.0); if (rval) { - fprintf (stderr, "CClp_setbnd failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_setbnd failed\n"); + goto CLEANUP; } lp->graph.edges[k].branch = -(b->depth); } } } else { - rval = find_branched_clique (lp, b->clique, b->sense, - b->rhs, &num); + rval = find_branched_clique(lp, b->clique, b->sense, b->rhs, &num); if (rval) { - fprintf (stderr, "find_branch_clique failed\n"); + fprintf(stderr, "find_branch_clique failed\n"); goto CLEANUP; } lp->cuts.cuts[num].branch = 1; @@ -3684,28 +3660,25 @@ int CCtsp_add_branchhistory_to_lp (CCtsp_lp *lp) return rval; } -static int find_branched_clique (CCtsp_lp *lp, CCtsp_lpclique *c, char sense, - int rhs, int *cutnum) -{ +static int find_branched_clique(CCtsp_lp* lp, CCtsp_lpclique* c, char sense, int rhs, int* cutnum) { int i; - CCtsp_lpcut *cu; - CCtsp_lpcut *cuts = lp->cuts.cuts; - CCtsp_lpclique *cliques = lp->cuts.cliques; - int cutcount = lp->cuts.cutcount; + CCtsp_lpcut* cu; + CCtsp_lpcut* cuts = lp->cuts.cuts; + CCtsp_lpclique* cliques = lp->cuts.cliques; + int cutcount = lp->cuts.cutcount; int diff = 0; *cutnum = -1; for (i = 0; i < cutcount; i++) { cu = &cuts[i]; - if (cu->cliquecount == 1 && - cu->sense == sense && cu->rhs == rhs) { - CCtsp_lpclique_compare (&cliques[cu->cliques[0]], c, &diff); + if (cu->cliquecount == 1 && cu->sense == sense && cu->rhs == rhs) { + CCtsp_lpclique_compare(&cliques[cu->cliques[0]], c, &diff); if (!diff) { if (*cutnum == -1) { *cutnum = i; } else { - fprintf (stderr, "two copies of branched clique\n"); + fprintf(stderr, "two copies of branched clique\n"); return 1; } } @@ -3713,7 +3686,7 @@ static int find_branched_clique (CCtsp_lp *lp, CCtsp_lpclique *c, char sense, } if (*cutnum == -1) { - fprintf (stderr, "did not find branched clique\n"); + fprintf(stderr, "did not find branched clique\n"); return 1; } else { return 0; @@ -3862,12 +3835,11 @@ int CCtsp_bb_splitprob (char *probname, int probnum, int ncount, } */ -static int branch_side (CCtsp_lp *lp, CCtsp_branchobj *b, int side, int child, - double *val, int *prune, int silent, CCrandstate *rstate) -{ +static int branch_side(CCtsp_lp* lp, CCtsp_branchobj* b, int side, int child, double* val, int* prune, + int silent, CCrandstate* rstate) { int rval = 0; - int oldid = lp->id; - int oldparent = lp->parent_id; + int oldid = lp->id; + int oldparent = lp->parent_id; double oldbound = lp->lowerbound; double newbound; int test; @@ -3877,9 +3849,9 @@ static int branch_side (CCtsp_lp *lp, CCtsp_branchobj *b, int side, int child, if (b->ends[0] != -1) { if (!silent) { - printf ("Creating child %d of LP %d: Set Edge (%d, %d) to %d\n", - side, lp->id, b->ends[0], b->ends[1], side); - fflush (stdout); + printf("Creating child %d of LP %d: Set Edge (%d, %d) to %d\n", side, lp->id, b->ends[0], + b->ends[1], side); + fflush(stdout); } if (side == 0) { b->rhs = 0; @@ -3889,80 +3861,85 @@ static int branch_side (CCtsp_lp *lp, CCtsp_branchobj *b, int side, int child, } else { if (side == 0) { if (!silent) { - printf ("Creating child 0 of LP %d: Set Clique <= 2\n", lp->id); - fflush (stdout); + printf("Creating child 0 of LP %d: Set Clique <= 2\n", lp->id); + fflush(stdout); } - b->rhs = 2; b->sense = 'L'; + b->rhs = 2; + b->sense = 'L'; } else { if (!silent) { - printf ("Creating child 1 of LP %d: Set Clique >= 4\n", lp->id); - fflush (stdout); + printf("Creating child 1 of LP %d: Set Clique >= 4\n", lp->id); + fflush(stdout); } - b->rhs = 4; b->sense = 'G'; + b->rhs = 4; + b->sense = 'G'; } } - fflush (stdout); + fflush(stdout); - rval = CCtsp_execute_branch (lp, b, silent, rstate); + rval = CCtsp_execute_branch(lp, b, silent, rstate); if (rval && rval != 2) { - fprintf (stderr, "CCtsp_execute_branch failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_execute_branch failed\n"); + goto CLEANUP; } else if (rval == 2) { - printf ("Branched-LP is infeasible\n"); fflush (stdout); - rval = CCtsp_verify_infeasible_lp (lp, &test, silent); + printf("Branched-LP is infeasible\n"); + fflush(stdout); + rval = CCtsp_verify_infeasible_lp(lp, &test, silent); if (rval) { - fprintf (stderr, "CCtsp_verify_infeasible_lp failed\n"); + fprintf(stderr, "CCtsp_verify_infeasible_lp failed\n"); goto CLEANUP; } if (test) { if (!silent) { - printf ("Creating child leafnode - infeasible\n"); - fflush (stdout); + printf("Creating child leafnode - infeasible\n"); + fflush(stdout); } *val = CCtsp_LP_MAXDOUBLE; *prune = 1; lp->parent_id = oldid; lp->id = child; - rval = CCtsp_write_probleaf_id (lp); + rval = CCtsp_write_probleaf_id(lp); if (rval) { - fprintf (stderr, "CCtsp_write_probleaf_id failed\n"); + fprintf(stderr, "CCtsp_write_probleaf_id failed\n"); goto CLEANUP; } rval = 0; } else { - fprintf (stderr, "did not verify an infeasible LP\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "did not verify an infeasible LP\n"); + rval = 1; + goto CLEANUP; } } else { - rval = CCtsp_pricing_loop (lp, &newbound, silent, rstate); - CCcheck_rval (rval, "CCtsp_pricing_loop failed"); + rval = CCtsp_pricing_loop(lp, &newbound, silent, rstate); + CCcheck_rval(rval, "CCtsp_pricing_loop failed"); *val = newbound; lp->lowerbound = newbound; if (lp->lowerbound >= lp->upperbound - 0.9) { - rval = CCtsp_verify_lp_prune (lp, &test, silent); - CCcheck_rval (rval, "CCtsp_verify_lp_prune failed"); + rval = CCtsp_verify_lp_prune(lp, &test, silent); + CCcheck_rval(rval, "CCtsp_verify_lp_prune failed"); if (test) { if (!silent) { - printf ("verified that child can be pruned\n"); - fflush (stdout); + printf("verified that child can be pruned\n"); + fflush(stdout); } *prune = 1; lp->parent_id = oldid; lp->id = child; - rval = CCtsp_write_probleaf_id (lp); - CCcheck_rval (rval,"CCtsp_write_probleaf_id failed"); + rval = CCtsp_write_probleaf_id(lp); + CCcheck_rval(rval, "CCtsp_write_probleaf_id failed"); } else { - printf ("exact pricing could not prune child\n"); - fflush (stdout); + printf("exact pricing could not prune child\n"); + fflush(stdout); } } if (*prune == 0) { lp->parent_id = oldid; lp->id = child; - rval = CCtsp_write_probfile_id (lp); - CCcheck_rval (rval, "CCtsp_write_probfile_id failed"); + rval = CCtsp_write_probfile_id(lp); + CCcheck_rval(rval, "CCtsp_write_probfile_id failed"); lp->parent_id = oldparent; lp->id = oldid; } @@ -3975,17 +3952,17 @@ static int branch_side (CCtsp_lp *lp, CCtsp_branchobj *b, int side, int child, return rval; } -int CCtsp_splitprob (CCtsp_lp *lp, CCtsp_branchobj *b, int child0, int child1, - int silent, CCrandstate *rstate) -{ - int oldid = lp->id; - int oldparent = lp->parent_id; - CClp_warmstart *warmstart = (CClp_warmstart *) NULL; +int CCtsp_splitprob(CCtsp_lp* lp, CCtsp_branchobj* b, int child0, int child1, int silent, + CCrandstate* rstate) { + int oldid = lp->id; + int oldparent = lp->parent_id; + CClp_warmstart* warmstart = (CClp_warmstart*)NULL; int rval = 0; - rval = CClp_get_warmstart (lp->lp, &warmstart); + rval = CClp_get_warmstart(lp->lp, &warmstart); if (rval) { - fprintf (stderr, "CClp_get_warmstart failed\n"); goto CLEANUP; + fprintf(stderr, "CClp_get_warmstart failed\n"); + goto CLEANUP; } lp->parent_id = lp->id; @@ -3998,21 +3975,24 @@ int CCtsp_splitprob (CCtsp_lp *lp, CCtsp_branchobj *b, int child0, int child1, } lp->id = child0; - rval = CCtsp_execute_branch (lp, b, silent, rstate); + rval = CCtsp_execute_branch(lp, b, silent, rstate); if (rval == 2) { rval = 0; - printf ("The down side of the branch was infeasible\n"); - fflush (stdout); + printf("The down side of the branch was infeasible\n"); + fflush(stdout); } else if (rval) { - fprintf (stderr, "CCtsp_execute_branch failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_execute_branch failed\n"); + goto CLEANUP; } - rval = CCtsp_write_probfile_id (lp); + rval = CCtsp_write_probfile_id(lp); if (rval) { - fprintf (stderr, "CCtsp_write_probfile_id failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_write_probfile_id failed\n"); + goto CLEANUP; } - rval = CCtsp_execute_unbranch (lp, warmstart, silent, rstate); + rval = CCtsp_execute_unbranch(lp, warmstart, silent, rstate); if (rval) { - fprintf (stderr, "CCtsp_execute_unbranch failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_execute_unbranch failed\n"); + goto CLEANUP; } if (b->ends[0] != -1) { @@ -4023,58 +4003,61 @@ int CCtsp_splitprob (CCtsp_lp *lp, CCtsp_branchobj *b, int child0, int child1, } lp->id = child1; - rval = CCtsp_execute_branch (lp, b, silent, rstate); + rval = CCtsp_execute_branch(lp, b, silent, rstate); if (rval == 2) { rval = 0; - printf ("The up side of the branch was infeasible\n"); - fflush (stdout); + printf("The up side of the branch was infeasible\n"); + fflush(stdout); } else if (rval) { - fprintf (stderr, "CCtsp_execute_branch failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_execute_branch failed\n"); + goto CLEANUP; } - rval = CCtsp_write_probfile_id (lp); + rval = CCtsp_write_probfile_id(lp); if (rval) { - fprintf (stderr, "CCtsp_write_probfile_id failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_write_probfile_id failed\n"); + goto CLEANUP; } - rval = CCtsp_execute_unbranch (lp, warmstart, silent, rstate); + rval = CCtsp_execute_unbranch(lp, warmstart, silent, rstate); if (rval) { - fprintf (stderr, "CCtsp_execute_unbranch failed\n"); goto CLEANUP; + fprintf(stderr, "CCtsp_execute_unbranch failed\n"); + goto CLEANUP; } - CLEANUP: - CClp_free_warmstart (&warmstart); + CClp_free_warmstart(&warmstart); lp->parent_id = oldparent; lp->id = oldid; return rval; } -int CCtsp_dumptour (int ncount, CCdatagroup *dat, int *perm, char *probname, - int *tour, char *fname, int writeedges, int silent) -{ +int CCtsp_dumptour(int ncount, CCdatagroup* dat, int* perm, char* probname, int* tour, char* fname, + int writeedges, int silent) { int rval = 0; - int *cyc = (int *) NULL; + int* cyc = (int*)NULL; int i; double len = 0.0; - FILE *fout = (FILE *) NULL; + FILE* fout = (FILE*)NULL; char buf[1024]; if (!perm || !tour) { - fprintf (stderr, "bad input for CCtsp_dumptour\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "bad input for CCtsp_dumptour\n"); + rval = 1; + goto CLEANUP; } if (!fname) { - sprintf (buf, "%s.sol", probname); + sprintf(buf, "%s.sol", probname); } else { - sprintf (buf, "%s", fname); + sprintf(buf, "%s", fname); } - cyc = CC_SAFE_MALLOC (ncount, int); + cyc = CC_SAFE_MALLOC(ncount, int); if (!cyc) { - fprintf (stderr, "out of memory in CCtsp_dumptour\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "out of memory in CCtsp_dumptour\n"); + rval = 1; + goto CLEANUP; } for (i = 0; i < ncount; i++) { @@ -4085,8 +4068,9 @@ int CCtsp_dumptour (int ncount, CCdatagroup *dat, int *perm, char *probname, } for (i = 0; i < ncount; i++) { if (cyc[i] == 0) { - fprintf (stderr, "array is not a tour in CCtsp_dumptour\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "array is not a tour in CCtsp_dumptour\n"); + rval = 1; + goto CLEANUP; } } for (i = 0; i < ncount; i++) { @@ -4095,47 +4079,51 @@ int CCtsp_dumptour (int ncount, CCdatagroup *dat, int *perm, char *probname, if (dat) { for (i = 1; i < ncount; i++) { - len += (double) CCutil_dat_edgelen (tour[i-1], tour[i], dat); + len += (double)CCutil_dat_edgelen(tour[i - 1], tour[i], dat); } - len += (double) CCutil_dat_edgelen (tour[ncount-1], tour[0], dat); + len += (double)CCutil_dat_edgelen(tour[ncount - 1], tour[0], dat); if (!silent) { - printf ("Write tour of length %.2f to %s\n", len, buf); - fflush (stdout); + printf("Write tour of length %.2f to %s\n", len, buf); + fflush(stdout); } } else { if (!silent) { - printf ("Write tour to %s\n", buf); fflush (stdout); + printf("Write tour to %s\n", buf); + fflush(stdout); } } if (!writeedges) { - rval = CCutil_writecycle (ncount, buf, cyc, 0); + rval = CCutil_writecycle(ncount, buf, cyc, 0); if (rval) { - fprintf (stderr, "CCutil_writecycle failed\n"); goto CLEANUP; + fprintf(stderr, "CCutil_writecycle failed\n"); + goto CLEANUP; } } else { if (!dat) { - fprintf (stderr, "need datagroup to write edge file\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "need datagroup to write edge file\n"); + rval = 1; + goto CLEANUP; } else { - fout = fopen (buf, "w"); - if (fout == (FILE *) NULL) { - perror (buf); - fprintf (stderr, "Unable to open %s for output\n", buf); - rval = 1; goto CLEANUP; + fout = fopen(buf, "w"); + if (fout == (FILE*)NULL) { + perror(buf); + fprintf(stderr, "Unable to open %s for output\n", buf); + rval = 1; + goto CLEANUP; } - fprintf (fout, "%d %d\n", ncount, ncount); + fprintf(fout, "%d %d\n", ncount, ncount); for (i = 1; i < ncount; i++) { - fprintf (fout, "%d %d %d\n", cyc[i-1], cyc[i], - CCutil_dat_edgelen (tour[i-1], tour[i], dat)); + fprintf(fout, "%d %d %d\n", cyc[i - 1], cyc[i], + CCutil_dat_edgelen(tour[i - 1], tour[i], dat)); } - fprintf (fout, "%d %d %d\n", cyc[ncount - 1], cyc[0], - CCutil_dat_edgelen (tour[ncount - 1], tour[0], dat)); + fprintf(fout, "%d %d %d\n", cyc[ncount - 1], cyc[0], + CCutil_dat_edgelen(tour[ncount - 1], tour[0], dat)); } } CLEANUP: - CC_IFFREE (cyc, int); + CC_IFFREE(cyc, int); return rval; } diff --git a/tsp/src/edgelen.c b/tsp/src/edgelen.c index ad24632..9123abd 100644 --- a/tsp/src/edgelen.c +++ b/tsp/src/edgelen.c @@ -115,54 +115,36 @@ /****************************************************************************/ #include "machdefs.h" -#include "util.h" #include "macrorus.h" +#include "util.h" +static double dtrunc(double); -static double - dtrunc (double); - -static int - edgelen_nonorm (int i, int j, CCdatagroup *dat), - max_edgelen (int i, int j, CCdatagroup *dat), - man_edgelen (int i, int j, CCdatagroup *dat), - euclid_edgelen (int i, int j, CCdatagroup *dat), - euclid_ceiling_edgelen (int i, int j, CCdatagroup *dat), - euclid3d_edgelen (int i, int j, CCdatagroup *dat), - geographic_edgelen (int i, int j, CCdatagroup *dat), - geom_edgelen (int i, int j, CCdatagroup *dat), - att_edgelen (int i, int j, CCdatagroup *dat), - dsjrand_edgelen (int i, int j, CCdatagroup *dat), - crystal_edgelen (int i, int j, CCdatagroup *dat), - matrix_edgelen (int i, int j, CCdatagroup *dat), - sparse_edgelen (int i, int j, CCdatagroup *dat), - user_edgelen (int i, int j, CCdatagroup *dat), - rhmap1_edgelen (int i, int j, CCdatagroup *dat), - rhmap2_edgelen (int i, int j, CCdatagroup *dat), - rhmap3_edgelen (int i, int j, CCdatagroup *dat), - rhmap4_edgelen (int i, int j, CCdatagroup *dat), - rhmap5_edgelen (int i, int j, CCdatagroup *dat), - toroidal_edgelen (int i, int j, CCdatagroup *dat); - -static void - init_userdat (CCdata_user *userdat), - free_userdat (CCdata_user *userdat), - init_rhdata (CCdata_rhvector *rhdat), - free_rhdata (CCdata_rhvector *rhdat); +static int edgelen_nonorm(int i, int j, CCdatagroup* dat), max_edgelen(int i, int j, CCdatagroup* dat), + man_edgelen(int i, int j, CCdatagroup* dat), euclid_edgelen(int i, int j, CCdatagroup* dat), + euclid_ceiling_edgelen(int i, int j, CCdatagroup* dat), euclid3d_edgelen(int i, int j, CCdatagroup* dat), + geographic_edgelen(int i, int j, CCdatagroup* dat), geom_edgelen(int i, int j, CCdatagroup* dat), + att_edgelen(int i, int j, CCdatagroup* dat), dsjrand_edgelen(int i, int j, CCdatagroup* dat), + crystal_edgelen(int i, int j, CCdatagroup* dat), matrix_edgelen(int i, int j, CCdatagroup* dat), + sparse_edgelen(int i, int j, CCdatagroup* dat), user_edgelen(int i, int j, CCdatagroup* dat), + rhmap1_edgelen(int i, int j, CCdatagroup* dat), rhmap2_edgelen(int i, int j, CCdatagroup* dat), + rhmap3_edgelen(int i, int j, CCdatagroup* dat), rhmap4_edgelen(int i, int j, CCdatagroup* dat), + rhmap5_edgelen(int i, int j, CCdatagroup* dat), toroidal_edgelen(int i, int j, CCdatagroup* dat); +static void init_userdat(CCdata_user* userdat), free_userdat(CCdata_user* userdat), + init_rhdata(CCdata_rhvector* rhdat), free_rhdata(CCdata_rhvector* rhdat); #ifndef M_PI #define M_PI 3.14159265358979323846264 #endif -#ifdef CCUTIL_EDGELEN_FUNCTIONPTR +#ifdef CCUTIL_EDGELEN_FUNCTIONPTR -int (*CCutil_dat_edgelen) (int i, int j, CCdatagroup *dat) = edgelen_nonorm; +int (*CCutil_dat_edgelen)(int i, int j, CCdatagroup* dat) = edgelen_nonorm; #else /* CCUTIL_EDGELEN_FUNCTIONPTR */ -int CCutil_dat_edgelen (int i, int j, CCdatagroup *dat) -{ +int CCutil_dat_edgelen(int i, int j, CCdatagroup* dat) { if (dat->ndepot) { if (i >= dat->orig_ncount) { return dat->depotcost[j]; @@ -175,70 +157,68 @@ int CCutil_dat_edgelen (int i, int j, CCdatagroup *dat) #endif /* CCUTIL_EDGELEN_FUNCTIONPTR */ - -int CCutil_dat_setnorm (CCdatagroup *dat, int norm) -{ +int CCutil_dat_setnorm(CCdatagroup* dat, int norm) { switch (norm) { - case CC_EUCLIDEAN_CEIL: - dat->edgelen = euclid_ceiling_edgelen; - break; - case CC_EUCLIDEAN: - dat->edgelen = euclid_edgelen; - break; - case CC_MAXNORM: - dat->edgelen = max_edgelen; - break; - case CC_MANNORM: - dat->edgelen = man_edgelen; - break; - case CC_EUCLIDEAN_3D: - dat->edgelen = euclid3d_edgelen; - break; - case CC_USER: - dat->edgelen = user_edgelen; - break; - case CC_GEOGRAPHIC: - dat->edgelen = geographic_edgelen; - break; - case CC_GEOM: - dat->edgelen = geom_edgelen; - break; - case CC_ATT: - dat->edgelen = att_edgelen; - break; - case CC_MATRIXNORM: - dat->edgelen = matrix_edgelen; - break; - case CC_DSJRANDNORM: - dat->edgelen = dsjrand_edgelen; - break; - case CC_CRYSTAL: - dat->edgelen = crystal_edgelen; - break; - case CC_SPARSE: - dat->edgelen = sparse_edgelen; - break; - case CC_RHMAP1: - dat->edgelen = rhmap1_edgelen; - break; - case CC_RHMAP2: - dat->edgelen = rhmap2_edgelen; - break; - case CC_RHMAP3: - dat->edgelen = rhmap3_edgelen; - break; - case CC_RHMAP4: - dat->edgelen = rhmap4_edgelen; - break; - case CC_RHMAP5: - dat->edgelen = rhmap5_edgelen; - break; - case CC_EUCTOROIDAL: - dat->edgelen = toroidal_edgelen; - break; - default: - fprintf (stderr, "ERROR: Unknown NORM %d.\n", norm); - return 1; + case CC_EUCLIDEAN_CEIL: + dat->edgelen = euclid_ceiling_edgelen; + break; + case CC_EUCLIDEAN: + dat->edgelen = euclid_edgelen; + break; + case CC_MAXNORM: + dat->edgelen = max_edgelen; + break; + case CC_MANNORM: + dat->edgelen = man_edgelen; + break; + case CC_EUCLIDEAN_3D: + dat->edgelen = euclid3d_edgelen; + break; + case CC_USER: + dat->edgelen = user_edgelen; + break; + case CC_GEOGRAPHIC: + dat->edgelen = geographic_edgelen; + break; + case CC_GEOM: + dat->edgelen = geom_edgelen; + break; + case CC_ATT: + dat->edgelen = att_edgelen; + break; + case CC_MATRIXNORM: + dat->edgelen = matrix_edgelen; + break; + case CC_DSJRANDNORM: + dat->edgelen = dsjrand_edgelen; + break; + case CC_CRYSTAL: + dat->edgelen = crystal_edgelen; + break; + case CC_SPARSE: + dat->edgelen = sparse_edgelen; + break; + case CC_RHMAP1: + dat->edgelen = rhmap1_edgelen; + break; + case CC_RHMAP2: + dat->edgelen = rhmap2_edgelen; + break; + case CC_RHMAP3: + dat->edgelen = rhmap3_edgelen; + break; + case CC_RHMAP4: + dat->edgelen = rhmap4_edgelen; + break; + case CC_RHMAP5: + dat->edgelen = rhmap5_edgelen; + break; + case CC_EUCTOROIDAL: + dat->edgelen = toroidal_edgelen; + break; + default: + fprintf(stderr, "ERROR: Unknown NORM %d.\n", norm); + return 1; } dat->norm = norm; @@ -249,19 +229,15 @@ int CCutil_dat_setnorm (CCdatagroup *dat, int norm) return 0; } -void CCutil_dat_getnorm (CCdatagroup *dat, int *norm) -{ - (*norm) = dat->norm; -} +void CCutil_dat_getnorm(CCdatagroup* dat, int* norm) { (*norm) = dat->norm; } -static int edgelen_nonorm (int i, int j, CCdatagroup *dat) -{ - fprintf (stderr, "CCutil_dat_edgelen has been called with no norm set\n"); - fprintf (stderr, "This is a FATAL ERROR\n"); - if (i != 0 || j != 0 || dat != (CCdatagroup *) NULL) { +static int edgelen_nonorm(int i, int j, CCdatagroup* dat) { + fprintf(stderr, "CCutil_dat_edgelen has been called with no norm set\n"); + fprintf(stderr, "This is a FATAL ERROR\n"); + if (i != 0 || j != 0 || dat != (CCdatagroup*)NULL) { /* so the compiler won't complain about unused variables */ - fprintf (stderr, "This is a FATAL ERROR\n"); - exit (1); + fprintf(stderr, "This is a FATAL ERROR\n"); + exit(1); } return -1; } @@ -269,44 +245,35 @@ static int edgelen_nonorm (int i, int j, CCdatagroup *dat) /* Several variables that would normally be called y1 and y2 are called yy1 and yy2 to avoid conflict with the bessel functions */ -static int max_edgelen (int i, int j, CCdatagroup *dat) -{ +static int max_edgelen(int i, int j, CCdatagroup* dat) { double t1 = dat->x[i] - dat->x[j], t2 = dat->y[i] - dat->y[j]; - if (t1 < 0) - t1 *= -1; - if (t2 < 0) - t2 *= -1; + if (t1 < 0) t1 *= -1; + if (t2 < 0) t2 *= -1; t1 += 0.5; t2 += 0.5; - return (int) (t1 < t2 ? t2 : t1); + return (int)(t1 < t2 ? t2 : t1); } -static int man_edgelen (int i, int j, CCdatagroup *dat) -{ +static int man_edgelen(int i, int j, CCdatagroup* dat) { double t1 = dat->x[i] - dat->x[j], t2 = dat->y[i] - dat->y[j]; - if (t1 < 0) - t1 *= -1; - if (t2 < 0) - t2 *= -1; + if (t1 < 0) t1 *= -1; + if (t2 < 0) t2 *= -1; - return (int) (t1 + t2 + 0.5); + return (int)(t1 + t2 + 0.5); } - -static int euclid_edgelen (int i, int j, CCdatagroup *dat) -{ +static int euclid_edgelen(int i, int j, CCdatagroup* dat) { double t1 = dat->x[i] - dat->x[j], t2 = dat->y[i] - dat->y[j]; int temp; - temp = (int) (sqrt (t1 * t1 + t2 * t2) + 0.5); + temp = (int)(sqrt(t1 * t1 + t2 * t2) + 0.5); return temp; } -static int toroidal_edgelen (int i, int j, CCdatagroup *dat) -{ +static int toroidal_edgelen(int i, int j, CCdatagroup* dat) { double t1 = dat->x[i] - dat->x[j]; double t2 = dat->y[i] - dat->y[j]; int temp; @@ -315,68 +282,63 @@ static int toroidal_edgelen (int i, int j, CCdatagroup *dat) if (t2 < 0) t2 = -t2; if (dat->gridsize - t1 < t1) t1 = dat->gridsize - t1; if (dat->gridsize - t2 < t2) t2 = dat->gridsize - t2; - temp = (int) (sqrt (t1 * t1 + t2 * t2) + 0.5); + temp = (int)(sqrt(t1 * t1 + t2 * t2) + 0.5); return temp; } -static int euclid3d_edgelen (int i, int j, CCdatagroup *dat) -{ +static int euclid3d_edgelen(int i, int j, CCdatagroup* dat) { double t1 = dat->x[i] - dat->x[j], t2 = dat->y[i] - dat->y[j]; double t3 = dat->z[i] - dat->z[j]; int temp; - temp = (int) (sqrt (t1 * t1 + t2 * t2 + t3 * t3) + 0.5); + temp = (int)(sqrt(t1 * t1 + t2 * t2 + t3 * t3) + 0.5); return temp; } -static int euclid_ceiling_edgelen (int i, int j, CCdatagroup *dat) -{ +static int euclid_ceiling_edgelen(int i, int j, CCdatagroup* dat) { double t1 = dat->x[i] - dat->x[j], t2 = dat->y[i] - dat->y[j]; -/* - int rd; - double max; - - max = sqrt (t1 * t1 + t2 * t2); - rd = (int) max; - return (((max - rd) > .000000001) ? rd + 1 : rd); -*/ - return (int) (ceil (sqrt (t1 * t1 + t2 * t2))); + /* + int rd; + double max; + + max = sqrt (t1 * t1 + t2 * t2); + rd = (int) max; + return (((max - rd) > .000000001) ? rd + 1 : rd); + */ + return (int)(ceil(sqrt(t1 * t1 + t2 * t2))); } #define GH_PI (3.141592) -static int geographic_edgelen (int i, int j, CCdatagroup *dat) -{ +static int geographic_edgelen(int i, int j, CCdatagroup* dat) { double deg, min; double lati, latj, longi, longj; double q1, q2, q3; int dd; double x1 = dat->x[i], x2 = dat->x[j], yy1 = dat->y[i], yy2 = dat->y[j]; - deg = dtrunc (x1); + deg = dtrunc(x1); min = x1 - deg; lati = GH_PI * (deg + 5.0 * min / 3.0) / 180.0; - deg = dtrunc (x2); + deg = dtrunc(x2); min = x2 - deg; latj = GH_PI * (deg + 5.0 * min / 3.0) / 180.0; - deg = dtrunc (yy1); + deg = dtrunc(yy1); min = yy1 - deg; longi = GH_PI * (deg + 5.0 * min / 3.0) / 180.0; - deg = dtrunc (yy2); + deg = dtrunc(yy2); min = yy2 - deg; longj = GH_PI * (deg + 5.0 * min / 3.0) / 180.0; - q1 = cos (longi - longj); - q2 = cos (lati - latj); - q3 = cos (lati + latj); - dd = (int) (6378.388 * acos (0.5 * ((1.0 + q1) * q2 - (1.0 - q1) * q3)) - + 1.0); + q1 = cos(longi - longj); + q2 = cos(lati - latj); + q3 = cos(lati + latj); + dd = (int)(6378.388 * acos(0.5 * ((1.0 + q1) * q2 - (1.0 - q1) * q3)) + 1.0); return dd; } -static int geom_edgelen (int i, int j, CCdatagroup *dat) -{ +static int geom_edgelen(int i, int j, CCdatagroup* dat) { double lati, latj, longi, longj; double q1, q2, q3, q4, q5; @@ -386,12 +348,12 @@ static int geom_edgelen (int i, int j, CCdatagroup *dat) longi = M_PI * dat->y[i] / 180.0; longj = M_PI * dat->y[j] / 180.0; - q1 = cos (latj) * sin(longi - longj); - q3 = sin((longi - longj)/2.0); - q4 = cos((longi - longj)/2.0); + q1 = cos(latj) * sin(longi - longj); + q3 = sin((longi - longj) / 2.0); + q4 = cos((longi - longj) / 2.0); q2 = sin(lati + latj) * q3 * q3 - sin(lati - latj) * q4 * q4; q5 = cos(lati - latj) * q4 * q4 - cos(lati + latj) * q3 * q3; - return (int) (6378388.0 * atan2(sqrt(q1*q1 + q2*q2), q5) + 1.0); + return (int)(6378388.0 * atan2(sqrt(q1 * q1 + q2 * q2), q5) + 1.0); } #if 0 @@ -416,44 +378,40 @@ static int geom_edgelen (int i, int j, CCdatagroup *dat) } #endif -static int att_edgelen (int i, int j, CCdatagroup *dat) -{ +static int att_edgelen(int i, int j, CCdatagroup* dat) { double xd = dat->x[i] - dat->x[j]; double yd = dat->y[i] - dat->y[j]; - double rij = sqrt ((xd * xd + yd * yd) / 10.0); - double tij = dtrunc (rij); + double rij = sqrt((xd * xd + yd * yd) / 10.0); + double tij = dtrunc(rij); int dij; if (tij < rij) - dij = (int) tij + 1; + dij = (int)tij + 1; else - dij = (int) tij; + dij = (int)tij; return dij; } -static double dtrunc (double x) -{ +static double dtrunc(double x) { int k; - k = (int) x; - x = (double) k; + k = (int)x; + x = (double)k; return x; } -void CCutil_dsjrand_init (CCdatagroup *dat, int maxdist, int seed) -{ - dat->dsjrand_factor = maxdist/2147483648.0; - dat->dsjrand_param = 104*seed+1; +void CCutil_dsjrand_init(CCdatagroup* dat, int maxdist, int seed) { + dat->dsjrand_factor = maxdist / 2147483648.0; + dat->dsjrand_param = 104 * seed + 1; } -static int dsjrand_edgelen (int i, int j, CCdatagroup *dat) -{ - int di = (int) dat->x[i]; - int dj = (int) dat->x[j]; +static int dsjrand_edgelen(int i, int j, CCdatagroup* dat) { + int di = (int)dat->x[i]; + int dj = (int)dat->x[j]; int x, y, z; - x = di&dj; - y = di|dj; + x = di & dj; + y = di | dj; z = dat->dsjrand_param; x *= z; @@ -466,7 +424,7 @@ static int dsjrand_edgelen (int i, int j, CCdatagroup *dat) y *= x; z *= y; - x = ((di+dj)^z)&0x7fffffff; + x = ((di + dj) ^ z) & 0x7fffffff; return (int)(x * dat->dsjrand_factor); } @@ -476,44 +434,35 @@ static int dsjrand_edgelen (int i, int j, CCdatagroup *dat) #define CRYSTAL_NEEDS_FLIP(x) ((x) > (CRYSTAL_FLIP_TOL)) #define CRYSTAL_FLIP(x) ((2 * (CRYSTAL_FLIP_TOL)) - (x)) -static int crystal_edgelen (int i, int j, CCdatagroup *dat) -{ +static int crystal_edgelen(int i, int j, CCdatagroup* dat) { double w, w1; w = dat->x[i] - dat->x[j]; - if (w < 0) - w = -w; + if (w < 0) w = -w; w1 = dat->y[i] - dat->y[j]; - if (w1 < 0) - w1 = -w1; - if (CRYSTAL_NEEDS_FLIP (w1)) - w1 = CRYSTAL_FLIP (w1); - if (w < w1) - w = w1; + if (w1 < 0) w1 = -w1; + if (CRYSTAL_NEEDS_FLIP(w1)) w1 = CRYSTAL_FLIP(w1); + if (w < w1) w = w1; w1 = dat->z[i] - dat->z[j]; - if (w1 < 0) - w1 = -w1; - if (w < w1) - w = w1; + if (w1 < 0) w1 = -w1; + if (w < w1) w = w1; - return (int) w; + return (int)w; } -static int matrix_edgelen (int i, int j, CCdatagroup *dat) -{ +static int matrix_edgelen(int i, int j, CCdatagroup* dat) { if (i > j) return (dat->adj[i])[j]; else return (dat->adj[j])[i]; } -static int sparse_edgelen (int i, int j, CCdatagroup *dat) -{ - int *adj; +static int sparse_edgelen(int i, int j, CCdatagroup* dat) { + int* adj; int k, deg; if (i > j) { - CC_SWAP (i, j, k); + CC_SWAP(i, j, k); } adj = dat->adj[i]; deg = dat->degree[i]; @@ -526,143 +475,110 @@ static int sparse_edgelen (int i, int j, CCdatagroup *dat) return dat->default_len; } -void CCutil_init_datagroup (CCdatagroup *dat) -{ - dat->x = (double *) NULL; - dat->y = (double *) NULL; - dat->z = (double *) NULL; - dat->adj = (int **) NULL; - dat->adjspace = (int *) NULL; - dat->len = (int **) NULL; - dat->lenspace = (int *) NULL; - dat->degree = (int *) NULL; +void CCutil_init_datagroup(CCdatagroup* dat) { + dat->x = (double*)NULL; + dat->y = (double*)NULL; + dat->z = (double*)NULL; + dat->adj = (int**)NULL; + dat->adjspace = (int*)NULL; + dat->len = (int**)NULL; + dat->lenspace = (int*)NULL; + dat->degree = (int*)NULL; dat->norm = 0; dat->dsjrand_param = 1; dat->dsjrand_factor = 1.0; dat->default_len = 100000; dat->sparse_ecount = 0; dat->edgelen = edgelen_nonorm; - init_userdat (&dat->userdat); - init_rhdata (&dat->rhdat); + init_userdat(&dat->userdat); + init_rhdata(&dat->rhdat); dat->ndepot = 0; dat->orig_ncount = 0; - dat->depotcost = (int *) NULL; - dat->orig_names = (int *) NULL; + dat->depotcost = (int*)NULL; + dat->orig_names = (int*)NULL; } -void CCutil_freedatagroup (CCdatagroup *dat) -{ - CC_IFFREE (dat->x, double); - CC_IFFREE (dat->y, double); - CC_IFFREE (dat->z, double); - CC_IFFREE (dat->adj, int *); - CC_IFFREE (dat->adjspace, int); - CC_IFFREE (dat->len, int *); - CC_IFFREE (dat->lenspace, int); - CC_IFFREE (dat->degree, int); - free_userdat (&dat->userdat); - free_rhdata (&dat->rhdat); - CC_IFFREE (dat->depotcost, int); - CC_IFFREE (dat->orig_names, int); +void CCutil_freedatagroup(CCdatagroup* dat) { + CC_IFFREE(dat->x, double); + CC_IFFREE(dat->y, double); + CC_IFFREE(dat->z, double); + CC_IFFREE(dat->adj, int*); + CC_IFFREE(dat->adjspace, int); + CC_IFFREE(dat->len, int*); + CC_IFFREE(dat->lenspace, int); + CC_IFFREE(dat->degree, int); + free_userdat(&dat->userdat); + free_rhdata(&dat->rhdat); + CC_IFFREE(dat->depotcost, int); + CC_IFFREE(dat->orig_names, int); } -static void init_userdat (CCdata_user *userdat) -{ - userdat->x = (double *) NULL; - userdat->y = (double *) NULL; +static void init_userdat(CCdata_user* userdat) { + userdat->x = (double*)NULL; + userdat->y = (double*)NULL; } -static void free_userdat (CCdata_user *userdat) -{ - CC_IFFREE (userdat->x, double); - CC_IFFREE (userdat->y, double); +static void free_userdat(CCdata_user* userdat) { + CC_IFFREE(userdat->x, double); + CC_IFFREE(userdat->y, double); } -static int user_edgelen (int i, int j, CCdatagroup *dat) -{ +static int user_edgelen(int i, int j, CCdatagroup* dat) { double dw = dat->userdat.x[i] - dat->userdat.x[j]; double dw1 = dat->userdat.y[i] - dat->userdat.y[j]; - static const double ibm_xmult[7] = {1062.5, - 300.0, - 300.0, - 250.0, - 300.0, - 1000.0, - 154.6}; - static const double ibm_xadd[7] = {155.0 - 0.01 * 1062.5, - 197.5 - 0.05 * 300.0, - 212.5 - 0.10 * 300.0, - 227.5 - 0.15 * 250.0, - 240.5 - 0.20 * 300.0, - 255.0 - 0.25 * 1000.0, - 305.0 - 0.30 * 154.6}; - static const double ibm_ymult[7] = {1062.5, - 450.0, - 350.0, - 250.0, - 300.0, - 900.0, - 157.7}; - static const double ibm_yadd[7] = {150.0 - 0.01 * 1062.5, - 192.5 - 0.05 * 450.0, - 215.0 - 0.10 * 350.0, - 232.5 - 0.15 * 250.0, - 245.5 - 0.20 * 300.0, - 250.0 - 0.25 * 900.0, - 295.0 - 0.30 * 157.7}; - - if (dw < 0.0) - dw = -dw; + static const double ibm_xmult[7] = {1062.5, 300.0, 300.0, 250.0, 300.0, 1000.0, 154.6}; + static const double ibm_xadd[7] = {155.0 - 0.01 * 1062.5, 197.5 - 0.05 * 300.0, 212.5 - 0.10 * 300.0, + 227.5 - 0.15 * 250.0, 240.5 - 0.20 * 300.0, 255.0 - 0.25 * 1000.0, + 305.0 - 0.30 * 154.6}; + static const double ibm_ymult[7] = {1062.5, 450.0, 350.0, 250.0, 300.0, 900.0, 157.7}; + static const double ibm_yadd[7] = {150.0 - 0.01 * 1062.5, 192.5 - 0.05 * 450.0, 215.0 - 0.10 * 350.0, + 232.5 - 0.15 * 250.0, 245.5 - 0.20 * 300.0, 250.0 - 0.25 * 900.0, + 295.0 - 0.30 * 157.7}; + + if (dw < 0.0) dw = -dw; dw /= 25400.0; if (dw <= 0.01) { dw *= 15500.0; } else if (dw >= 0.30) { dw = dw * 154.6 + (305.0 - 0.3 * 154.6); } else { - dw = dw * ibm_xmult[(int) (dw / 0.05)] + - ibm_xadd[(int) (dw / 0.05)]; + dw = dw * ibm_xmult[(int)(dw / 0.05)] + ibm_xadd[(int)(dw / 0.05)]; } - if (dw1 < 0.0) - dw1 = -dw1; + if (dw1 < 0.0) dw1 = -dw1; dw1 /= 25400.0; if (dw1 <= 0.01) { dw1 *= 15000.0; } else if (dw1 >= 0.30) { dw1 = dw1 * 157.7 + (295.0 - 0.3 * 157.7); } else { - dw1 = dw1 * ibm_ymult[(int) (dw1 / 0.05)] + - ibm_yadd[(int) (dw1 / 0.05)]; + dw1 = dw1 * ibm_ymult[(int)(dw1 / 0.05)] + ibm_yadd[(int)(dw1 / 0.05)]; } - if (dw < dw1) - dw = dw1; - return (int) dw; + if (dw < dw1) dw = dw1; + return (int)dw; } -static void init_rhdata (CCdata_rhvector *rhdat) -{ - rhdat->space = (char *) NULL; - rhdat->vectors = (char **) NULL; +static void init_rhdata(CCdata_rhvector* rhdat) { + rhdat->space = (char*)NULL; + rhdat->vectors = (char**)NULL; rhdat->rhlength = 0; rhdat->dist_00 = 0; rhdat->dist_01 = 0; rhdat->dist_02 = 0; rhdat->dist_22 = 0; - rhdat->p = 0.0; + rhdat->p = 0.0; } -static void free_rhdata (CCdata_rhvector *rhdat) -{ - CC_IFFREE (rhdat->space, char); - CC_IFFREE (rhdat->vectors, char *); +static void free_rhdata(CCdata_rhvector* rhdat) { + CC_IFFREE(rhdat->space, char); + CC_IFFREE(rhdat->vectors, char*); rhdat->rhlength = 0; } -static int rhmap1_edgelen (int i, int j, CCdatagroup *dat) -{ - char **vectors = dat->rhdat.vectors; +static int rhmap1_edgelen(int i, int j, CCdatagroup* dat) { + char** vectors = dat->rhdat.vectors; int rhlength = dat->rhdat.rhlength; - char *v1 = vectors[i]; - char *v2 = vectors[j]; + char* v1 = vectors[i]; + char* v2 = vectors[j]; int n; int sum = 0; int dist_00 = dat->rhdat.dist_00; @@ -671,59 +587,71 @@ static int rhmap1_edgelen (int i, int j, CCdatagroup *dat) int dist_12 = dat->rhdat.dist_12; int dist_22 = dat->rhdat.dist_22; - if (v1 == (char *) NULL || v2 == (char *) NULL) return 0; - - for (n=0; nrhdat.vectors; +static int rhmap2_edgelen(int i, int j, CCdatagroup* dat) { + char** vectors = dat->rhdat.vectors; int rhlength = dat->rhdat.rhlength; - char *v1 = vectors[i]; - char *v2 = vectors[j]; + char* v1 = vectors[i]; + char* v2 = vectors[j]; int n; double sum = 0; double p = dat->rhdat.p; - if (v1 == (char *) NULL || v2 == (char *) NULL) return 0; - - for (n=0; nrhdat.vectors; +static int rhmap3_edgelen(int i, int j, CCdatagroup* dat) { + char** vectors = dat->rhdat.vectors; int len = dat->rhdat.rhlength; - char *first = vectors[i]; - char *second = vectors[j]; + char* first = vectors[i]; + char* second = vectors[j]; int xindex; int a = 0; int b = 0; @@ -737,18 +665,20 @@ static int rhmap3_edgelen (int i, int j, CCdatagroup *dat) double theta; double term; - if (first == (char *) NULL) { - if (second == (char *) NULL) return 0; + if (first == (char*)NULL) { + if (second == (char*)NULL) return 0; first = second; - second = (char *) NULL; + second = (char*)NULL; } - - if (second == (char *) NULL) { + + if (second == (char*)NULL) { for (xindex = 0; xindex < len; xindex++) { - if (first[xindex] == 1) a++; - else if (first[xindex] == 0) b++; + if (first[xindex] == 1) + a++; + else if (first[xindex] == 0) + b++; } - trans = pow(sqrt(P), (double) a) * pow(sqrt(Q), (double) b); + trans = pow(sqrt(P), (double)a) * pow(sqrt(Q), (double)b); } else { for (xindex = 0; xindex < len; xindex++) { if ((first[xindex] != 2) || (second[xindex] != 2)) { @@ -760,8 +690,8 @@ static int rhmap3_edgelen (int i, int j, CCdatagroup *dat) } } if (n == 0) return MAX_DIST; - temp = (n - (a*P) - (d*Q)); - term = (4.0 * n * P * Q * (b+c)); + temp = (n - (a * P) - (d * Q)); + term = (4.0 * n * P * Q * (b + c)); if (term >= (temp * temp)) return MAX_DIST; @@ -769,20 +699,17 @@ static int rhmap3_edgelen (int i, int j, CCdatagroup *dat) if (theta >= 1.0) return MAX_DIST; - trans = pow((1.0 - (theta*P)), (double) d) * - pow((1.0 - (theta*Q)), (double) a) * - pow((theta * sqrt(P*Q)), (double) (b+c)); - + trans = pow((1.0 - (theta * P)), (double)d) * pow((1.0 - (theta * Q)), (double)a) * + pow((theta * sqrt(P * Q)), (double)(b + c)); } - return ((int) (-10.0 * log10(trans))); + return ((int)(-10.0 * log10(trans))); } -static int rhmap4_edgelen (int i, int j, CCdatagroup *dat) -{ - char **vectors = dat->rhdat.vectors; +static int rhmap4_edgelen(int i, int j, CCdatagroup* dat) { + char** vectors = dat->rhdat.vectors; int len = dat->rhdat.rhlength; - char *first = vectors[i]; - char *second = vectors[j]; + char* first = vectors[i]; + char* second = vectors[j]; int xindex; int a = 0; int b = 0; @@ -796,18 +723,20 @@ static int rhmap4_edgelen (int i, int j, CCdatagroup *dat) double theta; double term; - if (first == (char *) NULL) { - if (second == (char *) NULL) return 0; + if (first == (char*)NULL) { + if (second == (char*)NULL) return 0; first = second; - second = (char *) NULL; + second = (char*)NULL; } - - if (second == (char *) NULL) { + + if (second == (char*)NULL) { for (xindex = 0; xindex < len; xindex++) { - if (first[xindex] == 1) a++; - else if (first[xindex] == 0) b++; + if (first[xindex] == 1) + a++; + else if (first[xindex] == 0) + b++; } - trans = pow(sqrt(P), (double) a) * pow(sqrt(Q), (double) b); + trans = pow(sqrt(P), (double)a) * pow(sqrt(Q), (double)b); } else { for (xindex = 0; xindex < len; xindex++) { if ((first[xindex] != 2) && (second[xindex] != 2)) { @@ -819,8 +748,8 @@ static int rhmap4_edgelen (int i, int j, CCdatagroup *dat) } } if (n == 0) return MAX_DIST; - temp = (n - (a*P) - (d*Q)); - term = (4.0 * n * P * Q * (b+c)); + temp = (n - (a * P) - (d * Q)); + term = (4.0 * n * P * Q * (b + c)); if (term >= (temp * temp)) return MAX_DIST; @@ -828,33 +757,31 @@ static int rhmap4_edgelen (int i, int j, CCdatagroup *dat) if (theta >= 1.0) return MAX_DIST; - trans = pow((1.0 - (theta*P)), (double) d) * - pow((1.0 - (theta*Q)), (double) a) * - pow((theta * sqrt(P*Q)), (double) (b+c)); - + trans = pow((1.0 - (theta * P)), (double)d) * pow((1.0 - (theta * Q)), (double)a) * + pow((theta * sqrt(P * Q)), (double)(b + c)); } - return ((int) (-10.0 * log10(trans))); + return ((int)(-10.0 * log10(trans))); } -static int rhmap5_edgelen (int i, int j, CCdatagroup *dat) -{ - char **vectors = dat->rhdat.vectors; +static int rhmap5_edgelen(int i, int j, CCdatagroup* dat) { + char** vectors = dat->rhdat.vectors; int rhlength = dat->rhdat.rhlength; - char *v1 = vectors[i]; - char *v2 = vectors[j]; + char* v1 = vectors[i]; + char* v2 = vectors[j]; int n; int mis = 0; int cnt = 0; - if (v1 == (char *) NULL || v2 == (char *) NULL) return 0; - - for (n=0; necount = 0; - elist->ends = (int *) NULL; + elist->ends = (int*)NULL; } -void CCelistl_init (CCelistl *elist) -{ +void CCelistl_init(CCelistl* elist) { elist->ecount = 0; - elist->ends = (int *) NULL; - elist->len = (int *) NULL; + elist->ends = (int*)NULL; + elist->len = (int*)NULL; } -void CCelistw_init (CCelistw *elist) -{ +void CCelistw_init(CCelistw* elist) { elist->ecount = 0; - elist->ends = (int *) NULL; - elist->weight = (double *) NULL; + elist->ends = (int*)NULL; + elist->weight = (double*)NULL; } -void CCelistlw_init (CCelistlw *elist) -{ +void CCelistlw_init(CCelistlw* elist) { elist->ecount = 0; - elist->ends = (int *) NULL; - elist->len = (int *) NULL; - elist->weight = (double *) NULL; + elist->ends = (int*)NULL; + elist->len = (int*)NULL; + elist->weight = (double*)NULL; } -void CCelist_free (CCelist *elist) -{ +void CCelist_free(CCelist* elist) { elist->ecount = 0; - CC_IFFREE (elist->ends, int); + CC_IFFREE(elist->ends, int); } -void CCelistl_free (CCelistl *elist) -{ +void CCelistl_free(CCelistl* elist) { elist->ecount = 0; - CC_IFFREE (elist->ends, int); - CC_IFFREE (elist->len, int); + CC_IFFREE(elist->ends, int); + CC_IFFREE(elist->len, int); } -void CCelistw_free (CCelistw *elist) -{ +void CCelistw_free(CCelistw* elist) { elist->ecount = 0; - CC_IFFREE (elist->ends, int); - CC_IFFREE (elist->weight, double); + CC_IFFREE(elist->ends, int); + CC_IFFREE(elist->weight, double); } -void CCelistlw_free (CCelistlw *elist) -{ +void CCelistlw_free(CCelistlw* elist) { elist->ecount = 0; - CC_IFFREE (elist->ends, int); - CC_IFFREE (elist->len, int); - CC_IFFREE (elist->weight, double); + CC_IFFREE(elist->ends, int); + CC_IFFREE(elist->len, int); + CC_IFFREE(elist->weight, double); } -int CCelist_alloc (CCelist *elist, int ecount) -{ - elist->ends = CC_SAFE_MALLOC (ecount*2, int); - if (elist->ends == (int *) NULL) { - CCelist_free (elist); +int CCelist_alloc(CCelist* elist, int ecount) { + elist->ends = CC_SAFE_MALLOC(ecount * 2, int); + if (elist->ends == (int*)NULL) { + CCelist_free(elist); return 1; } elist->ecount = ecount; return 0; } -int CCelistl_alloc (CCelistl *elist, int ecount) -{ - elist->ends = CC_SAFE_MALLOC (ecount*2, int); - elist->len = CC_SAFE_MALLOC (ecount, int); - if (elist->ends == (int *) NULL || - elist->len == (int *) NULL) { - CCelistl_free (elist); +int CCelistl_alloc(CCelistl* elist, int ecount) { + elist->ends = CC_SAFE_MALLOC(ecount * 2, int); + elist->len = CC_SAFE_MALLOC(ecount, int); + if (elist->ends == (int*)NULL || elist->len == (int*)NULL) { + CCelistl_free(elist); return 1; } elist->ecount = ecount; return 0; } -int CCelistw_alloc (CCelistw *elist, int ecount) -{ - elist->ends = CC_SAFE_MALLOC (ecount*2, int); - elist->weight = CC_SAFE_MALLOC (ecount, double); - if (elist->ends == (int *) NULL || - elist->weight == (double *) NULL) { - CCelistw_free (elist); +int CCelistw_alloc(CCelistw* elist, int ecount) { + elist->ends = CC_SAFE_MALLOC(ecount * 2, int); + elist->weight = CC_SAFE_MALLOC(ecount, double); + if (elist->ends == (int*)NULL || elist->weight == (double*)NULL) { + CCelistw_free(elist); return 1; } elist->ecount = ecount; return 0; } -int CCelistlw_alloc (CCelistlw *elist, int ecount) -{ - elist->ends = CC_SAFE_MALLOC (ecount*2, int); - elist->len = CC_SAFE_MALLOC (ecount, int); - elist->weight = CC_SAFE_MALLOC (ecount, double); - if (elist->ends == (int *) NULL || - elist->len == (int *) NULL || - elist->weight == (double *) NULL) { - CCelistlw_free (elist); +int CCelistlw_alloc(CCelistlw* elist, int ecount) { + elist->ends = CC_SAFE_MALLOC(ecount * 2, int); + elist->len = CC_SAFE_MALLOC(ecount, int); + elist->weight = CC_SAFE_MALLOC(ecount, double); + if (elist->ends == (int*)NULL || elist->len == (int*)NULL || elist->weight == (double*)NULL) { + CCelistlw_free(elist); return 1; } elist->ecount = ecount; return 0; } -int CCutil_edge_to_cycle (int ncount, int *elist, int *yesno, int *cyc) -{ +int CCutil_edge_to_cycle(int ncount, int* elist, int* yesno, int* cyc) { int *Lside, *Rside; int i, k, end1, end2, prev, this, next, start, okfirst, first = 0; int rval = 0; *yesno = 0; - Lside = CC_SAFE_MALLOC (ncount, int); - Rside = CC_SAFE_MALLOC (ncount, int); + Lside = CC_SAFE_MALLOC(ncount, int); + Rside = CC_SAFE_MALLOC(ncount, int); if (!Lside || !Rside) { - fprintf (stderr, "out of memory in CCutil_edge_to_cycle\n"); - rval = 1; goto CLEANUP; + fprintf(stderr, "out of memory in CCutil_edge_to_cycle\n"); + rval = 1; + goto CLEANUP; } for (i = 0; i < ncount; i++) { @@ -219,9 +203,9 @@ int CCutil_edge_to_cycle (int ncount, int *elist, int *yesno, int *cyc) for (i = 0, k = 0; i < ncount; i++) { end1 = elist[k++]; end2 = elist[k++]; - if (Lside[end1] == -1 || Rside[end1] == -1 || - Lside[end2] == -1 || Rside[end2] == -1) { - *yesno = 0; goto CLEANUP; + if (Lside[end1] == -1 || Rside[end1] == -1 || Lside[end2] == -1 || Rside[end2] == -1) { + *yesno = 0; + goto CLEANUP; } } start = elist[0]; @@ -230,8 +214,7 @@ int CCutil_edge_to_cycle (int ncount, int *elist, int *yesno, int *cyc) k = 0; okfirst = 0; do { - if (this == first) - okfirst = 1; + if (this == first) okfirst = 1; if (Lside[this] != prev) next = Lside[this]; else @@ -242,7 +225,8 @@ int CCutil_edge_to_cycle (int ncount, int *elist, int *yesno, int *cyc) } while (next != start && k < ncount); if (k != ncount || !okfirst) { - *yesno = 0; goto CLEANUP; + *yesno = 0; + goto CLEANUP; } *yesno = 1; @@ -263,11 +247,10 @@ int CCutil_edge_to_cycle (int ncount, int *elist, int *yesno, int *cyc) } while (next != start && k < ncount); } - CLEANUP: - CC_IFFREE (Lside, int); - CC_IFFREE (Rside, int); + CC_IFFREE(Lside, int); + CC_IFFREE(Rside, int); return rval; } diff --git a/tsp/src/heldkarp.c b/tsp/src/heldkarp.c index fe5b0dd..a783e60 100644 --- a/tsp/src/heldkarp.c +++ b/tsp/src/heldkarp.c @@ -64,122 +64,111 @@ /* */ /****************************************************************************/ -#include "machdefs.h" #include "heldkarp.h" -#include "util.h" + +#include "machdefs.h" #include "macrorus.h" +#include "util.h" #define LINE_LEN (75) -#define MAX_NODES (100) +#define MAX_NODES (100) #define WEIGHT_ADJUST (5) #define WEIGHT_MULT (1 << WEIGHT_ADJUST) -#define WEIGHT_MAX_EDGE (1 << (20 - WEIGHT_ADJUST)) /* no overflow */ +#define WEIGHT_MAX_EDGE (1 << (20 - WEIGHT_ADJUST)) /* no overflow */ #define WEIGHT_MAX_NODE (1 << 21) typedef struct treenode { - int deg; - int parent; - int mark; - int *adj; - int *eadj; - int parentedge; - int parentlen; + int deg; + int parent; + int mark; + int* adj; + int* eadj; + int parentedge; + int parentlen; } treenode; - -static void - initial_y (int ncount, int ecount, int *elist, int *len, int *y), - hk_work (int ncount, int *elist, int *elen, int *len, int **adjlist, - int *zadjlist, int *y, int *deg, int *upperbound, int *tree, - int *foundtour, int *besttour, int *efix, int *degfix, int depth, - int *bbcount, int just_verify, int silent, int nodelimit), - held_karp_bound (int ncount, int *elist, int *elen, int *len, - int **adjlist, int *zadjlist, int *y, int *deg, int upperbound, - int *tree, int *val, int *newtour, int *besttour, int maxiter, - double beta, int silent), - one_tree (int ncount, int *elist, int *len, int **adjlist, int *zadjlist, - int *y, int *tree, int *notree), - span_tree(int nnodes, int **adjlist, int elen[], int y[], int sptree[], - int *notree), - edge_select (int ncount, int *elist, int *len, int *y, int *tree, - int *efix, int *ebranch), - set_adjlist (int n0, int n1, int **adjlist, int *zadjlist, int val); - - -int CCheldkarp_small (int ncount, CCdatagroup *dat, double *upbound, - double *optval, int *foundtour, int anytour, int *tour_elist, - int nodelimit, int silent) -{ +static void initial_y(int ncount, int ecount, int* elist, int* len, int* y), + hk_work(int ncount, int* elist, int* elen, int* len, int** adjlist, int* zadjlist, int* y, int* deg, + int* upperbound, int* tree, int* foundtour, int* besttour, int* efix, int* degfix, int depth, + int* bbcount, int just_verify, int silent, int nodelimit), + held_karp_bound(int ncount, int* elist, int* elen, int* len, int** adjlist, int* zadjlist, int* y, + int* deg, int upperbound, int* tree, int* val, int* newtour, int* besttour, int maxiter, + double beta, int silent), + one_tree(int ncount, int* elist, int* len, int** adjlist, int* zadjlist, int* y, int* tree, int* notree), + span_tree(int nnodes, int** adjlist, int elen[], int y[], int sptree[], int* notree), + edge_select(int ncount, int* elist, int* len, int* y, int* tree, int* efix, int* ebranch), + set_adjlist(int n0, int n1, int** adjlist, int* zadjlist, int val); + +int CCheldkarp_small(int ncount, CCdatagroup* dat, double* upbound, double* optval, int* foundtour, + int anytour, int* tour_elist, int nodelimit, int silent) { int rval = 0; int i, j, k, ecount; - int *elist = (int *) NULL; - int *elen = (int *) NULL; - - ecount = ncount * (ncount-1) / 2; - elist = CC_SAFE_MALLOC (ecount*2, int); - elen = CC_SAFE_MALLOC (ecount, int); - if (elist == (int *) NULL || elen == (int *) NULL) { - fprintf (stderr, "out of memory in CCheldkarp_small\n"); - rval = HELDKARP_ERROR; goto CLEANUP; + int* elist = (int*)NULL; + int* elen = (int*)NULL; + + ecount = ncount * (ncount - 1) / 2; + elist = CC_SAFE_MALLOC(ecount * 2, int); + elen = CC_SAFE_MALLOC(ecount, int); + if (elist == (int*)NULL || elen == (int*)NULL) { + fprintf(stderr, "out of memory in CCheldkarp_small\n"); + rval = HELDKARP_ERROR; + goto CLEANUP; } for (i = 0, k = 0; i < ncount; i++) { for (j = 0; j < i; j++) { - elist[2*k] = i; - elist[2*k+1] = j; - elen[k] = CCutil_dat_edgelen (i, j, dat); - //if( i == ncount-1 && j == 0 ) elen[k] = -5000; + elist[2 * k] = i; + elist[2 * k + 1] = j; + elen[k] = CCutil_dat_edgelen(i, j, dat); + // if( i == ncount-1 && j == 0 ) elen[k] = -5000; k++; } } - rval = CCheldkarp_small_elist (ncount, ecount, elist, elen, upbound, - optval, foundtour, anytour, tour_elist, - nodelimit, silent); + rval = CCheldkarp_small_elist(ncount, ecount, elist, elen, upbound, optval, foundtour, anytour, + tour_elist, nodelimit, silent); CLEANUP: - CC_IFFREE (elist, int); - CC_IFFREE (elen, int); + CC_IFFREE(elist, int); + CC_IFFREE(elen, int); return rval; } /// This version takes the segment distance matrix directly as elen /// The elen distances should be given in the same elist order -int CCheldkarp_small_segment (int ncount, int *elen, double *upbound, - double *optval, int *foundtour, int anytour, int *tour_elist, - int nodelimit, int silent ) -{ +int CCheldkarp_small_segment(int ncount, int* elen, double* upbound, double* optval, int* foundtour, + int anytour, int* tour_elist, int nodelimit, int silent) { int rval = 0; int i, j, k, ecount; - int *elist = (int *) NULL; + int* elist = (int*)NULL; - ecount = ncount * (ncount-1) / 2; - elist = CC_SAFE_MALLOC (ecount*2, int); + ecount = ncount * (ncount - 1) / 2; + elist = CC_SAFE_MALLOC(ecount * 2, int); // elen = CC_SAFE_MALLOC (ecount, int); - if (elist == (int *) NULL || elen == (int *) NULL) { - fprintf (stderr, "out of memory in CCheldkarp_small\n"); - rval = HELDKARP_ERROR; goto CLEANUP; + if (elist == (int*)NULL || elen == (int*)NULL) { + fprintf(stderr, "out of memory in CCheldkarp_small\n"); + rval = HELDKARP_ERROR; + goto CLEANUP; } for (i = 0, k = 0; i < ncount; i++) { for (j = 0; j < i; j++) { - elist[2*k] = i; - elist[2*k+1] = j; - //elen[k] = CCutil_dat_edgelen (i, j, dat); + elist[2 * k] = i; + elist[2 * k + 1] = j; + // elen[k] = CCutil_dat_edgelen (i, j, dat); k++; } } - rval = CCheldkarp_small_elist (ncount, ecount, elist, elen, upbound, - optval, foundtour, anytour, tour_elist, - nodelimit, silent); + rval = CCheldkarp_small_elist(ncount, ecount, elist, elen, upbound, optval, foundtour, anytour, + tour_elist, nodelimit, silent); CLEANUP: - CC_IFFREE (elist, int); + CC_IFFREE(elist, int); return rval; } @@ -190,234 +179,249 @@ int CCheldkarp_small_segment (int ncount, int *elen, double *upbound, * adj(i,j) < 0 => -adj(i,j) = k+1 (means edge is fixed to 1) */ -int CCheldkarp_small_elist (int ncount, int ecount, int *elist, int *elen, - double *upbound, double *optval, int *foundtour, int anytour, - int *tour_elist, int nodelimit, int silent) -{ - int rval = 0; +int CCheldkarp_small_elist(int ncount, int ecount, int* elist, int* elen, double* upbound, double* optval, + int* foundtour, int anytour, int* tour_elist, int nodelimit, int silent) { + int rval = 0; int bbcount = 0; int init_ub = ncount * WEIGHT_MAX_EDGE + 1; int n1, n2, i, upperbound, val; - int *p; - int **adjlist = (int **) NULL; - int *padjlist = (int *) NULL; - int *zadjlist = (int *) NULL; - int *degfix = (int *) NULL; - int *tree = (int *) NULL; - int *efix = (int *) NULL; - int *len = (int *) NULL; - int *deg = (int *) NULL; - int *y = (int *) NULL; - int *besttour = (int *) NULL; + int* p; + int** adjlist = (int**)NULL; + int* padjlist = (int*)NULL; + int* zadjlist = (int*)NULL; + int* degfix = (int*)NULL; + int* tree = (int*)NULL; + int* efix = (int*)NULL; + int* len = (int*)NULL; + int* deg = (int*)NULL; + int* y = (int*)NULL; + int* besttour = (int*)NULL; *foundtour = 0; - if (upbound) upperbound = (int) (*upbound); - else upperbound = init_ub; + if (upbound) + upperbound = (int)(*upbound); + else + upperbound = init_ub; val = upperbound; if (ncount > MAX_NODES) { - fprintf (stderr, "too many nodes\n"); - rval = HELDKARP_ERROR; goto CLEANUP; + fprintf(stderr, "too many nodes\n"); + rval = HELDKARP_ERROR; + goto CLEANUP; } for (i = 0; i < ecount; i++) { if (elen[i] > WEIGHT_MAX_EDGE || -elen[i] > WEIGHT_MAX_EDGE) { - fprintf (stderr, "edge too long\n"); - rval = HELDKARP_ERROR; goto CLEANUP; + fprintf(stderr, "edge too long\n"); + rval = HELDKARP_ERROR; + goto CLEANUP; } } /* build adjlist for graph with node 0 deleted */ - adjlist = CC_SAFE_MALLOC (ncount-1, int *); - padjlist = CC_SAFE_MALLOC ((ncount-1)*(ncount-1), int); - zadjlist = CC_SAFE_MALLOC (ncount, int); - len = CC_SAFE_MALLOC (ecount, int); - if (adjlist == (int **) NULL || padjlist == (int *) NULL || - zadjlist == (int *) NULL || len == (int *) NULL) { - fprintf (stderr, "out of memory in tiny_heldkarp\n"); - rval = HELDKARP_ERROR; goto CLEANUP; + adjlist = CC_SAFE_MALLOC(ncount - 1, int*); + padjlist = CC_SAFE_MALLOC((ncount - 1) * (ncount - 1), int); + zadjlist = CC_SAFE_MALLOC(ncount, int); + len = CC_SAFE_MALLOC(ecount, int); + if (adjlist == (int**)NULL || padjlist == (int*)NULL || zadjlist == (int*)NULL || len == (int*)NULL) { + fprintf(stderr, "out of memory in tiny_heldkarp\n"); + rval = HELDKARP_ERROR; + goto CLEANUP; } - for (i=0, p = padjlist; i edge i */ - for (i=0; i nodelimit) { rval = HELDKARP_SEARCHLIMITEXCEEDED; } else { - *optval = (double) val; + *optval = (double)val; } if (*foundtour && tour_elist) { - for (i = 0; i < ncount; i++) { - tour_elist[2*i] = elist[2*besttour[i]]; - tour_elist[2*i+1] = elist[2*besttour[i]+1]; + tour_elist[2 * i] = elist[2 * besttour[i]]; + tour_elist[2 * i + 1] = elist[2 * besttour[i] + 1]; } } CLEANUP: - CC_IFFREE (adjlist, int *); - CC_IFFREE (padjlist, int); - CC_IFFREE (zadjlist, int); - CC_IFFREE (degfix, int); - CC_IFFREE (tree, int); - CC_IFFREE (efix, int); - CC_IFFREE (len, int); - CC_IFFREE (deg, int); - CC_IFFREE (y, int); - CC_IFFREE (besttour, int); + CC_IFFREE(adjlist, int*); + CC_IFFREE(padjlist, int); + CC_IFFREE(zadjlist, int); + CC_IFFREE(degfix, int); + CC_IFFREE(tree, int); + CC_IFFREE(efix, int); + CC_IFFREE(len, int); + CC_IFFREE(deg, int); + CC_IFFREE(y, int); + CC_IFFREE(besttour, int); return rval; } -static void initial_y (int ncount, int ecount, int *elist, int *len, int *y) -{ +static void initial_y(int ncount, int ecount, int* elist, int* len, int* y) { int i; for (i = 0; i < ncount; i++) y[i] = INT_MAX; - for (i=0; i < ecount; i++) { - if (len[i] < y[elist[2*i]]) y[elist[2*i]] = len[i]; - if (len[i] < y[elist[2*i+1]]) y[elist[2*i+1]] = len[i]; + for (i = 0; i < ecount; i++) { + if (len[i] < y[elist[2 * i]]) y[elist[2 * i]] = len[i]; + if (len[i] < y[elist[2 * i + 1]]) y[elist[2 * i + 1]] = len[i]; } for (i = 0; i < ncount; i++) { y[i] /= 2; } } -static void hk_work (int ncount, int *elist, int *elen, int *len, - int **adjlist, int *zadjlist, int *y, int *deg, int *upperbound, - int *tree, int *foundtour, int *besttour, int *efix, int *degfix, - int depth, int *bbcount, int just_verify, int silent, int nodelimit) -{ +static void hk_work(int ncount, int* elist, int* elen, int* len, int** adjlist, int* zadjlist, int* y, + int* deg, int* upperbound, int* tree, int* foundtour, int* besttour, int* efix, + int* degfix, int depth, int* bbcount, int just_verify, int silent, int nodelimit) { int ebranch, n0, n1, maxiter, val, newtour; double beta; int i; (*bbcount)++; if (nodelimit != -1 && *bbcount > nodelimit) return; - maxiter = (depth > 0 ? 10 : 1000); - beta = (depth > 0 ? 0.9 : 0.99); - held_karp_bound (ncount, elist, elen, len, adjlist, zadjlist, y, deg, - *upperbound, tree, &val, &newtour, besttour, maxiter, - beta, silent); - if (newtour == 1) { *foundtour = 1; *upperbound = val; return; } + maxiter = (depth > 0 ? 10 : 1000); + beta = (depth > 0 ? 0.9 : 0.99); + held_karp_bound(ncount, elist, elen, len, adjlist, zadjlist, y, deg, *upperbound, tree, &val, &newtour, + besttour, maxiter, beta, silent); + if (newtour == 1) { + *foundtour = 1; + *upperbound = val; + return; + } if (val >= *upperbound) return; - edge_select (ncount, elist, len, y, tree, efix, &ebranch); + edge_select(ncount, elist, len, y, tree, efix, &ebranch); if (ebranch == -1) return; - n0 = elist[2*ebranch]; - n1 = elist[2*ebranch+1]; - set_adjlist (n0, n1, adjlist, zadjlist, 0); - - if (!silent && depth < LINE_LEN) { printf ("0"); fflush (stdout); } - hk_work (ncount, elist, elen, len, adjlist, zadjlist, y, deg, upperbound, - tree, foundtour, besttour, efix, degfix, depth+1, bbcount, - just_verify, silent, nodelimit); - if (!silent && depth < LINE_LEN) { printf ("\b \b"); fflush (stdout); } + n0 = elist[2 * ebranch]; + n1 = elist[2 * ebranch + 1]; + set_adjlist(n0, n1, adjlist, zadjlist, 0); + + if (!silent && depth < LINE_LEN) { + printf("0"); + fflush(stdout); + } + hk_work(ncount, elist, elen, len, adjlist, zadjlist, y, deg, upperbound, tree, foundtour, besttour, efix, + degfix, depth + 1, bbcount, just_verify, silent, nodelimit); + if (!silent && depth < LINE_LEN) { + printf("\b \b"); + fflush(stdout); + } if (*foundtour == 1 && just_verify == 1) { - set_adjlist (n0, n1, adjlist, zadjlist, ebranch+1); return; + set_adjlist(n0, n1, adjlist, zadjlist, ebranch + 1); + return; } if (degfix[n0] < 2 && degfix[n1] < 2) { efix[ebranch] = 1; degfix[n0]++; degfix[n1]++; - set_adjlist (n0, n1, adjlist, zadjlist, -(ebranch+1)); + set_adjlist(n0, n1, adjlist, zadjlist, -(ebranch + 1)); - if (!silent && depth < LINE_LEN) { printf ("1"); fflush (stdout); } - hk_work (ncount, elist, elen, len, adjlist, zadjlist, y, deg, - upperbound, tree, foundtour, besttour, efix, degfix, depth+1, - bbcount, just_verify, silent, nodelimit); - if (!silent && depth < LINE_LEN) { printf ("\b \b"); fflush (stdout); } + if (!silent && depth < LINE_LEN) { + printf("1"); + fflush(stdout); + } + hk_work(ncount, elist, elen, len, adjlist, zadjlist, y, deg, upperbound, tree, foundtour, besttour, + efix, degfix, depth + 1, bbcount, just_verify, silent, nodelimit); + if (!silent && depth < LINE_LEN) { + printf("\b \b"); + fflush(stdout); + } efix[ebranch] = 0; degfix[n0]--; degfix[n1]--; } - set_adjlist (n0, n1, adjlist, zadjlist, ebranch+1); + set_adjlist(n0, n1, adjlist, zadjlist, ebranch + 1); } -static void held_karp_bound (int ncount, int *elist, int *elen, int *len, - int **adjlist, int *zadjlist, int *y, int *deg, int upperbound, - int *tree, int *val, int *newtour, int *besttour, int maxiter, - double beta, int silent) -{ +static void held_karp_bound(int ncount, int* elist, int* elen, int* len, int** adjlist, int* zadjlist, int* y, + int* deg, int upperbound, int* tree, int* val, int* newtour, int* besttour, + int maxiter, double beta, int silent) { int i, k, t, tlen, ysum, square, notree, newsum; - int abound = (upperbound << WEIGHT_ADJUST); - int goal = ((upperbound-1) << WEIGHT_ADJUST); + int abound = (upperbound << WEIGHT_ADJUST); + int goal = ((upperbound - 1) << WEIGHT_ADJUST); int bestbound = -INT_MAX; - int iter = 0; - double alpha = 2.0; + int iter = 0; + double alpha = 2.0; *newtour = 0; for (i = 0, ysum = 0; i < ncount; i++) { - ysum += y[i]; + ysum += y[i]; } do { - one_tree (ncount, elist, len, adjlist, zadjlist, y, tree, ¬ree); + one_tree(ncount, elist, len, adjlist, zadjlist, y, tree, ¬ree); if (notree == 1) { - *val = INT_MAX; return; + *val = INT_MAX; + return; } - for (i = 0, tlen = 2*ysum; i < ncount; i++) { + for (i = 0, tlen = 2 * ysum; i < ncount; i++) { k = tree[i]; - tlen += (len[k] - y[elist[2*k]] - y[elist[2*k+1]]); + tlen += (len[k] - y[elist[2 * k]] - y[elist[2 * k + 1]]); } if (tlen > bestbound) bestbound = tlen; if (tlen > goal) break; - + for (i = 0; i < ncount; i++) deg[i] = 2; for (i = 0; i < ncount; i++) { - deg[elist[2*tree[i]]]--; - deg[elist[2*tree[i]+1]]--; + deg[elist[2 * tree[i]]]--; + deg[elist[2 * tree[i] + 1]]--; } for (i = 1, square = 0; i < ncount; i++) { - square += ((deg[i])*(deg[i])); + square += ((deg[i]) * (deg[i])); } if (square == 0) { *newtour = 1; @@ -426,21 +430,23 @@ static void held_karp_bound (int ncount, int *elist, int *elen, int *len, } for (i = 0, *val = 0; i < ncount; i++) *val += elen[tree[i]]; if (silent < 2) { - printf ("Tour found: %d\n", *val); fflush (stdout); + printf("Tour found: %d\n", *val); + fflush(stdout); } return; } if (++iter >= maxiter) break; - t = (int) (alpha * (double) ((abound-tlen)) / (double) square); + t = (int)(alpha * (double)((abound - tlen)) / (double)square); if (t < 2) break; alpha *= beta; newsum = 0; for (i = 1; i < ncount; i++) { - y[i] += (t*(deg[i])); /* ysum does not change */ - if (y[i] > WEIGHT_MAX_NODE) { /* prevent overflow */ - y[i] = WEIGHT_MAX_NODE; newsum = 1; + y[i] += (t * (deg[i])); /* ysum does not change */ + if (y[i] > WEIGHT_MAX_NODE) { /* prevent overflow */ + y[i] = WEIGHT_MAX_NODE; + newsum = 1; } } if (newsum) { @@ -452,13 +458,12 @@ static void held_karp_bound (int ncount, int *elist, int *elen, int *len, if (bestbound % WEIGHT_MULT) (*val)++; } -static void one_tree (int ncount, int *elist, int *len, int **adjlist, - int *zadjlist, int *y, int *tree, int *notree) -{ +static void one_tree(int ncount, int* elist, int* len, int** adjlist, int* zadjlist, int* y, int* tree, + int* notree) { int min1, min2, emin1, emin2, i, w, e; *notree = 0; - span_tree (ncount-1, adjlist, len, y+1, tree, notree); + span_tree(ncount - 1, adjlist, len, y + 1, tree, notree); if (*notree) return; min1 = INT_MAX; @@ -470,7 +475,7 @@ static void one_tree (int ncount, int *elist, int *len, int **adjlist, e = zadjlist[i]; if (e > 0) { e--; - w = len[e] - y[elist[2*e]] - y[elist[2*e+1]]; + w = len[e] - y[elist[2 * e]] - y[elist[2 * e + 1]]; if (w < min1) { min2 = min1; min1 = w; @@ -481,58 +486,59 @@ static void one_tree (int ncount, int *elist, int *len, int **adjlist, emin2 = e; } } else if (e < 0) { - if (min2 == -INT_MAX) { *notree = 1; return; } + if (min2 == -INT_MAX) { + *notree = 1; + return; + } min2 = min1; min1 = -INT_MAX; emin2 = emin1; - emin1 = (-e)-1; + emin1 = (-e) - 1; } } if (min2 == INT_MAX) { *notree = 1; } else { - tree[ncount-2] = emin1; - tree[ncount-1] = emin2; + tree[ncount - 2] = emin1; + tree[ncount - 1] = emin2; } } -static void span_tree (int nnodes, int **adjlist, int elen[], int y[], - int sptree[], int *notree) -{ - int nbnd,nadd,nrem; - int cur,minnode,i; - int we,e,ycur; +static void span_tree(int nnodes, int** adjlist, int elen[], int y[], int sptree[], int* notree) { + int nbnd, nadd, nrem; + int cur, minnode, i; + int we, e, ycur; int nremain[MAX_NODES]; int nedge[MAX_NODES]; int nlen[MAX_NODES]; int minlen; - int *tptr; - - nbnd = nnodes-1; - for (i=0; i=0; i--){ + for (i = nrem - 1; i >= 0; i--) { e = tptr[nremain[i]]; - if (e > 0 ) { - we = elen[e-1] - ycur - y[nremain[i]]; - if (we < nlen[i]){ + if (e > 0) { + we = elen[e - 1] - ycur - y[nremain[i]]; + if (we < nlen[i]) { nedge[i] = e; nlen[i] = we; } - } else if (e < 0) { /* => edge is fixed */ - if (nlen[i] == -INT_MAX){ + } else if (e < 0) { /* => edge is fixed */ + if (nlen[i] == -INT_MAX) { *notree = 1; return; } else { @@ -540,16 +546,16 @@ static void span_tree (int nnodes, int **adjlist, int elen[], int y[], nlen[i] = -INT_MAX; } } - if (nlen[i] < minlen){ + if (nlen[i] < minlen) { minlen = nlen[i]; minnode = i; } } - if (minnode == -1) { /* Graph not connected */ - *notree = 1; + if (minnode == -1) { /* Graph not connected */ + *notree = 1; return; } else { - e = nedge[minnode]-1; + e = nedge[minnode] - 1; sptree[nadd] = e; cur = nremain[minnode]; nrem--; @@ -560,9 +566,7 @@ static void span_tree (int nnodes, int **adjlist, int elen[], int y[], } } -static void edge_select (int ncount, int *elist, int *len, int *y, int *tree, - int *efix, int *ebranch) -{ +static void edge_select(int ncount, int* elist, int* len, int* y, int* tree, int* efix, int* ebranch) { int i, e, w; int min = INT_MAX; int emin = -1; @@ -570,18 +574,21 @@ static void edge_select (int ncount, int *elist, int *len, int *y, int *tree, for (i = 0; i < ncount; i++) { e = tree[i]; if (efix[e] == 0) { - w = len[e] - y[elist[2*e]] - y[elist[2*e+1]]; - if (w < min) { min = w; emin = e; } + w = len[e] - y[elist[2 * e]] - y[elist[2 * e + 1]]; + if (w < min) { + min = w; + emin = e; + } } } *ebranch = emin; } -static void set_adjlist (int n0, int n1, int **adjlist, int *zadjlist, - int val) -{ - if (n0 == 0) zadjlist[n1] = val; - else if (n1 == 0) zadjlist[n0] = val; - else adjlist[n0-1][n1-1] = adjlist[n1-1][n0-1] = val; - +static void set_adjlist(int n0, int n1, int** adjlist, int* zadjlist, int val) { + if (n0 == 0) + zadjlist[n1] = val; + else if (n1 == 0) + zadjlist[n0] = val; + else + adjlist[n0 - 1][n1 - 1] = adjlist[n1 - 1][n0 - 1] = val; } From 819a09dbeaf3c526422a2102a72eac0a36489702 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:12:26 +0100 Subject: [PATCH 3/5] add pre-commit files check to workflow --- .github/workflows/validation.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index d93f898..84311f7 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -29,7 +29,7 @@ jobs: image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics steps: - uses: actions/checkout@v3 - - run: python3 pipeline/validateLibrary.py . + - run: python3 pipeline/validateLibrary.py . build-tracklib: name: Build only tracklib @@ -43,6 +43,10 @@ jobs: with: cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DREST_WELCOME=ON -DRESTLIB_TRACK=ON" branch: ${{ env.BRANCH_NAME }} + - name: Verify pre-commit config files match + run: | + cd $GITHUB_WORKSPACE + python ${{ env.REST_PATH }}/scripts/validatePreCommitConfig.py - name: Load REST libraries run: | source ${{ env.REST_PATH }}/thisREST.sh From 8509838141c07fb6c12b2961ebf4e2d84a4a6d8f Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:33:34 +0100 Subject: [PATCH 4/5] run the validation script using curl --- .github/workflows/validation.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 84311f7..0bcfeef 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -44,9 +44,7 @@ jobs: cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DREST_WELCOME=ON -DRESTLIB_TRACK=ON" branch: ${{ env.BRANCH_NAME }} - name: Verify pre-commit config files match - run: | - cd $GITHUB_WORKSPACE - python ${{ env.REST_PATH }}/scripts/validatePreCommitConfig.py + run: curl https://raw.githubusercontent.com/rest-for-physics/framework/master/scripts/validatePreCommitConfig.py | sudo python - - name: Load REST libraries run: | source ${{ env.REST_PATH }}/thisREST.sh From 88b3f5f48839167c9005ac23e1fe35bb2f44adf8 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:36:18 +0100 Subject: [PATCH 5/5] make sure the directory is correct --- .github/workflows/validation.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 0bcfeef..7797231 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -44,7 +44,9 @@ jobs: cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DREST_WELCOME=ON -DRESTLIB_TRACK=ON" branch: ${{ env.BRANCH_NAME }} - name: Verify pre-commit config files match - run: curl https://raw.githubusercontent.com/rest-for-physics/framework/master/scripts/validatePreCommitConfig.py | sudo python - + run: | + cd $GITHUB_WORKSPACE + curl https://raw.githubusercontent.com/rest-for-physics/framework/master/scripts/validatePreCommitConfig.py | python - name: Load REST libraries run: | source ${{ env.REST_PATH }}/thisREST.sh