kspa

package module
v0.0.0-...-328f88b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2022 License: MIT Imports: 17 Imported by: 0

README

kSPA - The k-Shortest Paths Algorithms Go package


Base interface


All kSP-algorithms implements Searcher interface:

	TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)
	TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)
	TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

where

  • g - pointer to the directed cyclic graph (DCG) MultiGraph,
  • srcId - the start point Id of desired paths,
  • srcIds - array of start points,
  • targetId - the end point Id of desired paths,
  • targetIds - array of end points,
  • topK - desired count of paths.

TopK function return the PriorityQueue object with top k-paths from the single source to the single target, where path's weight → min.

TopKOneToOne function return the PriorityQueue object with top k-paths for every pair single source → single target stored in corresponding positions of arrays srcIds and targetIds.

TopKOneToMany function return the PriorityQueue object with top k-paths for every pair single source → any target stored in i-th position of array srcIds and every position of targetIds.

All subroutines exposed above exploit MultiGraph object as storage of Directed cyclic Graph.

Directed Cyclic Graph


MultiGraph object supports several operations with DCG

func (g *MultiGraph) Build(ent EntitySeq)
func (g *MultiGraph) Pred(v int) MEdgeSeq
func (g *MultiGraph) Succ(u int) MEdgeSeq
func (g *MultiGraph) UpdateRelation(ent EntitySeq) error
func (g *MultiGraph) GetEdgeIndex(id1, id2 int) (int, bool)

where

  • Build - builds DCG from the Entities array,
  • Pred - returns all predecessors of the vertex with internal id v,
  • Succ - returns all successors of the vertex with internal id u,
  • UpdateRelation - update DCG from the Entities array; returns Error object if ent array consists new edges,
  • GetEdgeIndex - returns internal index of MultiEdge,
  • id1, id2 - Ids of verteces from Entity object,
  • ent - EntitySeq array of Entity-objects.

NOTE

For getting the internal ids of vertex use g.VertexIndex map of MultiGraph.


Input data


Package provide subroutines for export/import entities from Json files:

func FromJsonFile(fn string) (seq EntitySeq)
func ToJsonFile(fn string, seq EntitySeq)

The entity object must have the structure exposed below

type EntityRaw struct {
	EntityId string `json:"EntityId"`
	Id1      int    `json:"Id1"`
	Id2      int    `json:"Id2"`
	Relation string `json:"Relation"`
}

where

  • EntityId - unique id of the edge,
  • Id1, Id2 - not unique ids of verteces,
  • Relation - value of Entity cost

Operations with DCG


  1. Reading and building graph from JSON file:
	basePath := "./examples"

	graph := new(MultiGraph)
    entities := FromJsonFile(path.Join(basePath, "small.json"))
	graph.Build(entities)
  1. Getting internal edge index
    entity := Entity{Id1: 1, Id2: 2}
    index, getIndexOk := graph.GetEdgeIndex(entity.Id1, entity.Id2)
  1. Getting predecessors and successors of vertex
    entity := Entity{Id1: 1, Id2: 2}
    u := graph.VertexIndex[entity.Id1]
    v := graph.VertexIndex[entity.Id2]
    s := graph.Succ(u)
    p := graph.Pred(v)
  1. Updating edges costs
    updates := FromJsonFile(path.Join(basePath, "small_update.json"))
    err := graph.UpdateRelation(updates)

    if err != nil {
        panic(fmt.Errorf("UpdateRelation() error = %v", err))
    }

More examples of using DCG object see here.

Algorithms


The package includes several algothims:

  1. Depth-First Search with Memoization | source
  2. Recursive Depth-First Search | source
  3. Iterative Depth-First Search | source
  4. Floyd-Warshall | source
  5. Bellman-Ford | source

NOTE

The algorithms 2-5 don't implemented completely. It is part of experimental interfaces of package. Please be careful with using it.


Depth-First Search with Memoization


This is a variant of ID-DFS algorithm. Current implementation have several modification and differences from the original algorithm:

  • depth of searching limited by concrete value instead of positive infinity in the original algorithm,
  • using memoization,
  • reducing multiple edges with the same source and target to optimal edge with least value of weights,
  • weights calculates as - math.log(entity.Relation),
  • using weight boundaries and PriorityQueue.

