Exemplo n.º 1
0
void TMultimodalGraphImplB::RandomWalk(TVec< TPair<TInt,TInt> > NodeIds, int WalkLength) {
  int CurrentLocalNodeId = NodeToModeMapping.GetKey(NodeToModeMapping.GetRndKeyId(TInt::Rnd));
  TPair<TInt,TInt> CurrentNodeId = TPair<TInt,TInt>(NodeToModeMapping.GetDat(CurrentLocalNodeId), CurrentLocalNodeId);
  int NodeIdIdx = 0;
  NodeIds.SetVal(NodeIdIdx++, CurrentNodeId);
  while (NodeIds.Len() < WalkLength) {
    TNodeI NI = GetNI(CurrentNodeId);
    TIntV AdjacentModes = TIntV(); NI.GetAdjacentModes(AdjacentModes);
    // Throw an appropriately biased coin here
    int EdgeId = TInt::Rnd.GetUniDevInt(NI.GetOutDeg());
    int i;
    for (i = 0; i < AdjacentModes.Len(); i++) {
      int ModeOutDeg = NI.GetOutDeg(AdjacentModes.GetDat(i));
      if (EdgeId < ModeOutDeg) { break; }
      EdgeId -= ModeOutDeg;
    }
    NodeIds.SetVal(NodeIdIdx++, TPair<TInt,TInt>(AdjacentModes.GetDat(i), NI.GetOutNId(EdgeId, AdjacentModes.GetDat(i))));
  }
}
Exemplo n.º 2
0
TMultimodalGraphImplB::TEdgeI TMultimodalGraphImplB::GetEI(const TPair<TInt,TInt>& SrcNId, const TPair<TInt,TInt>& DstNId) const {
  TNodeI CurNode = TNodeI(NodeToModeMapping.GetI(SrcNId.GetVal2()), &Graphs, &NodeToModeMapping);
  TIntV AdjacentModes = TIntV();
  CurNode.GetAdjacentModes(AdjacentModes);

  TPair<TInt,TInt> ModeIdsKey = GetModeIdsKey(SrcNId.GetVal1(), DstNId.GetVal1());

  int CurAdjacentMode = 0;
  for (int i=0; i<AdjacentModes.Len();i++) {
    if (AdjacentModes.GetDat(i) == DstNId.GetVal1()) {
      CurAdjacentMode=i;
      break;
    }
  }

  return TEdgeI(CurNode, EndNI(), Graphs.GetDat(ModeIdsKey).GetEI(SrcNId.GetVal2(), DstNId.GetVal2()).GetCurEdge(), AdjacentModes, CurAdjacentMode);
}