Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of nikita m. kozlvovsky  >  Kruskal  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: a simple example
Class: Kruskal
Find minimum spanning tree using Kruskal algorithm
Author: By
Last change:
Date: 2004-11-10 16:58
Size: 813 bytes
 

Contents

Class file image Download
<?php
require_once("Kruskal.class.php");

function 
print_arcs($aText,$arcArray,$nArcs)
{
?>
<ul><?=$aText?><?=$nArcs?> arcs
<?    
    
foreach ($arcArray as $arc => $cost) {
?>
<li>arc <?=$arc?>, cost <?=$cost?>
<?
    
}
?>
</ul>
<?
}

$arcs = array(
    
"AB" => 17,
    
"BC" => 23,
    
"CD" => 32,
    
"DE" => 14,
    
"AF" => 11,
    
"FG" => 19,
    
"BG" => 28,
    
"GH" => 27,
    
"CH" => 21,
    
"HI" => 15,
    
"DI" => 11,
    
"IJ" => 42,
    
"EJ" => 41,
    
"FK" => 10,
    
"KL" => 26,
    
"GL" => 61,
    
"LM" => 20,
    
"HM" => 31,
    
"MN" => 18,
    
"IN" => 71,
    
"NP" => 21,
    
"JP" => 51
);

$k = new Kruskal($arcs);
$min_arcs $k->findMinimum();
$min_cost $k->calculateMinimumCost();


print_arcs('base graph ',$arcs,sizeof($arcs));
print_arcs("minimal spanning tree, cost $min_cost",$min_arcs,sizeof($min_arcs));

?>