Algorithm includes the next steps:

  1. Reduce multiple edges with the same source and target to optimal edge with least value of weights calculates as - math.log(entity.Relation).
  2. Build Depth-First Search Tree using dfs+memoization+limiting depth by optimal value:
    DFS(source, target, level) returns nodes, stat:
        if inMemo(source, target, level):
            return getMemo(source, target, level)

        stat = {min, max, mean, mean2, pathsCount}
        nodes = array of TreeNode

        for edge as (u,v) in successors(succ):
            if target == v:
                appendTo(nodes, NewTreeNode(edge, "endpoint"))
                calcStatistics(stat, edge)
                continue

            appendTo(nodes, 
                ExpandTreeNodes(edge,DFS(v, target, level+1)))
            calcStatistics(stat, edge)

        setMemo(source, target, level, nodes, stat)
        return nodes, stat

For every TreeNode weight x MIN(x), MAX(x), E(x) and E(x**2) statistics processed and stored. This statistics used for skip not optimal branches for reducing searching area.

  1. Calculate threshold depended by preinitialized mode which reduce Time Complexity of algorithm:
    stat = getMemo(source, target, level) // E(x), E(x**2), pathsCount
	switch mode {
	case THR_ZERO:
		threshold = 0
	case THR_MEAN:
		threshold = E(x)
	case THR_MEAN_STDDEV:
		threshold = E(x) - sqrt((E(x**2)-E(x) ** 2)/pathsCount)
	}

Also user can set the custom value of threhold.

  1. Trace memo object using original dfs algorithm with constraints:
pq = priority queue

TRACE(src int, target int, level int):
	if src < 0 or target < 0 or level < 0:
        return

	nodes, stat = getMemo(source, target, level)

	if psa[level]+stat.minWeight >= threshold:
		return

	if maxWeight != MIN_WEIGHT and
        psa[level]+stat.minWeight > maxWeight:
		return

	for node in nodes:
		edges[level] = node.base
		weight = psa[level] + node.base.weight
		psa[level+1] = weight

		if node.src < 0:
			if weight >= 0:
				continue

			if weight < maxWeight:
				set(pq, edges, weight)
				maxWeight = pq[0].priority

			continue
		}

		TRACE(node.src, node.target, node.level)
  1. Process multiple edges with the same source and target for every optimal edge from pq. This step is true because every path included not optimal edge is worse or equal than the path included only optimal edges. For more information see ProcessOutsideEdges.

Launch Depth-First Search methods


Some Factory interfaces provided by package for creating Searcher-compatible objects:

func NewDfs(name string, deepLimit int) (Searcher, error)
func DfsDo(st Searcher, op string, g *MultiGraph, srcIds []int, targetIds []int, topK int) (pathsb []byte, err error)
func NewSearcher(major string, minor string) (Searcher, error)

where

  • major - the algorithm's family, e.g. "dfs",
  • minor, name - particular algorithm, e.g. "colored", "stacked", "memo",
  • deepLimit - depth of searching limited by this value,
  • op - one of the "TopK", "TopKOneToOne", "TopKOneToMany".

Benchmarks


Benchmarks above were made for the Depth-First Search with Memoization algorithm with deepLimit=[5, 6]. For details see this.


NOTE

  • All values in tables exposed in milliseconds.
  • Testing environment - os: linux, arch: amd64, cpu: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz.
  • Test data was generated by GenerateRandomEntitiesJson subroutine.
  • q25, q50, q75 - are corresponding percentiles 25%, 50%, 75%.

Table 1 - Depth-First Search with Memoization with deepLimit=5
# fn mean min max q25 q50 q75
0 TopK 8.4 4.3 22 6.8 7.1 7.5
1 TopKOneToMany 33 6.0 64 17 39 48
2 TopKOneToOne 71 6.9 160 35 69 100
3 UpdateRelation < 1 ns < 1 ns < 1 ns < 1 ns < 1 ns < 1 ns

pic 1

Table 2 - Depth-First Search with Memoization with deepLimit=6
# fn mean min max q25 q50 q75
0 TopK 17 8.9 44 13 14 15
1 TopKOneToMany 71 13 180 29 51 110
2 TopKOneToOne 140 80 320 72 130 190
3 UpdateRelation < 1 ns < 1 ns < 1 ns < 1 ns < 1 ns < 1 ns

pic 2

Analysis


With the depth equal 5 and top-100 paths all subroutines working time less than 160ms. Maximum working time was detected for TopKOneToOne subroutine for the 15th length input array srcIds.

With the depth equal 6 and top-100 paths all subroutines working time less than 320ms. Maximum working time was detected for TopKOneToOne subroutine for the 15th length input array srcIds. But for 10th length input array srcIds maximum working time is about 200ms.

With both depth values (5 and 6) the subroutine UpdateRelation working time less than 1 ns for updating 20000 edges in graph structure. It is possible due to the internal index maps inside the DCG and MultiEdge objects.

With depths equal or greater 5 paths with internal loops may exist, e.g. chain with length eq 8:

entity-7023 -> entity-1305-b -> entity-291-b -> entity-1992-b -> entity-6958 -> entity-1305-b -> entity-291-b -> entity-18-b 

has negative internal loop from vertex with id 15 to the same vertex:

entity-1305-b -> entity-291-b -> entity-1992-b -> entity-6958

This path is the best with the maximum relation value and the Depth-First Search with Memoization algorithm allows to find it.

Compare results from this and that its obvious that the Depth-First Search with Memoization algorithm allows to find more paths with greater cost than the Recursive and Iterative classic Depth-First Search algorithms with skipping visited verteces.

Conclusion


  • Using Depth-First Search algorithm with Memoization appropriate for systems with the rigorous time constraints (e.g. > 5000 verteces and > 20000 edges).
  • For best performance find compromises between depth and size of top-k sequence (e.g. for depth=8 use top-10 sequence, for depth=5 use top-100 sequence, for depth=6 use top-50 or less sequence).
  • For dense graph performance of the package subroutines may be worse.
  • Choose the threshold parameter or algorithm for it processing according to density of Relation parameter.
  • Depth-First Search with Memoization algorithm allows to find more paths with greater cost than the Recursive and Iterative classic Depth-First Search algorithms with skipping visited verteces.
  • Algorithms such Bellman-Ford and Floyd-Warshall not appropriate for DCG with large count of vertices and edges due to low performance (more than several seconds for full paths task). Besides Bellman-Ford and Floyd-Warshall algorithms don't correct working with nested negative cycles.

Documentation

Index

Constants

View Source
const (
	THR_NOT_USED = iota
	THR_CUSTOM
	THR_ZERO
)
View Source
const (
	LO_NOT_IN_CHAIN = iota
	LO_PARENT
	LO_CHILD
	LO_CURRENT
)
View Source
const (
	FN_ALL_PATHS = iota
	FN_LO_ONLY
)
View Source
const (
	UNDEFINED = iota
	LIMIT_ORDER
)

Variables

View Source
var MAX_WEIGHT float64 = math.Inf(1)
View Source
var MIN_WEIGHT float64 = math.Inf(-1)

Functions

func DfsDo

func DfsDo(st Searcher, op string, g *MultiGraph, srcIds []int, targetIds []int, topK int) (pathsb []byte, err error)

func EdgesCsvToJson

func EdgesCsvToJson(csvFp string, jsonFp string) error

func FromJsonFile

func FromJsonFile[T EdgeConstraint](fn string) (seq []T, e error)

func GenerateRandomEntitiesJson

func GenerateRandomEntitiesJson(base string, count int, removeOld bool, c RandomEntitySeqInfo)

func GenerateRandomLimitOrdersCsv

func GenerateRandomLimitOrdersCsv(base string, tpl string, count int, removeOld bool, c RandomEdgeSeqInfo)

func IdsHash

func IdsHash(id1, id2 int) (uint64, error)

func IsChainViewsEquals

func IsChainViewsEquals(resPaths [][]ChainView, wantPaths [][]ChainView, mistakesAllowed int) bool

func LoadText

func LoadText(fn string) ([]byte, error)

func PathsToChainView

func PathsToChainView(pathsb []byte) ([][]ChainView, error)

func PathsToJson

func PathsToJson(paths []PriorityQueue) ([]byte, error)

func PriorityQueues2BinaryFile

func PriorityQueues2BinaryFile(fp string, pqs []PriorityQueue) error

func ToCsvFile

func ToCsvFile(fn string, seq []*SingleEdge) error

func ToJsonFile

func ToJsonFile[T EdgeConstraint](fn string, seq []T) error

func Weight

func Weight(a *Entity) float64

func WriteText

func WriteText(fn string, data []byte) error

Types

type BellmanFord

type BellmanFord struct {
	// contains filtered or unexported fields
}

func (*BellmanFord) TopK

func (st *BellmanFord) TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)

func (*BellmanFord) TopKOneToMany

func (st *BellmanFord) TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

func (*BellmanFord) TopKOneToOne

func (st *BellmanFord) TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

type ChainView

type ChainView struct {
	In    int64   `json:"in"`
	Out   int64   `json:"out"`
	Chain string  `json:"chain"`
	Value float64 `json:"value"`
}

func EdgeSeqToChainView

func EdgeSeqToChainView(seq EdgeSeq) *ChainView

type Dfs

type Dfs struct {
	// contains filtered or unexported fields
}

func (*Dfs) SetDeepLimit

func (st *Dfs) SetDeepLimit(v int)

func (*Dfs) SetMultiGraph

func (st *Dfs) SetMultiGraph(g *MultiGraph)

func (*Dfs) SetTopKValue

func (st *Dfs) SetTopKValue(v int)

type DfsColored

type DfsColored struct {
	Dfs
	// contains filtered or unexported fields
}

func (*DfsColored) TopK

func (st *DfsColored) TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)

func (*DfsColored) TopKOneToMany

func (st *DfsColored) TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

func (*DfsColored) TopKOneToOne

func (st *DfsColored) TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

type DfsMemo

type DfsMemo struct {
	Dfs
	// contains filtered or unexported fields
}

func (*DfsMemo) AddLimitOrders

func (st *DfsMemo) AddLimitOrders(edges EdgeSeq) (MEdgeSeq, error)

func (*DfsMemo) Arbitrage

func (st *DfsMemo) Arbitrage(srcIds []int, topK int) (res []PriorityQueue)

func (*DfsMemo) Init

func (st *DfsMemo) Init()

func (*DfsMemo) RemoveLimitOrders

func (st *DfsMemo) RemoveLimitOrders(medges MEdgeSeq)

func (*DfsMemo) SetDeepLimit

func (st *DfsMemo) SetDeepLimit(v int)

func (*DfsMemo) SetFnMode

func (st *DfsMemo) SetFnMode(mode int)

func (*DfsMemo) SetGraph

func (st *DfsMemo) SetGraph(g *MultiGraph)

func (*DfsMemo) SetTreshold

func (st *DfsMemo) SetTreshold(t float64)

func (*DfsMemo) SetTresholdMode

func (st *DfsMemo) SetTresholdMode(mode int)

func (*DfsMemo) TopK

func (st *DfsMemo) TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)

func (*DfsMemo) TopKOneToMany

func (st *DfsMemo) TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

func (*DfsMemo) TopKOneToOne

func (st *DfsMemo) TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

type DfsStacked

type DfsStacked struct {
	// contains filtered or unexported fields
}

func (*DfsStacked) BestCycles

func (st *DfsStacked) BestCycles() (res []EdgeSeq)

func (*DfsStacked) SetDeepLimit

func (st *DfsStacked) SetDeepLimit(v int)

func (*DfsStacked) TopK

func (st *DfsStacked) TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)

func (*DfsStacked) TopKCycles

func (st *DfsStacked) TopKCycles(topK int) (res []PriorityQueue)

func (*DfsStacked) TopKOneToMany

func (st *DfsStacked) TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

func (*DfsStacked) TopKOneToOne

func (st *DfsStacked) TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

type EdgeConstraint

type EdgeConstraint interface {
	*Entity | *SingleEdge
}

type EdgeSeq

type EdgeSeq []*SingleEdge

func (*EdgeSeq) BuildVertexIndex

