scripts/chg-len.py
author Peter Kovacs <kpeter@inf.elte.hu>
Wed, 29 Apr 2009 03:15:24 +0200
changeset 640 6c408d864fa1
parent 376 4b2382fd80ef
child 733 abf31e4af617
permissions -rwxr-xr-x
Support negative costs and bounds in NetworkSimplex (#270)

* The interface is reworked to support negative costs and bounds.
- ProblemType and problemType() are renamed to
SupplyType and supplyType(), see also #234.
- ProblemType type is introduced similarly to the LP interface.
- 'bool run()' is replaced by 'ProblemType run()' to handle
unbounded problem instances, as well.
- Add INF public member constant similarly to the LP interface.
* Remove capacityMap() and boundMaps(), see also #266.
* Update the problem definition in the MCF module.
* Remove the usage of Circulation (and adaptors) for checking feasibility.
Check feasibility by examining the artifical arcs instead (after solving
the problem).
* Additional check for unbounded negative cycles found during the
algorithm (it is possible now, since negative costs are allowed).
* Fix in the constructor (the value types needn't be integer any more),
see also #254.
* Improve and extend the doc.
* Rework the test file and add test cases for negative costs and bounds.
alpar@272
     1
#! /usr/bin/env python
alpar@272
     2
alpar@272
     3
import sys
alpar@376
     4
alpar@376
     5
from mercurial import ui, hg
alpar@422
     6
from mercurial import util
alpar@422
     7
alpar@422
     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@376
    17
u = ui.ui()
alpar@376
    18
r = hg.repository(u, ".")
alpar@376
    19
N = r.changectx(".").rev()
alpar@376
    20
lengths=[0]*(N+1)
alpar@376
    21
for i in range(N+1):
alpar@376
    22
    p=r.changectx(i).parents()
alpar@376
    23
    if p[0]:
alpar@376
    24
        p0=lengths[p[0].rev()]
alpar@272
    25
    else:
alpar@376
    26
        p0=-1
alpar@376
    27
    if len(p)>1 and p[1]:
alpar@376
    28
        p1=lengths[p[1].rev()]
alpar@272
    29
    else:
alpar@376
    30
        p1=-1
alpar@376
    31
    lengths[i]=max(p0,p1)+1
alpar@376
    32
print lengths[N]