// for each node check that their neighbors are also nodes bool TUNGraph::IsOk(const bool& ThrowExcept) const { bool RetVal = true; for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) { const TNode& Node = NodeH[N]; if (! Node.NIdV.IsSorted()) { const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } int prevNId = -1; for (int e = 0; e < Node.GetDeg(); e++) { if (! IsNode(Node.GetNbhNId(e))) { const TStr Msg = TStr::Fmt("Edge %d --> %d: node %d does not exist.", Node.GetId(), Node.GetNbhNId(e), Node.GetNbhNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (e > 0 && prevNId == Node.GetNbhNId(e)) { const TStr Msg = TStr::Fmt("Node %d has duplidate edge %d --> %d.", Node.GetId(), Node.GetId(), Node.GetNbhNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } prevNId = Node.GetNbhNId(e); } } return RetVal; }
// Check the graph data structure for internal consistency. bool TUNGraph::IsOk(const bool& ThrowExcept) const { bool RetVal = true; for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) { const TNode& Node = NodeH[N]; if (! Node.NIdV.IsSorted()) { const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } int prevNId = -1; for (int e = 0; e < Node.GetDeg(); e++) { if (! IsNode(Node.GetNbrNId(e))) { const TStr Msg = TStr::Fmt("Edge %d --> %d: node %d does not exist.", Node.GetId(), Node.GetNbrNId(e), Node.GetNbrNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (e > 0 && prevNId == Node.GetNbrNId(e)) { const TStr Msg = TStr::Fmt("Node %d has duplicate edge %d --> %d.", Node.GetId(), Node.GetId(), Node.GetNbrNId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } prevNId = Node.GetNbrNId(e); } } int EdgeCnt = 0; for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) { EdgeCnt++; } if (EdgeCnt != GetEdges()) { const TStr Msg = TStr::Fmt("Number of edges counter is corrupted: GetEdges():%d, EdgeCount:%d.", GetEdges(), EdgeCnt); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } return RetVal; }
///////////////////////////////////////////////// // Simple JSON parser bool TJsonLoader::Next() { if (SIn.Empty() || SIn->Eof()) { TStr FNm; if (! SIn.Empty()) { printf(" %d items in file. %d items total. [%s]\n", LineNo, ItemCnt, ExeTm.GetTmStr()); } if (! FFile.Next(FNm)) { return false; } printf("JSON parse file %d: %s\n", ++FileCnt, FNm.CStr()); LineNo=0; if (TZipIn::IsZipExt(FNm.GetFExt())) { SIn=TZipIn::New(FNm); } else { SIn=TFIn::New(FNm); } ExeTm.Tick(); } try { SIn->GetNextLn(Line); LineNo++; ItemCnt++; Item.Parse(Line.CStr()); } catch (PExcept Except) { TStr FullMsgCStr = TStr::Fmt("%s while pasing '%s' in line %d\nBEGIN LINE\n", Except->GetStr().CStr(), GetCurFNm().CStr(), GetLineNo()); FullMsgCStr += Line; FullMsgCStr += "\nEND LINE\n"; SaveToErrLog(FullMsgCStr.CStr()); ErrNotify(FullMsgCStr.CStr()); return Next(); } return true; }
void ExeStop( const char* MsgCStr, const char* ReasonCStr, const char* CondCStr, const char* FNm, const int& LnN) { char ReasonMsgCStr[1000]; #if SW_TRACE PrintBacktrace(); Crash(); #endif // construct reason message if (ReasonCStr==NULL) { ReasonMsgCStr[0]=0; } else { sprintf(ReasonMsgCStr, " [Reason:'%s']", ReasonCStr); } // construct full message char FullMsgCStr[1000]; if (MsgCStr==NULL) { if (CondCStr==NULL) { sprintf(FullMsgCStr, "Execution stopped%s!", ReasonMsgCStr); } else { sprintf(FullMsgCStr, "Execution stopped: %s%s, file %s, line %d", CondCStr, ReasonMsgCStr, FNm, LnN); } } else { if (CondCStr==NULL) { sprintf(FullMsgCStr, "%s\nExecution stopped!", MsgCStr); } else { sprintf(FullMsgCStr, "Message: %s%s\nExecution stopped: %s, file %s, line %d", MsgCStr, ReasonMsgCStr, CondCStr, FNm, LnN); } } // report full message to log file SaveToErrLog(FullMsgCStr); #if defined(SW_NOABORT) TExcept::Throw(FullMsgCStr); #endif // report to screen & stop execution bool Continue=false; // call handler if (TOnExeStop::IsOnExeStopF()) { Continue=!((*TOnExeStop::GetOnExeStopF())(FullMsgCStr)); } if (!Continue) { ErrNotify(FullMsgCStr); #ifdef GLib_WIN32 abort(); //ExitProcess(1); #else exit(1); #endif } }
void TNotify::DfOnNotify(const TNotifyType& Type, const TStr& MsgStr){ switch (Type){ case ntInfo: InfoNotify(MsgStr); break; case ntWarn: WarnNotify(MsgStr); break; case ntErr: ErrNotify(MsgStr); break; case ntStat: StatNotify(MsgStr); break; default: Fail; } }
bool TNEGraph::IsOk(const bool& ThrowExcept) const { bool RetVal = true; for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) { const TNode& Node = NodeH[N]; if (! Node.OutEIdV.IsSorted()) { const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (! Node.InEIdV.IsSorted()) { const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } // check out-edge ids int prevEId = -1; for (int e = 0; e < Node.GetOutDeg(); e++) { if (! IsEdge(Node.GetOutEId(e))) { const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (e > 0 && prevEId == Node.GetOutEId(e)) { const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } prevEId = Node.GetOutEId(e); } // check in-edge ids prevEId = -1; for (int e = 0; e < Node.GetInDeg(); e++) { if (! IsEdge(Node.GetInEId(e))) { const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (e > 0 && prevEId == Node.GetInEId(e)) { const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e)); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } prevEId = Node.GetInEId(e); } } for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) { const TEdge& Edge = EdgeH[E]; if (! IsNode(Edge.GetSrcNId())) { const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } if (! IsNode(Edge.GetDstNId())) { const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } return RetVal; }
bool TBPGraph::IsOk(const bool& ThrowExcept) const { bool RetVal = false; // edge lists are sorted for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) { if (! LeftH[n].NIdV.IsSorted()) { const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", LeftH[n].GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) { if (! RightH[n].NIdV.IsSorted()) { const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", RightH[n].GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } // nodes only appear on one side for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) { if (RightH.IsKey(LeftH[n].GetId())) { const TStr Msg = TStr::Fmt("'Left' node %d also appears on the 'right'.", LeftH[n].GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) { if (LeftH.IsKey(RightH[n].GetId())) { const TStr Msg = TStr::Fmt("'Right' node %d also appears on the 'left'.", RightH[n].GetId()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } // edges only point from left to right and right to left for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) { for (int e = 0; e < LeftH[n].NIdV.Len(); e++) { if (! RightH.IsKey(LeftH[n].NIdV[e]) || ! RightH.GetDat(LeftH[n].NIdV[e]).NIdV.IsIn(LeftH[n].GetId())) { const TStr Msg = TStr::Fmt("'Left' node %d does not point to the 'right' node %d.", LeftH[n].GetId(), LeftH[n].NIdV[e]()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } } for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) { for (int e = 0; e < RightH[n].NIdV.Len(); e++) { if (! LeftH.IsKey(RightH[n].NIdV[e]) || ! LeftH.GetDat(RightH[n].NIdV[e]).NIdV.IsIn(RightH[n].GetId())) { const TStr Msg = TStr::Fmt("'Left' node %d does not point to the 'right' node %d.", RightH[n].GetId(), RightH[n].NIdV[e]()); if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; } } } return RetVal; }