func (seq *EdgeSeq) BuildVertexIndex() map[int]int

func (EdgeSeq) GetRelation

func (seq EdgeSeq) GetRelation() float64

func (EdgeSeq) MarshalJSON

func (seq EdgeSeq) MarshalJSON() ([]byte, error)

func (EdgeSeq) ReverseEdgeSeq

func (seq EdgeSeq) ReverseEdgeSeq()

func (*EdgeSeq) SetVertexIndex

func (seq *EdgeSeq) SetVertexIndex(vertexIndex map[int]int)

type Entity

type Entity struct {
	EntityId string  `json:"EntityId"`
	Id1      int     `json:"Id1"`
	Id2      int     `json:"Id2"`
	Relation float64 `json:"Relation"`
	Id1i     int     `json:"Id1i"`
	Id2i     int     `json:"Id2i"`
}

func (*Entity) MarshalJSON

func (b *Entity) MarshalJSON() ([]byte, error)

func (*Entity) UnmarshalJSON

func (b *Entity) UnmarshalJSON(data []byte) error

type EntityRaw

type EntityRaw struct {
	EntityId string `json:"EntityId"`
	Id1      int    `json:"Id1"`
	Id2      int    `json:"Id2"`
	Relation string `json:"Relation"`
}

type EntitySeq

type EntitySeq []*Entity

func GenerateRandomEntities

func GenerateRandomEntities(c RandomEntitySeqInfo) EntitySeq

type FloydWarshall

type FloydWarshall struct{}

func (*FloydWarshall) TopK

func (st *FloydWarshall) TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)

func (*FloydWarshall) TopKOneToMany

func (st *FloydWarshall) TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

func (*FloydWarshall) TopKOneToOne

func (st *FloydWarshall) TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)

type Item

type Item struct {
	Value    interface{}
	Priority float64
	Index    int
}

func (Item) MarshalJSON

func (pq Item) MarshalJSON() ([]byte, error)

type LimitOrderService

type LimitOrderService struct {
	// contains filtered or unexported fields
}

TODO

func (*LimitOrderService) Add

func (s *LimitOrderService) Add(id string, tokenIn int, tokenOut int, tokenInAmount float64, tokenOutAmount float64)

func (*LimitOrderService) AddWrapped

func (s *LimitOrderService) AddWrapped(lo *SingleEdge)

func (*LimitOrderService) AddWrappedList

func (s *LimitOrderService) AddWrappedList(los EdgeSeq)

func (*LimitOrderService) Remove

func (s *LimitOrderService) Remove(id string)

type MEdgeSeq

type MEdgeSeq []*MultiEdge

func SingleToMultiEdges

func SingleToMultiEdges(entities EdgeSeq) MEdgeSeq

func (MEdgeSeq) GetWeight

func (seq MEdgeSeq) GetWeight() float64

func (MEdgeSeq) ReverseEdgeSeq

func (seq MEdgeSeq) ReverseEdgeSeq()

type MultiEdge

type MultiEdge struct {
	SingleEdge
	// contains filtered or unexported fields
}

func (*MultiEdge) Add

func (e *MultiEdge) Add(s *SingleEdge) error

func (*MultiEdge) AddMany

func (e *MultiEdge) AddMany(s EdgeSeq) error

func (*MultiEdge) AddManyWithoutUniqueChecking

func (e *MultiEdge) AddManyWithoutUniqueChecking(s EdgeSeq)

func (*MultiEdge) BuildIndex

func (e *MultiEdge) BuildIndex()

func (*MultiEdge) Len

func (e *MultiEdge) Len() int

func (*MultiEdge) MergeWithoutUniqueChecking

func (e *MultiEdge) MergeWithoutUniqueChecking(m *MultiEdge)

func (*MultiEdge) Remove

func (e *MultiEdge) Remove(entityId string) error

func (*MultiEdge) RemoveMany

func (e *MultiEdge) RemoveMany(m *MultiEdge) bool

func (*MultiEdge) RemoveManyByIds

func (e *MultiEdge) RemoveManyByIds(entityIds []string) error

func (*MultiEdge) Update

func (e *MultiEdge) Update()

func (*MultiEdge) UpdateRelation

