Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ant-colony optimisation metaheuristic graph colouring function #2250

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

professorcode1
Copy link
Contributor

No description provided.

@ntamas
Copy link
Member

ntamas commented Nov 4, 2022

The reason for the failure is written in the test log if you scroll up a bit in the logs:

==13205==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8000 byte(s) in 1 object(s) allocated from:
    #0 0x561c260c8048 in __interceptor_calloc (/home/vsts/work/1/s/build/tests/example_igraph_coloring+0xab048) (BuildId: 0c12bb4f24227d1a173a8f2565fe073c9c24f344)
    #1 0x561c2611d036 in igraph_vector_int_init /home/vsts/work/1/s/src/core/vector.pmt:144:21
    #2 0x561c261469f5 in igraph_vertex_coloring_AntColony /home/vsts/work/1/s/src/misc/coloring.c:281:5
    #3 0x561c26104890 in main /home/vsts/work/1/s/examples/simple/igraph_coloring.c:34:5
    #4 0x7f54a1765d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)

Direct leak of 272 byte(s) in 1 object(s) allocated from:
    #0 0x561c260c8286 in __interceptor_realloc (/home/vsts/work/1/s/build/tests/example_igraph_coloring+0xab286) (BuildId: 0c12bb4f24227d1a173a8f2565fe073c9c24f344)
    #1 0x561c2611e73a in igraph_vector_int_reserve /home/vsts/work/1/s/src/core/vector.pmt:474:11
    #2 0x561c26107dee in igraph_vector_int_resize /home/vsts/work/1/s/src/core/vector.pmt:1261:5
    #3 0x561c2613dd44 in igraph_i_neighbors /home/vsts/work/1/s/src/graph/type_indexededgelist.c:929:5
    #4 0x561c26146f3a in DSatur /home/vsts/work/1/s/src/misc/coloring.c:205:9
    #5 0x561c26146ba5 in igraph_vertex_coloring_AntColony /home/vsts/work/1/s/src/misc/coloring.c:299:5
    #6 0x561c26104890 in main /home/vsts/work/1/s/examples/simple/igraph_coloring.c:34:5
    #7 0x7f54a1765d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)

SUMMARY: AddressSanitizer: 8272 byte(s) leaked in 2 allocation(s).

Basically, you allocate a new vector in saturation_degree but you never free the memory when you are done with it.

The correct usage pattern for allocating and freeing a new int vector would be:

IGRAPH_VECTOR_INIT_INT_FINALLY(&saturation_degree, vc);

[...use the vector the way you want...]

igraph_vector_int_destroy(&saturation_degree);
IGRAPH_FINALLY_CLEAN(1);

IGRAPH_VECTOR_INIT_INT_FINALLY() is a shorthand for this:

IGRAPH_CHECK(igraph_vector_int_init(&saturation_degree, vc));
IGRAPH_FINALLY(igraph_vector_int_destroy, &saturation_degree);

The important bit is the IGRAPH_FINALLY part, which registers the vector to be destroyed should an error happen in any subsequent calls that are wrapped in IGRAPH_CHECK(). When you are done with your vector, you must call igraph_vector_int_destroy() manually, and then remove it from the "finally" stack with IGRAPH_FINALLY_CLEAN(1).

A similar problem exists in DSatur() where you allocate the neighbours vector without proper error handling and cleanup.

If you do not know these macros, check out section 5.4 of the chapter about error handling in the docs.

@ntamas ntamas changed the title setup complete An Ant-colony optimisation metaheuristic graph colouring function Nov 4, 2022
@ntamas ntamas changed the title An Ant-colony optimisation metaheuristic graph colouring function Ant-colony optimisation metaheuristic graph colouring function Nov 4, 2022
@professorcode1
Copy link
Contributor Author

Thank you for the help. I primarily program in C++ with smart pointers so I completely forgot about the manual memory allocation and I didn't know the logs will have debug statements. I will fix it.

@stale
Copy link

stale bot commented Mar 25, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issues that have been inactive for a long time; will be closed in the absence of further activity label Mar 25, 2023
@professorcode1
Copy link
Contributor Author

Commenting to prevent issue from being closed. Can we keep this open for now. I can't continue on it before we settle the situation with the implementation of the sets.

@ntamas ntamas added todo Triaged for implementation in some unspecified future version and removed stale Issues that have been inactive for a long time; will be closed in the absence of further activity todo Triaged for implementation in some unspecified future version labels Mar 27, 2023
@ntamas
Copy link
Member

ntamas commented Mar 27, 2023

Removed the stale label so it will remain open until stalebot makes its rounds again :)

@codecov
Copy link

codecov bot commented Jun 4, 2023

Codecov Report

Merging #2250 (3d504fb) into master (e84149a) will increase coverage by 0.00%.
The diff coverage is 87.09%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2250   +/-   ##
=======================================
  Coverage   83.46%   83.46%           
=======================================
  Files         376      376           
  Lines       61576    61638   +62     
=======================================
+ Hits        51394    51448   +54     
- Misses      10182    10190    +8     
Impacted Files Coverage Δ
src/misc/coloring.c 94.76% <87.09%> (-3.69%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e84149a...3d504fb. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants