Skip to content
Snippets Groups Projects
Commit fbe335a4 authored by stephgc's avatar stephgc
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
sga
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pace-2020.iml" filepath="$PROJECT_DIR$/.idea/pace-2020.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeRunConfigurationManager" shouldGenerate="true" shouldDeleteObsolete="true" buildAllGenerated="true">
<generated>
<config projectName="sga" targetName="sga" />
</generated>
</component>
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="f0416398-494c-404a-9f67-661a97715f7b" name="Default Changelist" comment="" />
<ignored path="$PROJECT_DIR$/cmake-build-debug/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="FUSProjectUsageTrigger">
<session id="-124690362">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.0" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="c" value="8" />
<entry key="h" value="5" />
<entry key="txt" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="CMakeLists.txt" value="1" />
<entry key="ObjectiveC" value="13" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="c" value="376" />
<entry key="h" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="ObjectiveC" value="377" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/separator.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="368">
<caret line="1194" selection-start-line="1194" selection-end-line="1194" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/separator.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="7" column="7" selection-start-line="7" selection-start-column="7" selection-end-line="7" selection-end-column="7" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/improve.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="147">
<caret line="42" selection-start-line="42" selection-end-line="42" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tree.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="305">
<caret line="22" column="9" selection-start-line="22" selection-start-column="9" selection-end-line="22" selection-end-column="9" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/decompose.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="675">
<caret line="45" selection-start-line="45" selection-end-line="45" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/components.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="574">
<caret line="236" selection-start-line="236" selection-end-line="236" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1656">
<caret line="126" column="5" selection-start-line="126" selection-start-column="5" selection-end-line="126" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="172">
<caret line="28" lean-forward="true" selection-start-line="28" selection-end-line="28" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/graph.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="2" lean-forward="true" selection-start-line="3" selection-start-column="2" selection-end-line="3" selection-end-column="2" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/graph.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="203">
<caret line="17" lean-forward="true" selection-start-line="17" selection-end-line="17" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>searchCriticalCorrespondant</find>
<find>nbCallsPrune</find>
<find>verifyCriticalBranch</find>
<find>treeContainsNeighbors</find>
<find>updateSetOfNodes</find>
<find>buildSetOfNodes</find>
<find>searchForks</find>
<find>exploreAndSearchForks</find>
<find>nbSwaps</find>
<find>nodesInSubtrees</find>
<find>nbDeeperN</find>
<find>limitNbDeepestNeighbors</find>
<find>nbCVerticesWithNoNeighborInAAndB</find>
<find>selectABDisconnectedVertices</find>
<find>isABetterSeparator</find>
<find>nbCallsdecreaseNbNeighborsInB</find>
<find>verifyNbNeighbors</find>
<find>nbSubtrees</find>
<find>indpdNbCalls</find>
</findStrings>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/CMakeLists.txt" />
<option value="$PROJECT_DIR$/compression.c" />
<option value="$PROJECT_DIR$/tree.c" />
<option value="$PROJECT_DIR$/tree.h" />
<option value="$PROJECT_DIR$/separator.c" />
<option value="$PROJECT_DIR$/separator.h" />
<option value="$PROJECT_DIR$/improve.c" />
<option value="$PROJECT_DIR$/decompose.c" />
<option value="$PROJECT_DIR$/components.c" />
<option value="$PROJECT_DIR$/main.c" />
<option value="$PROJECT_DIR$/main.h" />
<option value="$PROJECT_DIR$/graph.c" />
<option value="$PROJECT_DIR$/graph.h" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" />
<component name="ProjectFrameBounds">
<option name="x" value="124" />
<option name="y" value="23" />
<option name="width" value="1087" />
<option name="height" value="877" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="sga" type="b2602c69:ProjectViewProjectNode" />
<item name="pace-2020" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Application.sga">
<configuration name="Build All" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" EXPLICIT_BUILD_TARGET_NAME="all">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="sga" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" PROJECT_NAME="sga" TARGET_NAME="sga" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="sga" RUN_TARGET_NAME="sga">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.Build All" />
<item itemvalue="Application.sga" />
</list>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="f0416398-494c-404a-9f67-661a97715f7b" name="Default Changelist" comment="" />
<created>1591533541767</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1591533541767</updated>
<workItem from="1591533543009" duration="3760000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="3760000" />
</component>
<component name="ToolWindowManager">
<frame x="124" y="23" width="1087" height="877" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24976076" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="CMake" />
<window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
<window_info anchor="bottom" id="Messages" weight="0.32939634" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32939634" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Database" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/compression.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="161">
<caret line="23" lean-forward="true" selection-start-line="23" selection-end-line="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/compression.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285">
<caret line="19" column="21" selection-start-line="19" selection-start-column="21" selection-end-line="19" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tree.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="382">
<caret line="50" lean-forward="true" selection-start-line="50" selection-end-line="50" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tree.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="305">
<caret line="22" column="9" selection-start-line="22" selection-start-column="9" selection-end-line="22" selection-end-column="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/separator.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="368">
<caret line="1194" selection-start-line="1194" selection-end-line="1194" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/separator.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="7" column="7" selection-start-line="7" selection-start-column="7" selection-end-line="7" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/improve.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="147">
<caret line="42" selection-start-line="42" selection-end-line="42" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/decompose.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="675">
<caret line="45" selection-start-line="45" selection-end-line="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/components.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="574">
<caret line="236" selection-start-line="236" selection-end-line="236" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1656">
<caret line="126" column="5" selection-start-line="126" selection-start-column="5" selection-end-line="126" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="172">
<caret line="28" lean-forward="true" selection-start-line="28" selection-end-line="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/graph.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="203">
<caret line="17" lean-forward="true" selection-start-line="17" selection-end-line="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/graph.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="2" lean-forward="true" selection-start-line="3" selection-start-column="2" selection-end-line="3" selection-end-column="2" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
project(sga C)
set(CMAKE_C_STANDARD 11)
include_directories(.)
add_definitions(-DPACE_2020)
add_executable(sga
graph.c
graph.h
lire.c
lire.h
lists.c
lists.h
main.c
heap.c
heap.h
tree.c tree.h
decompose.c decompose.h
separator.c separator.h
utils.c utils.h
sets.c sets.h main.h components.c components.h improve.c improve.h)
target_link_libraries(sga m)
Copyright (c) 2020 Sephane Grandcolas
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Makefile 0 → 100644
DEBUG=no
ifeq ($(DEBUG),yes)
CFLAGS= -I sga -g -Wall -pedantic -std=c99
else
CFLAGS= -I sga -std=c99 -O3
endif
ifeq ($(PACE),yes)
PACE_FLAG= -DPACE_2020
endif
src=.
all: sga
sga: obj/main.o obj/lists.o obj/lire.o obj/graph.o obj/tree.o obj/separator.o obj/decompose.o obj/heap.o obj/sets.o obj/utils.o obj/components.o obj/improve.o
gcc $(CFLAGS) obj/main.o obj/lists.o obj/lire.o obj/graph.o obj/tree.o obj/separator.o obj/decompose.o obj/heap.o obj/sets.o obj/utils.o obj/components.o obj/improve.o -o sga
obj/improve.o: ${src}/improve.c ${src}/improve.h ${src}/graph.h ${src}/utils.h ${src}/sets.h ${src}/lists.h ${src}/tree.h ${src}/decompose.h ${src}/main.h
gcc $(CFLAGS) -c ${src}/improve.c -o obj/improve.o
obj/components.o: ${src}/components.c ${src}/components.h ${src}/graph.h ${src}/utils.h ${src}/sets.h ${src}/lists.h ${src}/heap.h
gcc $(CFLAGS) -c ${src}/components.c -o obj/components.o
obj/utils.o: ${src}/utils.c ${src}/utils.h
gcc $(CFLAGS) -c ${src}/utils.c -o obj/utils.o
obj/sets.o: ${src}/sets.c ${src}/sets.h
gcc $(CFLAGS) -c ${src}/sets.c -o obj/sets.o
obj/decompose.o: ${src}/decompose.c ${src}/decompose.h ${src}/separator.h ${src}/graph.h ${src}/utils.h ${src}/tree.h ${src}/separator.h ${src}/heap.h ${src}/main.h ${src}/components.h ${src}/improve.h
gcc $(CFLAGS) $(PACE_FLAG) -c ${src}/decompose.c -o obj/decompose.o
obj/separator.o: ${src}/separator.c ${src}/separator.h ${src}/graph.h ${src}/utils.h ${src}/components.h ${src}/main.h ${src}/heap.h
gcc $(CFLAGS) -c ${src}/separator.c -o obj/separator.o
obj/tree.o: ${src}/tree.c ${src}/tree.h ${src}/graph.h ${src}/utils.h ${src}/sets.h ${src}/decompose.h
gcc $(CFLAGS) -c ${src}/tree.c -o obj/tree.o
obj/main.o: ${src}/main.c ${src}/lists.h ${src}/lire.h ${src}/graph.h ${src}/main.h
gcc $(CFLAGS) $(PACE_FLAG) -c ${src}/main.c -o obj/main.o
obj/graph.o: ${src}/graph.c ${src}/graph.h ${src}/lists.h
gcc $(CFLAGS) -c ${src}/graph.c -o obj/graph.o
obj/lists.o: ${src}/lists.c ${src}/lists.h
gcc $(CFLAGS) -c ${src}/lists.c -o obj/lists.o
obj/lire.o: ${src}/lire.c ${src}/lire.h ${src}/lists.h ${src}/graph.h ${src}/main.h
gcc $(CFLAGS) -c ${src}/lire.c -o obj/lire.o
obj/heap.o: ${src}/heap.c ${src}/heap.h
gcc $(CFLAGS) -c ${src}/heap.c -o obj/heap.o
clean:
rm -f sga \
rm -f obj/*.o
treedepth : A program that builds a tree decomposition of a graph.
The approach consists first in decomposing recursively the graph, searching each time a partition A|B|C of the vertices such that there is no edge of G whose extremities are one in A and the other in B. C is the separator.
The resulting decomposition is improved applying pullups and ejections while the height of the decomposition decreases.
Type make to build the program named treedepth. Type ./treedepth -help to print usage information.
For example ./treedepth -file heur_111.gr time 60.
Use make PACE=yes to generate a version of the program corresponding to pace 2020 requirements (no options in line then).
//
// Created by Stephane on 24/03/2020.
//
#include <assert.h>
#include "components.h"
#include "graph.h"
#include "heap.h"
#include "lists.h"
#include "sets.h"
#include "utils.h"
int *iComp = NULL; // for each vertex, the number of its component
int *compSizes;
int *compNbEdges;
int *compFirsts;
int * tableSortVComp;
//int *firstOfComp; // the first vertex of the component, useful when the component size is 1
int sizeCompMax;
int *queue = NULL, *first, *last;
void allocSearchConnectedComponents(Graph g) {
iComp = malloc(g->n*sizeof(int));
compSizes = malloc(g->n*sizeof(int));
compNbEdges = malloc(g->n*sizeof(int));
compFirsts = malloc(g->n*sizeof(int));
tableSortVComp = malloc(g->n*sizeof(int));
//firstOfComp = malloc(g->n*sizeof(int));
queue = malloc(g->n*sizeof(int));
}
// Search connected components of the subgraph delimited by V
// verif is just used to verify for each vertex that it is in the current set (useless for greedy search)
int searchConnectedComponents(SET V, int S[], int n, Graph g) {
int nbComp = 0;
int nbNodes = 0;
sizeCompMax = 0;
for (int i = 0; i < n; i++)
iComp[S[i]] = NONE;
// Call BFS exploration from each node of S[]
for (int i = 0; i < n; i++) {
if (iComp[S[i]] == NONE) {
iComp[S[i]] = nbComp;
compSizes[nbComp] = 1;
//firstOfComp[nbComp] = S[i];
first = last = queue;
*last++ = S[i];
compExploreBFS(nbComp, V, S, n, g, 1);
if (compSizes[nbComp] > sizeCompMax) sizeCompMax = compSizes[nbComp];
nbNodes += compSizes[nbComp];
nbComp++;
if (nbNodes == n) break;
}
}
return nbComp;
}
void compExploreBFS(int num, SET V, int S[], int n, Graph g, int verif) {
while (last != first) {
int *p = g->lists[*first];
first = first+1;
if (first == queue+g->n) first = queue;
while (*p != NONE) {
if ( ! verif || (isInSet(*p, V, S, n))) { // isInSet is OK since S[] is sorted
if (iComp[*p] == NONE) {
iComp[*p] = num;
compSizes[num]++;
*last++ = *p;
if (last == queue + g->n) last = queue;
}
}
p ++;
}
}
}
// Special version for separators: the neighbors of each vertex are ordered so as that those in S
// occur first. Search components for the subgraph corresponding to the heap (H->ind[] is NONE if not in the heap)
void compExploreBFSSubgraph(int num, Heap H, int nbN[], Graph g);
int searchConnectedComponentsInHeap(Heap H, int nbNiS[], Graph g) {
int nbComp = 0;
int nbNodes = 0;
sizeCompMax = 0;
for (int i = 0; i < H->n; i++)
iComp[H->val[i]] = NONE;
for (int i = 0; i < H->n; i++) {
if (iComp[H->val[i]] == NONE) {
iComp[H->val[i]] = nbComp;
compSizes[nbComp] = 1;
compNbEdges[nbComp] = 0;
first = last = queue;
*last++ = H->val[i];
compExploreBFSSubgraph(nbComp, H, nbNiS, g);
compNbEdges[nbComp] = compNbEdges[nbComp]/2;
if (compSizes[nbComp] > sizeCompMax) sizeCompMax = compSizes[nbComp];
nbNodes += compSizes[nbComp];
nbComp ++;
if (nbNodes == H->n) break;
}
}
return nbComp;
}
void compExploreBFSSubgraph(int num, Heap H, int nbN[], Graph g) {
while (last != first) {
int *p = g->lists[*first];
int *pp = p+nbN[*first];
first = first+1;
if (first == queue+g->n) first = queue;
while (p != pp) {
if (H->ind[*p] != NONE) {
compNbEdges[num] ++;
if (iComp[*p] == NONE) {
iComp[*p] = num;
compSizes[num] ++;
*last++ = *p;
if (last == queue + g->n) last = queue;
}
}
p++;
}
}
}
// Special version for greedy decomposition: the exploration can be stopped
// once we know that the neighbors of the last removed vertex are all reachable
#define UNVISITED_NEIGHBOR -2
#define IGNORED_NODE -3
int nbNeighborsToVisit;
void compExploreBFSAF(int u, int num, SET V, Heap heap, Graph g) {
while (last != first) {
int *p = g->lists[*first];
first = first+1;
if (first == queue+g->n) first = queue;
while (*p != NONE) {
if (heap->ind[*p] != NONE) { // (isInSet(*p, V, S, n)) should be false here (S[] not ordered)
if ((iComp[*p] == NONE) || (iComp[*p] == UNVISITED_NEIGHBOR)) {
if (iComp[*p] == UNVISITED_NEIGHBOR) {
if ((-- nbNeighborsToVisit == 0) && (num == 0)) // first component, all neighbors have been discovered
return;
}
iComp[*p] = num;
compSizes[num]++;
*last++ = *p;
if (last == queue + g->n) last = queue;
}
}
p ++;
}
}
}
int searchConnectedComponentsGreedy(SET V, Heap heap, Graph g, int removedVertex) {
int nbComp = 0;
int nbNodes = 0;
sizeCompMax = 0;
nbNeighborsToVisit = 0;
for (int i = 0; i < heap->n; i++)
iComp[heap->val[i]] = NONE;
// Mark neighbors which are in the heap
for (int *p = g->lists[removedVertex]; *p != NONE; p ++) {
if (conHeap->ind[*p] != NONE) { // (isInSet(*p, V, S, n)) not good (suppose vertices are ordered in S[]
iComp[*p] = UNVISITED_NEIGHBOR;
nbNeighborsToVisit++;
}
else iComp[*p] = IGNORED_NODE;
}
// NORMAL !! if (nbNeighborsToVisit != nbN4Con[removedVertex]) {printf("%d %d\n", nbNeighborsToVisit, nbN4Con[removedVertex]); exit(0);}
for (int *p = g->lists[removedVertex]; *p != NONE; p ++) {
if (iComp[*p] == UNVISITED_NEIGHBOR) {
iComp[*p] = nbComp;
compSizes[nbComp] = 1;
nbNeighborsToVisit --;
if ((nbNeighborsToVisit == 0) && (nbComp == 0)) return 1; // a unique neighbor
first = last = queue;
*last++ = *p;
compExploreBFSAF(*p, nbComp, V, heap, g);
if ((nbNeighborsToVisit == 0) && (nbComp == 0)) return 1;
if (compSizes[nbComp] > sizeCompMax) sizeCompMax = compSizes[nbComp];
nbNodes += compSizes[nbComp];
nbComp++;
if (nbNodes == heap->n) break;
}
}
return nbComp;
}
int nbCCE = 0;
void compExplore(int u, int num, SET V, int S[], int n, Graph g, int depth) {
LIST q = g->adj[u];
int nbNeighbors = 0;
nbCCE ++;
while (q != NULL) {
nbNeighbors ++;
if (nbNeighbors > g->nadj[u]) {printf("too many neighbors !\n"); exit(0);}
if ((isInSet(q->val, V, S, n)) && (iComp[q->val] == NONE)) { //((IN(q->val, V)) && (iComp[q->val] == NONE)) {
iComp[q->val] = num;
compSizes[num] ++;
compExplore(q->val, num, V, S, n, g, depth+1);
}
q = q->suiv;
}
}
//
// utils
//
// the vertices in S[] are ordered by their component number. sizes[] are initialized.
// Uses iComp[] and compSizes[] returned by searchConnectedComponentsGreedy() or
// searchConnectedComponents()
void sortListByComponent(int S[], int n, int nbComp, int sizes[]) {
for (int i = 0; i < n; i ++) {
tableSortVComp[i] = S[i];
}
compFirsts[0] = 0;
sizes[0] = compSizes[0];
for (int i = 1; i < nbComp; i ++) {
sizes[i] = compSizes[i];
compFirsts[i] = compFirsts[i - 1] + compSizes[i - 1];
}
for (int *p = tableSortVComp; p < tableSortVComp+n; p ++) {
int pos = compFirsts[iComp[*p]];
compFirsts[iComp[*p]] ++;
S[pos] = *p;
}
}
//
// Created by Stephane on 24/03/2020.
//
#ifndef SGA_COMPONENTS_H
#define SGA_COMPONENTS_H
#include "graph.h"
#include "heap.h"
#include "sets.h"
extern int * iComp;
extern int *compSizes;
extern int *compNbEdges;
extern int * tableSortVComp;
extern int sizeCompMax;
//extern int *firstOfComp;
void allocSearchConnectedComponents(Graph g);
int searchConnectedComponents(SET V, int S[], int n, Graph g);
int searchConnectedComponentsGreedy(SET V, Heap heap, Graph g, int removedVertex);
void compExplore(int u, int num, SET V, int S[], int n, Graph g, int depth);
void compExploreBFS(int num, SET V, int S[], int n, Graph g, int verif);
int searchConnectedComponentsInHeap(Heap H, int nbNiS[], Graph g);
void sortListByComponent(int S[], int n, int nbComp, int sizes[]);
#endif //SGA_COMPONENTS_H
This diff is collapsed.
//
// Created by Stephane on 10/03/2020.
//
#ifndef SRC_DECOMPOSE_H
#define SRC_DECOMPOSE_H
#include <stdio.h>
#include "graph.h"
#include "separator.h"
#include "sets.h"
#include "tree.h"
#define SEPARE_AND_EXPLORE 0
#define GREEDY_ALGORITHM 1
#define SIZE_SMALL_TREE 3
extern int *bestTree;
extern int bestHeight;
extern Separator separator;
extern Node * theNodes;
extern int time_limit;
void updateBestDecomposition(Node root, Graph g);
void testDecompose(Graph g, int nbRuns, int algo);
Node decompose(int *S, int n, int pos[], int depth, Graph g, int hmax, int connected);
Node greedyDecompose(Heap conHeap, int depth, Graph g, int hmax, int connected);
Node makeListWithUnconnectedVertices(Heap heap, Graph g, Node *last);
Node makeSmallTree(int *S, int n, Graph g);
Node decomposeConnectedComponents(int *iComp, int nbComp, int *S, int n, int pos[], int depth, Graph g, int hmax);
Node greedyDecomposeComponents(int iComp[], int nbComp, Heap conHeap, int depth, Graph g, int hmax);
int isSmallerNeighborsInB(int a, int b);
void allocNodes(Graph g);
void allocSets(Graph g, int max);
void reAllocSets(int size, Graph g);
void allocComponents(Graph g, int max);
void reAllocComponents(Graph g, int size);
void PACEOutput(FILE *file, int height, int fathers[], Graph g);
void saveToTable(int T[], Graph g);
Node buildTreeFromTable(int T[], Graph g);
int verifyDecomposition(Node tree, Graph g);
void printStatsOnCriticalNodes(Node root, int *nbCriticalNodes);
#endif //SRC_DECOMPOSE_H
graph.c 0 → 100644
/*
* graph.c
* graphes
*
* Created by Stphane on 19/02/18.
* Copyright 2018 __MyCompanyName__. All rights reserved.
*
*/
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include <tcl.h>
#include "lists.h"
#include "decompose.h"
#include "graph.h"
#include "heap.h"
#include "main.h"
#include "sets.h"
#include "utils.h"
int maxMemory = 8000;
Graph newGraph(int n, int m, LIST *adj, int *nadj) {
Graph g;
g = malloc(sizeof(struct graph));
g->n = n;
g->m = m;
if (adj == NULL) {
g->adj = calloc(n, sizeof(LIST));
g->nadj = calloc(n, sizeof(int));
}
else {
g->adj = adj;
g->nadj = nadj;
g->lists = malloc(g->n*sizeof(int *));
g->slists = malloc(g->n*sizeof(int *));
for (int i = 0; i < n; i ++) {
g->lists[i] = malloc((g->nadj[i]+1)*sizeof(int));
g->lists[i][g->nadj[i]] = NONE;
g->slists[i] = malloc((g->nadj[i]+1)*sizeof(int));
g->slists[i][g->nadj[i]] = NONE;
g->nadj[i] = 0;
}
for (int i = 0; i < n; i ++) {
LIST p = adj[i];
while (p != NULL) {
g->lists[i][g->nadj[i]] = g->slists[i][g->nadj[i]] = p->val;
g->nadj[i] ++;
p = p->suiv;
}
}
}
g->neighbors = malloc(g->n*sizeof(SET));
if ((algo == GREEDY_ALGORITHM) || ((g->n/64)*(g->n/128)/1024 > maxMemory)) { // n=260000 --> mem=8000
for (int i = 0; i < n; i ++) g->neighbors[i] = NULL;
return g;
}
for (int i = 0; i < n; i ++) {
SET neighbors = allocSet(g->n);
if (adj != NULL) {
int *p = g->lists[i];
while (*p != NONE) {
ADDe(*p, neighbors);
p ++;
}
}
g->neighbors[i] = neighbors;
}
#ifdef NOTDEF
g->nodes = malloc(n*sizeof(NODE_FIBO));
assert(g->nodes != NULL);
for (int i = 0; i < n; i ++) {
g->nodes[i] = newHeapNode(i, 0, NULL, NULL, NULL, NULL, 0, 1, NULL);
}
#endif
return g;
}
// Determine if u and v are neighbors.
int areNeighbours(int u, int v, Graph g) {
if (g->neighbors[v] != NULL)
return IN(u, g->neighbors[v]);
if (g->nadj[u] <= g->nadj[v]) {
for (int *p = g->lists[u]; *p != NONE; p++) {
if (*p == v) return 1;
}
return 0;
}
for (int *p = g->lists[v]; *p != NONE; p++) {
if (*p == u) return 1;
}
return 0;
}
void printGraph(Graph g) {
for (int i = 0; i < g->n; i ++) {
for (LIST p = g->adj[i]; p != NULL; p = p->suiv)
printf("%d -- %d\n", i, p->val);
}
}
// Count the number of vertices of list[] which are in the heap F (used to count the number of neighbors in the heap).
int nbVerticeInHeap(int list[], int n, Heap F, Graph g) {
int nb = 0;
for (int *p = list; p < list+n; p ++) {
if (F->ind[*p] != NONE)
nb ++;
}
return nb;
}
int nbNeighborsInHeap(int u, Heap F, Graph g) {
LIST p = g->adj[u];
int nb = 0;
while (p != NULL) {
if (F->ind[p->val] != NONE)
nb ++;
p = p->suiv;
}
return nb;
}
int nbNeighborsInList(int u, SET V, int *S, int n, Graph g) {
LIST p = g->adj[u];
int nbN = 0;
while (p != NULL) {
if (isInSet(p->val, V, S, n)) {
nbN ++;
}
p = p->suiv;
}
return nbN;
}
int hasNoNeighborInSet(int vertex, SET V, Graph g) {
for (int *p = g->lists[vertex]; *p != NONE; p ++)
if (IN(*p, V)) return 0;
return 1;
}
int hasNeighborsInSubtree(int vertex, SET V, Graph g) {
int nb = 0;
for (int *p = g->lists[vertex]; *p != NONE; p ++)
if (IN(*p, V)) nb ++;
return nb;
}
int haveSameNeighbors(int u, int v, Graph g) {
int *q;
for (int *p = g->lists[u]; *p != NONE; p ++) {
for (q = g->lists[v]; *q != NONE; q++)
if (*p == *q) break;
if (*q == NONE) return 0;
}
return 1;
}
//
// Connections in current set
//
Heap conHeap = NULL; // contains the vertices ordered by their number of neighbors in the cluster
int *nbN4Con; // for each vertex the number of its neighbors in the cluster
int nbE4Con, nbMax4Con, maxNbN4Con;
int nbUnconnectedVertices;
int hasMoreConnections(int a, int b) {
return (nbN4Con[a] > nbN4Con[b]);
}
void allocConnectionsHeap(Graph g) {
conHeap = allocHeap(g->n, hasMoreConnections);
nbN4Con = malloc(g->n * sizeof(int));
}
//
// Update the max value in the heap and its number of occurrences
//
void exploreCountMax(int i, int T[], int n) {
if (nbN4Con[T[i]] == maxNbN4Con) {
nbMax4Con ++;
if (2*i+1 < n) {
exploreCountMax(2*i+1, T, n);
if (2*i+2 < n)
exploreCountMax(2*i+2, T, n);
}
}
}
void updateNbMaxConInHeap(Heap heap) {
if (heap->n == 0) { nbMax4Con = 0; return; }
maxNbN4Con = nbN4Con[heap->val[0]];
nbMax4Con = 0;
exploreCountMax(0, heap->val, heap->n);
}
// Rebuilt the heap. Suppose that there is no unconnected components here (called after decomposeConnectedComponents)
// returns 1 if the heap is a clique
int rebuildConHeap(Heap heap) {
nbE4Con = 0;
nbUnconnectedVertices = 0; // Comes from decomposeConnectedComponents normally with no unconnected vertices
maxNbN4Con = -1;
int minNbN4Con = conHeap->n + 1;
for (int i = 0; i < conHeap->n; i ++) {
conHeap->ind[conHeap->val[i]] = i;
nbE4Con += nbN4Con[conHeap->val[i]];
if (nbN4Con[conHeap->val[i]] == 0) nbUnconnectedVertices ++;
if (nbN4Con[conHeap->val[i]] < minNbN4Con) minNbN4Con = nbN4Con[conHeap->val[i]];
if (nbN4Con[conHeap->val[i]] > maxNbN4Con) { maxNbN4Con = nbN4Con[conHeap->val[i]]; nbMax4Con = 1; }
else if (nbN4Con[conHeap->val[i]] == maxNbN4Con) nbMax4Con ++;
}
makeHeap(conHeap);
if (minNbN4Con == heap->n - 1) return 1;
return 0;
//heapVerif(conHeap, nbN4Con);
}
// The initial construction of the heap: there can be unconnected components !
void initConHeap(Graph g) {
//conHeap = allocHeap(g->n, hasMoreConnections);
//nbN4Con = malloc(g->n * sizeof(int));
nbE4Con = 0;
nbMax4Con = 0;
maxNbN4Con = -1;
nbUnconnectedVertices = 0;
conHeap->n = 0;
for (int i = 0; i < g->n; i++) {
heapJustAdd(i, conHeap);
nbN4Con[i] = g->nadj[i];
nbE4Con += nbN4Con[i];
if (nbN4Con[i] > maxNbN4Con) { maxNbN4Con = nbN4Con[i]; nbMax4Con = 1; }
else if (nbN4Con[i] == maxNbN4Con) nbMax4Con ++;
if (nbN4Con[i] == 0) nbUnconnectedVertices ++;
}
shakeList(conHeap->val, conHeap->ind, conHeap->n, g->n / 2);
makeHeap(conHeap);
}
int countNbUnconnectedInHeap(Heap F) {
int nb = 0;
for (int i = 0; i < F->n; i ++)
if (nbN4Con[F->val[i]] == 0) nb ++;
return nb;
}
// Here other vertices may have index not NONE but they can not be in u component and then they are not neighbors
int updateHeapNbNAfterRemoval(int u, Heap heap, Graph g) {
int nbRemovedEdges = 0;
//assert(nbUnconnectedVertices == countNbUnconnectedInHeap(heap));
for (int *pp = g->lists[u]; *pp != NONE; pp ++) {
nbN4Con[*pp] --;
if (heap->ind[*pp] != NONE) {
// if ( nbOccs(*pp, heap->val, heap->n) != 1) printf("%d OUYE\n", *pp);
nbRemovedEdges ++;
if (nbN4Con[*pp]+1 == maxNbN4Con) nbMax4Con --;
if (nbN4Con[*pp] == 0) { // put unconnected vertice at the end of the heap (can leave current branch)
int pos = heap->ind[*pp];
if (0 && (nbUnconnectedVertices+1 != countNbUnconnectedInHeap(heap))) { printf("nbunconnected is not good : %d / %d\n", countNbUnconnectedInHeap(heap), nbUnconnectedVertices+1);exit(0); }
heapSwap(pos, heap->n - 1 - nbUnconnectedVertices, heap);
// update the heap
if ((pos > 0) && (nbN4Con[heap->val[pos]] > nbN4Con[*pp]+1))
heapBubbleUp(pos, heap);
else if (nbN4Con[heap->val[pos]] < nbN4Con[*pp]+1)
heapBubbleDown(heap, pos);
nbUnconnectedVertices++;
}
else {
heapBubbleDown(heap, heap->ind[*pp]);
}
}
}
//assert(nbUnconnectedVertices == countNbUnconnectedInHeap(heap));
return nbRemovedEdges;
}
// returns the position of a vertex of S[] with many neighbors in S[] (depending of mode).
int vertexWithManyConnections(Heap heap, int mode) {
assert(heap->n != 0);
if (heap->n == 1) return heap->val[0];
if (mode == MAX_CONNECTED_WEIGHTED_AT_RANDOM) {// Unsupported: nbE4Con is not up to date
nbE4Con = 0;
for (int i = 0; i < heap->n; i ++)
nbE4Con += nbN4Con[heap->val[i]];
return chooseWeightedRandom(nbN4Con, heap->val, heap->n, nbE4Con);
}
if (mode == MAX_CONNECTED_BEST_AT_RANDOM)
return heap->val[rand()%nbMax4Con]; // perhaps not a vertex with the max number of neighbors
return heap->val[0];
}
graph.h 0 → 100644
#ifndef _H_graph
#define _H_graph
/*
* graph.h
* graphes
*
* Created by Stphane on 19/02/18.
* Copyright 2018 __MyCompanyName__. All rights reserved.
*
*/
#include "lists.h"
#include "heap.h"
#include "sets.h"
// Choice of a vertex (choose at random among the best or use a weighted random choice)
#define MAX_CONNECTED_WEIGHTED_AT_RANDOM 0
#define MAX_CONNECTED_BEST_AT_RANDOM 1
typedef struct graph * Graph;
struct graph {
int n; /* nb vertices */
int m; /* nb edges */
LIST *adj;
int **slists; // neighbors sorted lists
int **lists; // neighbors lists (reordered before separation to place first current vertices)
int *nadj;
SET *neighbors;
};
// For the heap sorted with numbers of connections
extern Heap conHeap;
extern int *nbN4Con; // for each vertex the number of its neighbors in the cluster
extern int nbE4Con, nbMax4Con, maxNbN4Con;
extern int nbUnconnectedVertices;
Graph newGraph(int n, int m, LIST *adj, int *nadj);
int areNeighbours(int u, int v, Graph g);
void printGraph(Graph g);
int nbNeighborsInHeap(int u, Heap F, Graph g);
int nbVerticeInHeap(int list[], int n, Heap F, Graph g);
int nbNeighborsInList(int u, SET V, int *S, int n, Graph g);
int hasNoNeighborInSet(int vertex, SET V, Graph g);
int hasNeighborsInSubtree(int vertex, SET V, Graph g);
int haveSameNeighbors(int u, int v, Graph g);
int hasMoreConnections(int a, int b);
void allocConnectionsHeap(Graph g);
int updateHeapNbNAfterRemoval(int u, Heap heap, Graph g);
int vertexWithManyConnections(Heap heap, int mode);
void updateNbMaxConInHeap(Heap H);
int rebuildConHeap(Heap heap);
void initConHeap(Graph g);
#endif
heap.c 0 → 100644
/*
* tas.c
* packing-satmod
*
* Created by Stphane on 11/11/14.
* Copyright 2014 __MyCompanyName__. All rights reserved.
*
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
//#include <tcl.h>
#include "heap.h"
#include "utils.h"
Heap allocHeap (int size, int (*lt)(int, int)) {
Heap F;
F = malloc(sizeof(struct heap));
assert(F != NULL);
F->size = size;
F->n = 0;
F->val = malloc(size*sizeof(int));
assert(F->val != NULL);
F->ind = malloc(size*sizeof(int));
assert(F->ind != NULL);
F->lt = lt;
return F;
}
void heapSetCompare(Heap F, int (*lt)(int, int)) {
F->lt = lt;
}
void freeHeap(Heap F) {
free(F->val);
free(F->ind);
free(F);
}
void resetHeap(Heap F) {
F->n = 0;
}
void heapSwap (int i, int j, Heap F) {
int x = F->val[i];
F->val[i] = F->val[j];
F->ind[F->val[i]] = i;
F->val[j] = x;
F->ind[x] = j;
}
void heapBubbleDown(Heap F, int i) {
int i_min;
DEBUT:
i_min = i;
if (FG(i) >= F->n)
return;
if (F->lt(F->val[FG(i)], F->val[i_min]))
i_min = FG(i);
if ((FD(i) < F->n) && F->lt(F->val[FD(i)], F->val[i_min]))
i_min = FD(i);
if (i_min != i) {
heapSwap(i, i_min, F);
i = i_min;
goto DEBUT;
}
}
void makeHeap(Heap F) {
int i;
for (i = (F->n-1)/2; i >= 0; i --)
heapBubbleDown(F, i);
}
int heapExtractMin (Heap F) {
int min = F->val[0];
F->ind[min] = NONE;
F->n --;
F->val[0] = F->val[F->n];
F->ind[F->val[0]] = 0;
heapBubbleDown(F, 0);
//heapVerif(F, weight);
return min;
}
void heapRemove (int x, Heap F) {
int i = F->ind[x];
F->ind[x] = NONE;
F->n --;
if (i == F->n)
return;
F->val[i] = F->val[F->n];
F->ind[F->val[i]] = i;
if (F->lt(x, F->val[i])) //(weight[F->val[i]] > weight[x])
heapBubbleDown(F, i);
else
heapBubbleUp(i, F);
//heapVerif(F, weight);
}
void heapJustRemove (int x, Heap F) {
int i = F->ind[x];
F->ind[x] = NONE;
F->n --;
if (i == F->n)
return;
F->val[i] = F->val[F->n];
F->ind[F->val[i]] = i;
}
void heapRemoveAll(Heap heap) {
for (int i = 0; i < heap->n; i ++)
heap->ind[heap->val[i]] = NONE;
heap->n = 0;
}
/* Decrease the value of x to w. */
void heapBubbleUp (int i, Heap F) {
while ( (i > 0) && (F->lt(F->val[i], F->val[PERE(i)])) ) { // (weight[F->val[PERE(i)]] > w) ) {
heapSwap(PERE(i), i, F);
i = PERE(i);
}
}
/* Decrease the value of x to w. */
void heapDecreaseKey (int x, Heap F) {
heapBubbleUp(F->ind[x], F);
}
void heapInsert (int x, Heap F) {
F->val[F->n] = x;
F->ind[x] = F->n;
F->n ++;
heapBubbleUp(F->n-1, F);
}
void heapJustAdd (int x, Heap F) {
F->val[F->n] = x;
F->ind[x] = F->n;
F->n ++;
}
void heapVerif(Heap F, int *values) {
for (int i = 0; i < F->n; i ++) {
if ((FG(i) < F->n) && (F->lt(F->val[FG(i)], F->val[i]))) { //(w[F->val[i]] > w[F->val[FG(i)]])) {
printf("heap mal configured %d/%d :: \n", F->val[i], F->val[FG(i)]);
heapPrint(F, values, FG(i)+1, 1585189);
exit(0);
}
if ((FD(i) < F->n) && (F->lt(F->val[FD(i)], F->val[i]))) { //(w[F->val[i]] > w[F->val[FD(i)]])) {
printf("heap mal configured %d/%d :: \n", F->val[i], F->val[FD(i)]);
heapPrint(F, values, FD(i)+1, 1585189);
exit(0);
}
}
}
void heapPrint(Heap F, int *weight, int n, int infini) {
for (int i = 0; i < n; i ++)
if (weight[F->val[i]] >= infini)
printf("- ");
else
printf("%d ", weight[F->val[i]]);
printf("\n");
}
void heapPrintMax(Heap F, int *weight) {
int max = weight[F->val[0]];
printf("heap max=%d ", max);
for (int i = 0; i < F->n; i ++)
if (weight[F->val[i]] == max)
printf("%d ", F->val[i]);
printf("\n");
}
int isInHeap(int x, Heap F) {
return (F->ind[x] != NONE);
}
//
// minheap :: Heap used to partition the elements that have the value min from the others (for a given evaluation val[])
//
// unused
int minheapCalculMin(Heap F, int val[]) {
int min = val[F->val[0]];
for (int i = 1; i < F->n; i ++)
if (val[F->val[i]] < min) min = val[F->val[i]];
return min;
}
// Recalculate min after all min have been removed, bound is the minimal value of the min
void minheapUpdateMin(Heap F, int bound, int val[]) {
int newmin = val[F->val[0]];
if (newmin > bound) {
for (int i = 1; i < F->n; i++)
if (val[F->val[i]] < newmin) {
newmin = val[F->val[i]];
if (newmin == bound) break;
}
}
F->min = newmin;
}
void minheapSearchAndPackMins(Heap F, int val[]) {
F->min = val[F->val[0]];
for (int i = 1; i < F->n; i ++)
if (val[F->val[i]] < F->min) F->min = val[F->val[i]];
F->nbmin = 0;
for (int i = 0; i < F->n; i ++)
if (val[F->val[i]] == F->min) {
heapSwap(F->nbmin, i, F);
F->nbmin ++;
}
}
void minheapPackMins(Heap F, int val[]) {
// Suppose that F->min is up to date
F->nbmin = 0;
for (int i = 0; i < F->n; i ++)
if (val[F->val[i]] == F->min) {
heapSwap(F->nbmin, i, F);
F->nbmin ++;
}
}
void minheapRemove(int x, Heap F, int val[]) {
int i = F->ind[x];
int *p = F->val + i;
F->ind[x] = NONE;
F->n --;
//if (F->n == 0) { F->nbmin = 0; return; }
if (val[x] > F->min) {
// x is not a min
if (i < F->n) {
*p = F->val[F->n];
F->ind[*p] = i;
}
return;
}
// x is a min
F->nbmin --;
// x was the last of the list
if (i == F->n) return;
// x was the uniq element with min value
if (F->nbmin == 0) {
// copy last element at position i and rebuild mins
int last = F->val[F->n];
*p = last;
F->ind[last] = i;
minheapUpdateMin(F, F->min+1, val);
minheapPackMins(F, val);
return;
}
// Copy last min at the position i
if (i != F->nbmin) {
*p = F->val[F->nbmin];
F->ind[*p] = i;
}
// Copy last non min element after the mins if necessary
if (F->n > F->nbmin) {
F->val[F->nbmin] = F->val[F->n];
F->ind[F->val[F->nbmin]] = F->nbmin;
}
}
void minheapJustRemove(int x, Heap F, int val[]) {
int i = F->ind[x];
int *p = F->val + i;
F->ind[x] = NONE;
F->n --;
if (val[x] > F->min) {
// x is not a min
if (i < F->n) {
*p = F->val[F->n];
F->ind[*p] = i;
}
return;
}
// x is a min
F->nbmin --;
// x was the last of the list
if (i == F->n) return;
// Copy last min at the position i
if (i != F->nbmin) {
*p = F->val[F->nbmin];
F->ind[*p] = i;
}
// Copy last non min element after the mins if necessary
if (F->n > F->nbmin) {
F->val[F->nbmin] = F->val[F->n];
F->ind[F->val[F->nbmin]] = F->nbmin;
}
}
// The value val[x] of x has decreased strictly
void minheapDecreaseValue(int x, Heap F, int val[]) {
if (val[x] < F->min) {
F->min = val[x];
F->nbmin = 1;
if (F->ind[x] > 0) heapSwap(0, F->ind[x], F);
return;
}
if (val[x] == F->min) {
if (F->ind[x] >= F->nbmin) heapSwap(F->nbmin, F->ind[x], F);
F->nbmin ++;
}
}
heap.h 0 → 100644
#ifndef _H_tas
#define _H_tas
/*
* tas.h
* packing-satmod
*
* Created by Stéphane on 11/11/14.
* Copyright 2014 __MyCompanyName__. All rights reserved.
*
*/
typedef struct heap
{
int size; /* Allocated size. */
int n; /* Number of values in the heap. */
int *val;
int *ind; /* Indexes of the values in val[]. */
int (*lt)(int, int);
int min; // for a certain evaluation, the minimal value for the elements of the heap
int nbmin; // the number of elements in the heap that have for evaluation the value min
}
* Heap;
#define FG(i) ((i)*2+1)
#define FD(i) ((i)*2+2)
#define PERE(i) (((i)-1)/2)
Heap allocHeap (int size, int (*lt)(int, int));
void freeHeap(Heap F);
void heapSetCompare(Heap F, int (*lt)(int, int));
void resetHeap(Heap F);
void heapBubbleDown(Heap F, int i);
void makeHeap(Heap F);
int heapExtractMin (Heap F);
void heapBubbleUp (int i, Heap F);
void heapRemove (int x, Heap F);
void heapJustRemove (int x, Heap F);
void heapRemoveAll(Heap heap);
void heapDecreaseKey (int x, Heap F);
void heapInsert (int x, Heap F);
void heapJustAdd (int x, Heap F);
void heapSwap (int i, int j, Heap F);
void heapPrint(Heap F, int *weight, int n, int infini);
void heapVerif(Heap F, int *w);
void heapPrintMax(Heap F, int *weight);
int isInHeap(int x, Heap F);
// minheaps
void minheapUpdateMin(Heap F, int bound, int val[]);
void minheapSearchAndPackMins(Heap F, int val[]);
void minheapPackMins(Heap F, int val[]);
void minheapRemove(int x, Heap F, int val[]);
void minheapJustRemove(int x, Heap F, int val[]);
void minheapDecreaseValue(int x, Heap F, int val[]);
#endif
This diff is collapsed.
//
// Created by Stephane on 08/04/2020.
//
#ifndef SGA_CRITICAL_PATH_H
#define SGA_CRITICAL_PATH_H
#include "graph.h"
#include "tree.h"
#include "sets.h"
extern int nbCallsEject;
Node makeEjectionsInCriticalBranch(Node root, Graph g);
int listEjections(Node root, int date, int maxEjections, int maxSearches, Graph g);
Node makeEjections(Node root, int nbEjections, Graph g);
int selectEjections(int *nodes, int *corr, int nb, int maxLen);
Node ejectNode(Node root, Node node, Node cc, Graph g);
int evaluateSwap(Node node, Node cc, Graph g);
Node markCriticalBranch(Node root, int date, int single, Graph g);
int verifyCriticalBranch(Node root, Node cc, int date, Graph g);
Node searchCriticalCorrespondant(Node node, int *maxHeight, int date, int store, Graph g);
#endif //SGA_CRITICAL_PATH_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment