scripts/chg-len.py
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 17 Apr 2009 18:04:36 +0200
changeset 656 e6927fe719e6
parent 390 4b2382fd80ef
child 780 abf31e4af617
permissions -rwxr-xr-x
Support >= and <= constraints in NetworkSimplex (#219, #234)

By default the same inequality constraints are supported as by
Circulation (the GEQ form), but the LEQ form can also be selected
using the problemType() function.

The documentation of the min. cost flow module is reworked and
extended with important notes and explanations about the different
variants of the problem and about the dual solution and optimality
conditions.
alpar@272
     1
#! /usr/bin/env python
alpar@272
     2
alpar@272
     3
import sys
alpar@390
     4
alpar@390
     5
from mercurial import ui, hg
alpar@439
     6
from mercurial import util
alpar@439
     7
alpar@439
     8
util.rcpath = lambda : []
alpar@272
     9
alpar@272
    10
if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
alpar@272
    11
    print """
alpar@272
    12
This utility just prints the length of the longest path
alpar@272
    13
in the revision graph from revison 0 to the current one.
alpar@272
    14
"""
alpar@272
    15
    exit(0)
alpar@272
    16
alpar@390
    17
u = ui.ui()
alpar@390
    18
r = hg.repository(u, ".")
alpar@390
    19
N = r.changectx(".").rev()
alpar@390
    20
lengths=[0]*(N+1)
alpar@390
    21
for i in range(N+1):
alpar@390
    22
    p=r.changectx(i).parents()
alpar@390
    23
    if p[0]:
alpar@390
    24
        p0=lengths[p[0].rev()]
alpar@272
    25
    else:
alpar@390
    26
        p0=-1
alpar@390
    27
    if len(p)>1 and p[1]:
alpar@390
    28
        p1=lengths[p[1].rev()]
alpar@272
    29
    else:
alpar@390
    30
        p1=-1
alpar@390
    31
    lengths[i]=max(p0,p1)+1
alpar@390
    32
print lengths[N]