~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to lib/neatogen/stress.c

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: stress.c,v 1.8 2008/04/25 14:38:29 erg Exp $ $Revision: 1.8 $ */
 
1
/* $Id: stress.c,v 1.14 2009/11/16 21:02:21 erg Exp $ $Revision: 1.14 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
1360
1360
    return Dij;
1361
1361
}
1362
1362
 
 
1363
 
 
1364
/* mdsModel:
 
1365
 * Update matrix with actual edge lengths
 
1366
 */
 
1367
float*
 
1368
mdsModel(vtx_data * graph, int nG)
 
1369
{
 
1370
    int i, j, e;
 
1371
    float *Dij;
 
1372
    int shift = 0;
 
1373
    double delta;
 
1374
 
 
1375
    if (graph->ewgts == NULL) return 0;
 
1376
 
 
1377
    /* first, compute shortest paths to fill in non-edges */
 
1378
    Dij = compute_weighted_apsp_packed(graph, nG);
 
1379
 
 
1380
    /* then, replace edge entries will user-supplied len */
 
1381
    for (i = 0; i < nG; i++) {
 
1382
        shift += i;
 
1383
        for (e = 1; e < graph[i].nedges; e++) {
 
1384
            j = graph[i].edges[e];
 
1385
            if (j < i) continue;
 
1386
            delta += abs(Dij[i*nG + j - shift] - graph[i].ewgts[e]);
 
1387
            Dij[i*nG + j - shift] = graph[i].ewgts[e];
 
1388
        }
 
1389
    }
 
1390
    if (Verbose) {
 
1391
        fprintf (stderr, "mdsModel: delta = %f\n", delta);
 
1392
    }
 
1393
    return Dij;
 
1394
}
 
1395
 
1363
1396
/* compute_apsp_packed:
1364
1397
 * Assumes integral weights > 0.
1365
1398
 */
1460
1493
    return Dij;
1461
1494
}
1462
1495
 
 
1496
#ifdef DEBUG
 
1497
static void dumpMatrix (float *Dij, int n)
 
1498
{
 
1499
    int i, j, count = 0;
 
1500
    for (i = 0; i < n; i++) {
 
1501
        for (j = i; j < n; j++) {
 
1502
            fprintf (stderr, "%.02f  ", Dij[count++]);
 
1503
        }
 
1504
        fputs ("\n", stderr);
 
1505
    }
 
1506
}
 
1507
#endif
 
1508
 
1463
1509
/* Accumulator type for diagonal of Laplacian. Needs to be as large
1464
1510
 * as possible. Use long double; configure to double if necessary.
1465
1511
 */
1505
1551
#ifdef ALTERNATIVE_STRESS_CALC
1506
1552
    double mat_stress;
1507
1553
#endif
 
1554
#ifdef NONCORE
 
1555
    FILE* fp = NULL;
 
1556
#endif
1508
1557
 
1509
1558
        /*************************************************
1510
1559
        ** Computation of full, dense, unrestricted k-D ** 
1535
1584
            agerr(AGPREV,
1536
1585
                  "is undefined. Reverting to the shortest path model.\n");
1537
1586
        }
 
1587
    } else if (model == MODEL_MDS) {
 
1588
        if (Verbose)
 
1589
            fprintf(stderr, "Calculating MDS model");
 
1590
        Dij = mdsModel(graph, n);
1538
1591
    }
1539
1592
    if (!Dij) {
1540
1593
        if (Verbose)
1654
1707
        fp = fopen(FILENAME, "wb");
1655
1708
        fwrite(lap2, sizeof(float), lap_length, fp);
1656
1709
        fclose(fp);
 
1710
        fp = NULL;
1657
1711
    }
1658
1712
#endif
1659
1713
 
1819
1873
                compute_stressf(coords, lap2, dim, n),
1820
1874
                iterations, elapsed_sec());
1821
1875
    }
 
1876
#ifdef WITH_CGRAPH
 
1877
    if (Verbose)
 
1878
        fprintf (stderr, "coords\n");
 
1879
#endif /* WITH_CGRAPH */
1822
1880
 
1823
1881
    for (i = 0; i < dim; i++) {
1824
1882
        for (j = 0; j < n; j++) {
1825
1883
            d_coords[i][j] = coords[i][j];
 
1884
#ifdef WITH_CGRAPH
 
1885
            if (Verbose)
 
1886
                fprintf (stderr, "%d\n",coords[i][j]);
 
1887
                        
 
1888
#endif /* WITH_CGRAPH */
1826
1889
        }
1827
1890
    }
 
1891
#ifdef NONCORE
 
1892
    if (fp)
 
1893
        fclose (fp);
 
1894
#endif
 
1895
 
1828
1896
    free(coords[0]);
1829
1897
    free(coords);
1830
1898