double GetGroupDegreeCentr(const PUNGraph& Graph, const TIntH& GroupNodes) { int deg; TIntH NN; TIntH GroupNodes1; for (THashKeyDatI<TInt, TInt> NI = GroupNodes.BegI(); NI < GroupNodes.EndI(); NI++) GroupNodes1.AddDat(NI.GetDat(), NI.GetDat()); for (THashKeyDatI<TInt, TInt> NI = GroupNodes1.BegI(); NI < GroupNodes1.EndI(); NI++){ TUNGraph::TNodeI node = Graph->GetNI(NI.GetKey()); deg = node.GetDeg(); for (int j = 0; j < deg; j++){ if (GroupNodes1.IsKey(node.GetNbrNId(j)) == 0 && NN.IsKey(node.GetNbrNId(j)) == 0) NN.AddDat(node.GetNbrNId(j), NI.GetKey()); } } return (double)NN.Len(); }
// Maximum Domination Problem void MaxCPGreedyBetter(const PUNGraph& Graph, const int k, TIntH& GroupNodes) { // buildup cpntainer of group nodes const int n = Graph->GetNodes(); int *NNodes = new int[n]; // container of neighbouring nodes int NNodes_br = 0; TIntH Nodes; // nodes sorted by vd double gc = 0, gc0 = 0; int addId = 0, addIdPrev = 0; for (TUNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++){ Nodes.AddDat(NI.GetId(), NI.GetDeg()); } Nodes.SortByDat(false); int br = 0; while (br < k) { for (THashKeyDatI<TInt, TInt> NI = Nodes.BegI(); NI < Nodes.EndI(); NI++){ if ((NI.GetDat() <= (int)gc0)) break; gc = NI.GetDat() - Intersect(Graph->GetNI(NI.GetKey()), NNodes, NNodes_br); if (gc>gc0){ gc0 = gc; addId = NI.GetKey(); } } if (addId != addIdPrev) { GroupNodes.AddDat(br, addId); br++; gc0 = 0; int nn = addId; bool nnnew = true; for (int j = 0; j<NNodes_br; j++) if (NNodes[j] == nn){ nnnew = false; j = NNodes_br; } if (nnnew){ NNodes[NNodes_br] = nn; NNodes_br++; } for (int i = 0; i<Graph->GetNI(addId).GetDeg(); i++) { int nn = Graph->GetNI(addId).GetNbrNId(i); bool nnnew = true; for (int j = 0; j<NNodes_br; j++) { if (NNodes[j] == nn){ nnnew = false; j = NNodes_br; } } if (nnnew){ NNodes[NNodes_br] = nn; NNodes_br++; } } addIdPrev = addId; Nodes.DelKey(addId); } else { br = k; } printf("%i,", br); } delete NNodes; }