GithubHelp home page GithubHelp logo

antonikania / metaheuristics Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.83 MB

Various metaheuristic algorithms designed to solve the clique problem

CMake 0.01% C++ 2.47% Shell 0.02% Jupyter Notebook 97.49%

metaheuristics's Introduction

Metaheuristics

This repository contains code from the Metaheuristics course at my university. The codebase includes various metaheuristic algorithms designed to solve the clique problem. Implemented algorithms:

  • Comprehensive review
  • Random solution
  • Hill Climbing
  • Tabu Search
  • Simulated Annealing
  • Genetic Algorithm

Clique Problem

The clique problem involves identifying the largest clique within a given graph. A clique is a subset of vertices where every pair is connected by an edge, forming a complete subgraph. The challenge is to determine the size of the largest clique, known as the graph's maximum clique. This problem is significant in various fields such as social network analysis, bioinformatics, and computer science, particularly due to its NP-complete complexity, making it computationally challenging to solve for large graphs.

Graph Representation

    [ 0 1 1 1 1 ]
    [ 1 0 1 0 1 ]
A = [ 1 1 0 1 1 ]
    [ 1 0 1 0 0 ]
    [ 1 1 1 0 0 ]

graphviz

graph { 1 -- 2; 1 -- 3; 1 -- 4; 1 -- 5; 2 -- 3; 2 -- 5; 3 -- 4; 3 -- 5; }

In this example, it can be seen that the matrix is mirrored across the diagonal, as the value at [4,2] is the same as at [2,4], representing the same connection, assuming that graphs are undirected.

    [ 0 1 1 1 1 ]     [ 0 1 1 1 1 ]
    [ 1 0 1 * 1 ]     [ 1 0 1 0 1 ]
A = [ 1 1 0 1 1 ]  =  [ 1 1 0 1 1 ]
    [ 1 0 1 0 0 ]     [ 1 * 1 0 0 ]
    [ 1 1 1 0 0 ]     [ 1 1 1 0 0 ]

By dropping the lower triangle, we do not lose any information.

    [ 0 1 1 1 1 ]
    [   0 1 0 1 ]
A = [     0 1 1 ]
    [       0 0 ]
    [         0 ]

This can be further simplified to the following matrix, as we are not interested in self-connections.

         (2)(3)(4)(5)
    (1) [ 1  1  1  1 ]
A = (2) [    1  0  1 ]
    (3) [       1  1 ]
    (4) [          0 ]

Goal Function

This section explains why the modifications were made to the matrix in the first place.

The adjacency matrix in its current state represents every possible edge in the graph, so if the graph is complete, it will only contain ones in the matrix. This simplifies the score functions as the

Let's view it in the previous example. The following subgraph will be checked and scored {1, 1, 1, 0, 1}, so nodes 1, 2, 3, and 5 are considered. The following adjacency matrix represents this subgraph:

         (2)(3)(5)
    (1) [ 1  1  1 ]
A = (2) [    1  1 ]
    (3) [       1 ]

graphviz(1)

graph { 1 -- 2; 1 -- 3; 1 -- 5; 2 -- 3; 2 -- 5; 3 -- 5; }

Using the following code from the goal_factory function, the adjacency matrix for this subgraph will be scored as 6:

for (char i : subgraph_adjacency_matrix) {
    if (i == 1) {
        score++;
    } else {
        score -= 100;
    }
}
```c++
for (char i : subgraph_adjacency_matrix) {
    if (i == 1) {
        score++;
    } else {
        score -= 100;
    }
}

Here, it can also be seen that each missing connection in the subgraph decreases the score by 100 points.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.