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

Added Karps Minimum Cycle Algorithm #281

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

GYuvanShankar
Copy link

@GYuvanShankar GYuvanShankar commented Dec 19, 2021

Based on issue #272.
Implemented Karps Minimum Cycle Algorithm.

@jeremy-murphy
Copy link
Contributor

jeremy-murphy commented Jan 4, 2022

Thanks for taking the time to implement this. It looks good, but as I said earlier it will take a few rounds of feedback to get it to be consistent with existing BGL code.

Please take a look at an existing similar algorithm such as Howard's cycle ratio algorithm and imitate what is there. There is a lot more to an algorithm than just the implementation, namely:

  • Documentation
  • Examples
  • Unit tests

PS. One thing that I do not expect anyone to imitate from the existing code are named parameters.

@jeremy-murphy jeremy-murphy marked this pull request as draft January 4, 2022 01:45
@jeremy-murphy
Copy link
Contributor

I marked this as a draft for now in the hope that it won't trigger the CI every time you push -- I'm still learning how this CI system works. When you have completed everything then mark it ready for review again.

namespace boost
{
template<typename Graph>
double karp_minimum_mean_cycle(Graph g)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it doesn't roll off the tongue very well, the paper does call it the "minimum cycle mean".

@GYuvanShankar
Copy link
Author

Thanks for looking into this. I will start the documentation, was just waiting for someone to approve of the code.

@GYuvanShankar GYuvanShankar marked this pull request as ready for review January 6, 2022 08:28
@jeremy-murphy
Copy link
Contributor

Hi @GYuvanShankar , thanks, it's looking good! I'll start a review, in which I'll make some (or many) small comments in the code itself.

@jeremy-murphy
Copy link
Contributor

When implementing algorithms, of any kind, it's important to be really familiar with the literature on them. In this case there is at least one paper that demonstrates a defect with Karp's algorithm and an alternative solution: https://www.cs.colostate.edu/~rmm/minCycleMean.pdf

I recommend that you read widely on MCM and then come back with a discussion on which algorithm(s) you propose to implement and why. This is an interesting overview, although I have only glanced at it: https://www.researchgate.net/profile/Rajesh-Gupta-10/publication/2689582_An_Experimental_Study_of_Minimum_Mean_Cycle_Algorithms/links/546e071f0cf29806ec2e6dba/An-Experimental-Study-of-Minimum-Mean-Cycle-Algorithms.pdf

Copy link
Contributor

@jeremy-murphy jeremy-murphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so sorry, I didn't realize that these review comments were in a "pending" state, not published.

#ifndef BOOST_GRAPH_KARP_MINIMUM_CYCLE_MEAN_HPP
#define BOOST_GRAPH_KARP_MINIMUM_CYCLE_MEAN_HPP

#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't allow <iostream> in header files: it brings in a lot of names and static objects, etc.

namespace boost
{
template<typename Graph>
double karp_minimum_cycle_mean(Graph g)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want to take g by const reference.

typename property_map<Graph, edge_weight_t>::type weight = get(edge_weight,g);
typedef typename boost::graph_traits<Graph>::out_edge_iterator out_edge_iterator;
BOOST_CONCEPT_ASSERT((GraphConcept< Graph >));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment about this file in general, we don't have automatic Clang format running (yet), so please follow the convention in the rest of the library:

  • whitespace around operators: a + b, a = b, etc.

</P>
<P>
This algorithm was described by Richard M. Karp in his paper
<A HREF="./dasdan-dac99.pdf">A characterization of the minimum cycle mean in a digraph</A></P>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give a proper citation of the paper.

@jesseli2002
Copy link
Contributor

PS. One thing that I do not expect anyone to imitate from the existing code are named parameters.
Why not? Are named parameters being deprecated or something?

@jeremy-murphy
Copy link
Contributor

PS. One thing that I do not expect anyone to imitate from the existing code are named parameters.
Why not? Are named parameters being deprecated or something?

It was a courageous and ambitious experiment at the time (20 something years ago) but it adds an awful lot of complexity and maintenance burden to the code for questionable benefit. In the long run, I would like to strip them out. I think we could achieve similar benefits, if wanted, from much simpler overloads and stronger types.

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

Successfully merging this pull request may close these issues.

5 participants