scripts/chg-len.py
author Peter Kovacs <kpeter@inf.elte.hu>
Tue, 15 Mar 2011 19:32:21 +0100
changeset 1047 ddd3c0d3d9bf
parent 439 62c1ed05e83f
permissions -rwxr-xr-x
Implement the scaling Price Refinement heuristic in CostScaling (#417)
instead of Early Termination.

These two heuristics are similar, but the newer one is faster
and not only makes it possible to skip some epsilon phases, but
it can improve the performance of the other phases, as well.
     1 #! /usr/bin/env python
     2 #
     3 # This file is a part of LEMON, a generic C++ optimization library.
     4 #
     5 # Copyright (C) 2003-2009
     6 # Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7 # (Egervary Research Group on Combinatorial Optimization, EGRES).
     8 #
     9 # Permission to use, modify and distribute this software is granted
    10 # provided that this copyright notice appears in all copies. For
    11 # precise terms see the accompanying LICENSE file.
    12 #
    13 # This software is provided "AS IS" with no warranty of any kind,
    14 # express or implied, and with no claim as to its suitability for any
    15 # purpose.
    16 
    17 import sys
    18 
    19 from mercurial import ui, hg
    20 from mercurial import util
    21 
    22 util.rcpath = lambda : []
    23 
    24 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
    25     print """
    26 This utility just prints the length of the longest path
    27 in the revision graph from revison 0 to the current one.
    28 """
    29     exit(0)
    30 
    31 u = ui.ui()
    32 r = hg.repository(u, ".")
    33 N = r.changectx(".").rev()
    34 lengths=[0]*(N+1)
    35 for i in range(N+1):
    36     p=r.changectx(i).parents()
    37     if p[0]:
    38         p0=lengths[p[0].rev()]
    39     else:
    40         p0=-1
    41     if len(p)>1 and p[1]:
    42         p1=lengths[p[1].rev()]
    43     else:
    44         p1=-1
    45     lengths[i]=max(p0,p1)+1
    46 print lengths[N]