Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-igraph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-igraph
Commits
759c6c7c
Commit
759c6c7c
authored
9 years ago
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change API for IGraph.Layout
parent
c89f092d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
11 deletions
+40
-11
Layout.hs
src/IGraph/Layout.hs
+30
-5
Read.hs
src/IGraph/Read.hs
+10
-6
No files found.
src/IGraph/Layout.hs
View file @
759c6c7c
module
IGraph.Layout
(
kamadaKawai
(
getLayout
,
LayoutOpt
(
..
)
,
LayoutMethod
(
..
)
)
where
import
Foreign
(
nullPtr
)
...
...
@@ -15,21 +17,44 @@ import IGraph.Internal.Data
data
LayoutOpt
=
LayoutOpt
{
_seed
::
Maybe
[(
Double
,
Double
)]
,
_nIter
::
Int
}
deriving
(
Show
)
,
_method
::
LayoutMethod
,
_sigma
::
(
Int
->
Double
)
-- ^ [KamadaKawai] the base standard deviation of position change proposals
,
_startTemp
::
Double
-- ^ [KamadaKawai] the initial temperature for the annealing
,
_coolFact
::
Double
-- ^ [KamadaKawai] the cooling factor for the simulated annealing
,
_kkConst
::
(
Int
->
Double
)
-- ^ [KamadaKawai] The Kamada-Kawai vertex attraction constant
}
instance
Default
LayoutOpt
where
def
=
LayoutOpt
{
_seed
=
Nothing
,
_nIter
=
10000
,
_method
=
KamadaKawai
,
_sigma
=
\
x
->
fromIntegral
x
/
4
,
_startTemp
=
10
,
_coolFact
=
0.99
,
_kkConst
=
\
x
->
fromIntegral
$
x
^
2
}
kamadaKawai
::
Graph
d
=>
LGraph
d
v
e
->
Double
->
Double
->
Double
->
Double
->
LayoutOpt
->
[(
Double
,
Double
)]
kamadaKawai
gr
sigma
initemp
coolexp
kkconst
opt
=
unsafePerformIO
$
do
data
LayoutMethod
=
KamadaKawai
getLayout
::
Graph
d
=>
LGraph
d
v
e
->
LayoutOpt
->
[(
Double
,
Double
)]
getLayout
gr
opt
=
unsafePerformIO
$
do
mptr
<-
mat
igraphLayoutKamadaKawai
(
_graph
gr
)
mptr
(
_nIter
opt
)
sigma
initemp
coolexp
kkconst
useSeed
nullPtr
nullPtr
nullPtr
nullPtr
case
_method
opt
of
KamadaKawai
->
igraphLayoutKamadaKawai
gptr
mptr
iters
s
initemp
coolexp
kkconst
useSeed
nullPtr
nullPtr
nullPtr
nullPtr
[
x
,
y
]
<-
matrixPtrToColumnLists
mptr
return
$
zip
x
y
where
n
=
nNodes
gr
gptr
=
_graph
gr
iters
=
_nIter
opt
s
=
_sigma
opt
n
initemp
=
_startTemp
opt
coolexp
=
_coolFact
opt
kkconst
=
_kkConst
opt
n
(
useSeed
,
mat
)
=
case
_seed
opt
of
Just
xs
->
if
length
xs
/=
nNodes
gr
then
error
"Seed error: incorrect size"
...
...
This diff is collapsed.
Click to expand it.
src/IGraph/Read.hs
View file @
759c6c7c
module
IGraph.Read
(
readAdjMatrix
,
fromAdjMatrix
,
readAdjMatrixWeighted
)
where
...
...
@@ -14,18 +15,21 @@ readDouble = fst . fromJust . readSigned readExponential
{-# INLINE readDouble #-}
readAdjMatrix
::
Graph
d
=>
FilePath
->
IO
(
LGraph
d
B
.
ByteString
()
)
readAdjMatrix
fl
=
do
c
<-
B
.
readFile
fl
let
(
header
:
xs
)
=
B
.
lines
c
readAdjMatrix
=
fmap
fromAdjMatrix
.
B
.
readFile
fromAdjMatrix
::
Graph
d
=>
B
.
ByteString
->
LGraph
d
B
.
ByteString
()
fromAdjMatrix
bs
=
let
(
header
:
xs
)
=
B
.
lines
bs
mat
=
map
(
map
readDouble
.
B
.
words
)
xs
es
=
fst
$
unzip
$
filter
f
$
zip
[
(
i
,
j
)
|
i
<-
[
0
..
nrow
-
1
],
j
<-
[
0
..
nrow
-
1
]
]
$
concat
mat
nrow
=
length
mat
ncol
=
length
$
head
mat
if
nrow
/=
ncol
then
error
"
nrow != ncol"
else
return
$
mkGraph
(
nrow
,
Just
$
B
.
words
header
)
(
es
,
Nothing
)
i
n
i
f
nrow
/=
ncol
then
error
"fromAdjMatrix:
nrow != ncol"
else
mkGraph
(
nrow
,
Just
$
B
.
words
header
)
(
es
,
Nothing
)
where
f
((
i
,
j
),
v
)
=
i
<
j
&&
v
/=
0
{-# INLINE fromAdjMatrix #-}
readAdjMatrixWeighted
::
Graph
d
=>
FilePath
->
IO
(
LGraph
d
B
.
ByteString
Double
)
readAdjMatrixWeighted
fl
=
do
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment