---
name: "Graph::Maker::SmallWorldK"
section: "3pm"
platform: "linux"
package: "libgraph-maker-perl"
version: "0.02-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Graph::Maker::SmallWorldK"
---

# Graph::Maker::SmallWorldK(3pm)

Creates a small world graph using Kleinberg's model in 2-dimensions

## NAME

Graph::Maker::SmallWorldK - Creates a small world graph using Kleinberg's model in 2-dimensions

## VERSION

Version 0.01

## SYNOPSIS

Creates a small world graph according to Kleinberg's long-range connection model. In Kleinberg's model a small world graph is connected to nodes within manhattan (L1) distance P and has Q long range contacts referred to as K(N, P, Q, alpha) or K\*(N, P, Q, alpha) (if it wraps-around). In addition Kleinberg's model gives all nodes a position so that routing can be done efficiently using a greedy algorithm, these positions are set in the 'pos' attribute for the vertices. If the graph is directed then edges are added in both directions to create an undirected graph.

```
        use strict;
        use warnings;
        use Graph;
        use Graph::Maker;
        use Graph::Maker::SmallWorldK;
        my $g = new Graph::Maker('small_world_k', N => 10, P => 2, undirected => 1);
        my $g2 = new Graph::Maker('small_world_k', N => 10, P => 2, Q => 1, alpha => 2.1, undirected => 1);
        # work with the graph
```

## FUNCTIONS

### new %params

Creates a small world graph with N^2 nodes in a 2-d grid, with connections to nodes within P manhattan units of distance, and Q random long-range connections to nodes determined by d(u, v) \*\* -alpha (where d is the manhattan distance) according to Kleinberg's model (the grid wraps-around if cyclic is specified). The recognized parameters are N, P, Q, cyclic, graph\_maker,  and alpha any others are passed onto Graph's constructor. If N is not given it defaults to 0. If P is not given it defaults to 1. If Q is not given it defaults to 0. If alpha is not given it defaults to 2 (2 \<= alpha \<= 3 allows poly-logarithmic routing using a local greedy algorithm). If cyclic is set then the "edges" of the grid are connected. The vertex attribute pos will be set to an array reference of the nodes d-dimensional position. If graph\_maker is specified it will be called to create the Graph class as desired (for example if you have a subclass of Graph), this defaults to create a Graph with the parameters specified.

## AUTHOR

Matt Spear, `"<batman900+cpan at gmail.com>"`

## BUGS

Please report any bugs or feature requests to `"bug-graph-maker-SmallWorldK at rt.cpan.org"`, or through the web interface at \<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Graph-Maker\>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

## COPYRIGHT & LICENSE

Copyright 2008 Matt Spear, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