func (e *MultiEdge) UpdateRelation(entityId string, relation float64) error

type MultiGraph

type MultiGraph struct {
	Edges       MEdgeSeq
	EdgeIndex   map[uint64]int
	VertexIndex map[int]int
	// contains filtered or unexported fields
}

func (*MultiGraph) Add

func (g *MultiGraph) Add(edges EdgeSeq, status int) (MEdgeSeq, error)

func (*MultiGraph) Build

func (g *MultiGraph) Build(ent EdgeSeq)

func (*MultiGraph) GetEdgeIndex

func (g *MultiGraph) GetEdgeIndex(id1, id2 int) (int, bool)

func (*MultiGraph) Pred

func (g *MultiGraph) Pred(v int) MEdgeSeq

func (*MultiGraph) Remove

func (g *MultiGraph) Remove(medges MEdgeSeq, status int)

func (*MultiGraph) Succ

func (g *MultiGraph) Succ(u int) MEdgeSeq

func (*MultiGraph) UpdateRelation

func (g *MultiGraph) UpdateRelation(ent EdgeSeq) error

type PriorityQueue

type PriorityQueue []*Item

func BinaryFile2PriorityQueues

func BinaryFile2PriorityQueues(fp string) ([]PriorityQueue, error)

func NewPriorityQueue

func NewPriorityQueue(size int, capacity int) PriorityQueue

func PriorityQueue2SortedArray

func PriorityQueue2SortedArray(pq PriorityQueue, asc bool) (sa PriorityQueue)

func ProcessOutsideEdges

func ProcessOutsideEdges(pq PriorityQueue, deepLimit int, topK int, reverseEdgeSeq bool, onlyLimitOrders bool) (res PriorityQueue)

func (*PriorityQueue) Append

func (pq *PriorityQueue) Append(value interface{}, priority float64)

func (*PriorityQueue) Init

func (pq *PriorityQueue) Init()

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) PopItem

func (pq *PriorityQueue) PopItem() (item *Item)

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (*PriorityQueue) PushItem

func (pq *PriorityQueue) PushItem(item *Item)

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

func (*PriorityQueue) Update

func (pq *PriorityQueue) Update(item *Item, value interface{}, priority float64)

type RandomEdgeSeqInfo

type RandomEdgeSeqInfo struct {
	Count    int
	PercDiff float64
}

type RandomEntitySeqInfo

type RandomEntitySeqInfo struct {
	VertexCount     int
	EdgesCount      int
	VertexStdFactor int
	RelationMin     float64
	RelationMax     float64
	NoiseMean       float64
	NoiseStdDev     float64
}

type Searcher

type Searcher interface {
	TopK(g *MultiGraph, srcId int, targetId int, topK int) (res PriorityQueue)
	TopKOneToOne(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)
	TopKOneToMany(g *MultiGraph, srcIds []int, targetIds []int, topK int) (res []PriorityQueue)
}

func NewDfs

func NewDfs(name string, deepLimit int) (Searcher, error)

func NewSearcher

func NewSearcher(major string, minor string) (Searcher, error)

type SingleEdge

type SingleEdge struct {
	Data   *Entity
	Weight float64
	Status int
}

func FromCsvFile

func FromCsvFile(fn string) (seq []*SingleEdge, e error)

func GenerateRandomLimitOrders

func GenerateRandomLimitOrders(fp string, count int, percDiff float64) []*SingleEdge

func (*SingleEdge) MarshalJSON

func (b *SingleEdge) MarshalJSON() ([]byte, error)

func (*SingleEdge) UnmarshalJSON

func (b *SingleEdge) UnmarshalJSON(data []byte) error

func (*SingleEdge) Update

func (e *SingleEdge) Update()

func (*SingleEdge) UpdateRelation

func (e *SingleEdge) UpdateRelation(relation float64)

type TreeItem

type TreeItem struct {
	// contains filtered or unexported fields
}

type TreeItemStat

type TreeItemStat struct {
	// contains filtered or unexported fields
}

type TreeNode

type TreeNode struct {
	// contains filtered or unexported fields
}

func NewTreeNode

func NewTreeNode(base *MultiEdge, src int, target int, level int, status int) *TreeNode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL