Commit 4afe752b authored by Kai Zhang's avatar Kai Zhang

add pagerank

parent ce5e3679
#include "IGraph/Internal/Structure.chs.h" #include "IGraph/Internal/Structure.chs.h"
int __c2hs_wrapped__igraph_pagerank(const igraph_t * graph,
igraph_pagerank_algo_t algo,
igraph_vector_t * vector,
igraph_real_t * value,
const igraph_vs_t * vids,
igraph_bool_t directed,
igraph_real_t damping,
const igraph_vector_t * weights,
void * options)
{
return igraph_pagerank(graph,
algo,
vector,
value,
*vids,
directed,
damping,
weights,
options);
}
int __c2hs_wrapped__igraph_induced_subgraph(const igraph_t * graph, int __c2hs_wrapped__igraph_induced_subgraph(const igraph_t * graph,
igraph_t * res, igraph_t * res,
const igraph_vs_t * vids, const igraph_vs_t * vids,
......
...@@ -5,15 +5,23 @@ import Foreign ...@@ -5,15 +5,23 @@ import Foreign
#include "cbits/haskelligraph.c" #include "cbits/haskelligraph.c"
{#enum igraph_neimode_t as Neimode {underscoreToCase} deriving (Show, Eq) #} {#enum igraph_neimode_t as Neimode {underscoreToCase}
deriving (Show, Eq) #}
{#enum igraph_edgeorder_type_t as EdgeOrderType {underscoreToCase} deriving (Show, Eq) #} {#enum igraph_edgeorder_type_t as EdgeOrderType {underscoreToCase}
deriving (Show, Eq) #}
{#enum igraph_spincomm_update_t as SpincommUpdate {underscoreToCase} deriving (Show, Eq) #} {#enum igraph_spincomm_update_t as SpincommUpdate {underscoreToCase}
deriving (Show, Eq) #}
{#enum igraph_spinglass_implementation_t as SpinglassImplementation {underscoreToCase} deriving (Show, Eq) #} {#enum igraph_spinglass_implementation_t as SpinglassImplementation {underscoreToCase}
deriving (Show, Eq) #}
{#enum igraph_attribute_elemtype_t as AttributeElemtype {underscoreToCase} deriving (Show, Eq) #} {#enum igraph_attribute_elemtype_t as AttributeElemtype {underscoreToCase}
deriving (Show, Eq) #}
{#enum igraph_subgraph_implementation_t as SubgraphImplementation {underscoreToCase} {#enum igraph_subgraph_implementation_t as SubgraphImplementation {underscoreToCase}
deriving (Show, Read, Eq) #} deriving (Show, Read, Eq) #}
{#enum igraph_pagerank_algo_t as PagerankAlgo {underscoreToCase}
deriving (Show, Read, Eq) #}
...@@ -38,3 +38,13 @@ import Foreign.C.Types ...@@ -38,3 +38,13 @@ import Foreign.C.Types
, `Bool' , `Bool'
, `VectorPtr' , `VectorPtr'
, `ArpackOptPtr' } -> `Int' #} , `ArpackOptPtr' } -> `Int' #}
{#fun igraph_pagerank as ^ { `IGraphPtr'
, `PagerankAlgo'
, `VectorPtr'
, id `Ptr CDouble'
, %`IGraphVsPtr'
, `Bool'
, `Double'
, `VectorPtr'
, id `Ptr ()' } -> `Int' #}
...@@ -3,6 +3,7 @@ module IGraph.Structure ...@@ -3,6 +3,7 @@ module IGraph.Structure
, closeness , closeness
, betweenness , betweenness
, eigenvectorCentrality , eigenvectorCentrality
, pagerank
) where ) where
import Control.Monad import Control.Monad
...@@ -78,3 +79,19 @@ eigenvectorCentrality gr ws = unsafePerformIO $ do ...@@ -78,3 +79,19 @@ eigenvectorCentrality gr ws = unsafePerformIO $ do
arparck <- igraphArpackNew arparck <- igraphArpackNew
igraphEigenvectorCentrality (_graph gr) vptr nullPtr True True ws' arparck igraphEigenvectorCentrality (_graph gr) vptr nullPtr True True ws' arparck
vectorPtrToList vptr vectorPtrToList vptr
-- | Google's PageRank
pagerank :: Graph d
=> LGraph d v e
-> Maybe [Double]
-> Double -- ^ damping factor, usually around 0.85
-> [Double]
pagerank gr ws d = unsafePerformIO $ alloca $ \p -> do
vptr <- igraphVectorNew 0
vsptr <- igraphVsAll
ws' <- case ws of
Just w -> listToVector w
_ -> liftM VectorPtr $ newForeignPtr_ $ castPtr nullPtr
igraphPagerank (_graph gr) IgraphPagerankAlgoPrpack vptr p vsptr
(isDirected gr) d ws' nullPtr
vectorPtrToList vptr
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment