% Copyright (C) 2013 Peter Schueller % % provide several definitions useful in custom cost functions % % the input graph #const gorig = g1. % the mix graph #const gmix = mix. % the graph to optimize for #const gres = res. % background knowledge graphs have gactivatable(G,_) true % high level dependency (any dep, including meta) initialdep(N1,N2) :- ge(gorig,N1,Ndep), gp(gorig,Ndep,type,dep), ge(gorig,Ndep,N2). % dependencies in res from input graph resorigdep(N1Res,N2Res) :- initialdep(N1,N2), gntarget(gmix,N1Mix,gorig,N1,_), gntarget(gres,N1Res,gmix,N1Mix,_), gntarget(gmix,N2Mix,gorig,N2,_), gntarget(gres,N2Res,gmix,N2Mix,_). % nodes in res from high level dependencies in input graph % (includes some dep nodes! (this is important for meta)) orignode(N1) :- resorigdep(N1,N2). orignode(N2) :- resorigdep(N1,N2). %print(@concat(("orignode ",N))) :- orignode(N). % dependencies in res resdep(N1,N2) :- ge(gres,N1,Ndep), gp(gres,Ndep,type,dep), ge(gres,Ndep,N2). % nodes from dependencies in res % (includes some dep nodes! (this is important for meta)) resnode(N1) :- resdep(N1,N2). resnode(N2) :- resdep(N1,N2). % nodes in result graph but not from input graph additionalnode(N) :- resnode(N), not orignode(N). %print(@concat(("additionalnode ",N))) :- additionalnode(N). % dependencies in result graph but not in input graph additionaldep(N1,N2) :- resdep(N1,N2), not resorigdep(N1,N2). %print(@concat(("additionaldep ",N1," ",N2))) :- additionaldep(N1,N2). % ... between nodes existing in input graph additionaldepEE(N1,N2) :- additionaldep(N1,N2), orignode(N1), orignode(N2). % ... between a node existing in input graph and a "new" node additionaldepEN(N1,N2) :- additionaldep(N1,N2), orignode(N1), not orignode(N2). additionaldepEN(N1,N2) :- additionaldep(N1,N2), not orignode(N1), orignode(N2). % ... between two nodes not existing in input graph additionaldepNN(N1,N2) :- additionaldep(N1,N2), not orignode(N1), not orignode(N2). %print(@concat(("additionaldepEE ",N1," ",N2))) :- additionaldepEE(N1,N2). %print(@concat(("additionaldepEN ",N1," ",N2))) :- additionaldepEN(N1,N2). %print(@concat(("additionaldepNN ",N1," ",N2))) :- additionaldepNN(N1,N2). % graphs that are not used but activated by certain reason % we report for each node that activated a graph if that graph was not used activated_unused(G,Node) :- activated_because(G,Node), activated(G,A), not used(G,A). dist(0..5). % nodes coming from a g1 node have all distances origdist(N1Res,Alldist) :- dist(Alldist), gn(res,N1Res), gntarget(res,N1Res,mix,i(g1,NOrig,1),_). % nodes connected to distance N (any edge direction) have distance N+1 within the distance limit origdist(N2,N+1) :- dist(N+1), % limit origdist(N1,N), gn(res,N2), 1 { ge(res,N1,N2) ; ge(res,N2,N1) }. % all other nodes: dist 5 origdist(N,5) :- gn(res,N), 0 { origdist(N,Dist) : dist(Dist) }. mindist(N,Dist) :- gn(res,N), Dist = #min { X : origdist(N,X) }. %print(@concat(("mindist ",N," => ",Dist))) :- mindist(N,Dist). nodestats(N,orig,Coll,0) :- mindist(N,0), Coll = #count { FromN,Adorn : gntarget(res,N,mix,FromN,Adorn) }. nodestats(N,new,Coll,Dist) :- mindist(N,Dist), dist(Dist), Dist > 0, Coll = #count { FromN,Adorn : gntarget(res,N,mix,FromN,Adorn) }. print(@concat(("nodestats ",N," ",NO," #",Coll," D",Dist))) :- nodestats(N,NO,Coll,Dist).