edge_paths_with_PE_controll.xsl 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
  5. exclude-result-prefixes="xs"
  6. version="2.0">
  7. <xsl:import href="PE_wariant_bit_table.xsl"/>
  8. <xsl:output indent="yes"/>
  9. <xsl:strip-space elements="*"/>
  10. <xsl:param name="PE_Price" select="2500"/>
  11. <xsl:param name="Cable_Price" select="3"/>
  12. <xsl:param name="max_combinate_groups_elements" select="8"/> <!-- po ile wezlow mamy grupowac do wyliczania kombinacji kosztow -->
  13. <xsl:param name="logic" select="'grouped'"/> <!-- tutaj robi grupy po $max_combinate_groups_elements -->
  14. <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
  15. <xsl:param name="debug" select="1"/>
  16. <!--<xsl:param name="edge_paths_with_PE.xml"/>-->
  17. <xsl:param name="edge_paths_with_PE_controll_temp" select="'edge_paths_with_PE_controll_temp'"/> <!-- cache do przekazywani danych z petli-->
  18. <xsl:param name="edge_paths_with_PE_controll_temp.alias" select="'edge_paths_with_PE_controll_temp.alias'" />
  19. <xsl:param name="edge_paths_with_PE_controll_paths_temp" select="'edge_paths_with_PE_controll_paths_temp'"/> <!-- do przechowywania calych sciezek do PathCrossed-->
  20. <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
  21. <xsl:template match="edge_joins_filled_paths_xml"><!-- w przypadku wyzwolenia dla pojedynczego pliku -->
  22. <xsl:message>Running script for params:
  23. PE_Price=<xsl:value-of select="$PE_Price"/>
  24. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  25. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  26. logic=<xsl:value-of select="$logic"/> .EOF
  27. </xsl:message>
  28. <edge_paths_with_PE_controll>
  29. <xsl:attribute name="logic" select="$logic"/>
  30. <!-- <xsl:attribute name="id" select="@id"/>
  31. <xsl:attribute name="len" select="@len"/>
  32. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>-->
  33. <xsl:apply-templates mode="PointMatrixGroup">
  34. <xsl:with-param name="edge_joins_filled_path" select="parent::node()"/><!-- jak lecimy natywnie dla pliku edge_joins_filled_paths_xml to dane sa w node()-->
  35. </xsl:apply-templates>
  36. </edge_paths_with_PE_controll>
  37. </xsl:template>
  38. <xsl:template match="edge_joins_filled_paths">
  39. <xsl:message>Running script for params:
  40. PE_Price=<xsl:value-of select="$PE_Price"/>
  41. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  42. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  43. logic=<xsl:value-of select="$logic"/> .EOF
  44. </xsl:message>
  45. <xsl:variable name="edge_joins_filled_paths_len">
  46. <xsl:for-each select="item">
  47. <xsl:sort select="number(asText/@len)" order="descending"/>
  48. <Path>
  49. <xsl:attribute name="id" select="@id"/>
  50. <xsl:attribute name="len" select="asText/@len"/>
  51. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  52. </Path>
  53. </xsl:for-each>
  54. </xsl:variable>
  55. <edge_paths_with_PE_controll>
  56. <xsl:attribute name="logic" select="$logic"/>
  57. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  58. </edge_paths_with_PE_controll>
  59. <!--<xsl:result-document href="edge_paths_with_PE.xml">
  60. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  61. </xsl:result-document>-->
  62. </xsl:template>
  63. <xsl:template match="Path|asText_XMl" mode="PointMatrixGroup">
  64. <xsl:param name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
  65. <Path>
  66. <xsl:attribute name="id" select="@id"/>
  67. <xsl:variable name="ID_Way" select="@id"/>
  68. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  69. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  70. <xsl:attribute name="len" select="@len"/>
  71. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  72. <xsl:variable name="len" select="@len"/>
  73. <xsl:message> Path dla ID_Way=<xsl:value-of select="$ID_Way"/>; len=<xsl:value-of select="@len"/>; Count=<xsl:value-of select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  74. Points_cnt=<xsl:value-of select="@Points_cnt"/>
  75. </xsl:message>
  76. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  77. <EdgeWayJoinsPair>
  78. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  79. </EdgeWayJoinsPair>
  80. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  81. <!-- sciagamy dane drog, z ktorymi sie przecinamy -->
  82. <xsl:variable name="PathsCrossed">
  83. <PathsCrossed>
  84. <xsl:for-each-group select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString/Ways" group-by="@ID_WAY">
  85. <Ways>
  86. <xsl:variable name="ID_WAY_joining" select="@ID_WAY"/>
  87. <xsl:attribute name="ID_WAY" select="$ID_WAY_joining"/>
  88. <xsl:variable name="ways_id_joining" select="@ways_id"/>
  89. <xsl:attribute name="ways_id_joining" select="$ways_id_joining"/>
  90. <xsl:variable name="ID_Join_joining" select="parent::node()/@ID_Join"/>
  91. <xsl:attribute name="ID_Join_joining" select="$ID_Join_joining"/>
  92. <xsl:choose>
  93. <xsl:when test="doc-available(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))">
  94. <xsl:variable name="Neigh_controll">
  95. <xsl:copy-of select="doc(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))"/>
  96. </xsl:variable>
  97. <!-- wykryc gdzie sie lacza i jakie sa odleglosci prawdziwe -->
  98. <!-- jak nasza droga sie laczy do przeciwnej? ktory nasz Way w nim siedzi -->
  99. <!-- zignorowac wezel zwiazany z podlaczonym tam joinem -->
  100. <!-- <IgnoreLocaldistance>
  101. <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
  102. </IgnoreLocaldistance>
  103. <IgnoreLocaldistance>
  104. <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
  105. </IgnoreLocaldistance>-->
  106. <!--<xsl:for-each select="$Neigh_controll/edge_paths_with_PE_controll/Path/PointMatrixGroupPE/PointMatrixGroup/odpalam_liczenie/(bp:Path_Point|bp:Path_Point_Cable)">
  107. <xsl:copy-of select="."/>
  108. </xsl:for-each>-->
  109. <xsl:apply-templates mode="PathsCrossed" select="$Neigh_controll"/>
  110. </xsl:when>
  111. <xsl:otherwise>
  112. <xsl:message> WARNING path should be analyzed and aviable in:<xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></xsl:message>
  113. <Warning> WARNING path should be analyzed and aviable in: <xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></Warning>
  114. </xsl:otherwise>
  115. </xsl:choose>
  116. </Ways>
  117. </xsl:for-each-group>
  118. </PathsCrossed>
  119. </xsl:variable>
  120. <xsl:copy-of select="$PathsCrossed"/>
  121. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  122. <xsl:variable name="EconomicDistanceCut">
  123. <EconomicDistanceCut>
  124. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[not(@error)]">
  125. <distance>
  126. <xsl:attribute name="pos" select="position()"/>
  127. <xsl:attribute name="not_id" select="@not_id"/>
  128. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  129. <xsl:attribute name="len" select="@len"/>
  130. <xsl:attribute name="id_path" select="@id_path"/>
  131. <xsl:variable name="Points" select="count(Points)"/>
  132. <xsl:attribute name="Points" select="$Points"/>
  133. <xsl:variable name="Ways" select="count(Ways)"/>
  134. <xsl:attribute name="Ways_count" select="$Ways"/>
  135. <xsl:choose>
  136. <xsl:when test="$Ways or $Points">
  137. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  138. <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  139. <xsl:if test="Ways">
  140. <!-- sprawdzamy jak sie dowiazuje i ile ma do najblizszego wezla -->
  141. <xsl:for-each-group select="Ways" group-by="@ID_WAY">
  142. <PathsCrossed>
  143. <xsl:attribute name="ID_WAY" select="@ID_WAY"/><xsl:attribute name="debug" select="'created at #163 by parsing Ways'"/>
  144. <xsl:variable name="Joining_ID_Join_from" select="parent::node()/@ID_Join"/>
  145. <xsl:choose>
  146. <xsl:when test="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos">
  147. <xsl:variable name="NeighJoin_pos" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos"/>
  148. <xsl:variable name="NeighJoin_pos_distance" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@pos= $NeighJoin_pos]/@distance)"/>
  149. <xsl:attribute name="NeighJoin_pos" select="$NeighJoin_pos"/>
  150. <xsl:attribute name="NeighJoin_pos_distance" select="$NeighJoin_pos_distance"/>
  151. <xsl:attribute name="Deb_Cur_ID_WAY" select="@ID_WAY"/>
  152. <xsl:attribute name="Joining_ID_Join_from" select="$Joining_ID_Join_from"/>
  153. <!-- chk w gore -->
  154. <xsl:variable name="NeighJoin_way_up_pos" select="max($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos) &lt; number($NeighJoin_pos) ] /@pos)"/>
  155. <xsl:choose>
  156. <xsl:when test="$NeighJoin_way_up_pos">
  157. <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
  158. <xsl:variable name="NeighJoin_way_up_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@ID_Join" />
  159. <xsl:variable name="NeighJoin_way_up_len" select="number($NeighJoin_pos_distance) - number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@distance) "/>
  160. <xsl:attribute name="NeighJoin_way_up_len" select="$NeighJoin_way_up_len"/>
  161. <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
  162. <xsl:attribute name="NeighJoin_way_up_ID_Join" select="$NeighJoin_way_up_ID_Join"/>
  163. </xsl:when>
  164. <xsl:otherwise>
  165. <xsl:attribute name="NeighJoin_way_up_len" select="-1"/>
  166. </xsl:otherwise>
  167. </xsl:choose>
  168. <xsl:variable name="NeighJoin_way_dn_pos" select="min($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos) &gt; number($NeighJoin_pos) ] /@pos)"/>
  169. <xsl:choose>
  170. <xsl:when test="$NeighJoin_way_dn_pos">
  171. <xsl:variable name="NeighJoin_way_dn_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@ID_Join"/>
  172. <xsl:variable name="NeighJoin_way_dn_len" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@distance) - number($NeighJoin_pos_distance) "/>
  173. <xsl:attribute name="NeighJoin_way_dn_pos" select="$NeighJoin_way_dn_pos"/>
  174. <xsl:attribute name="NeighJoin_way_dn_ID_Join" select="$NeighJoin_way_dn_ID_Join"/>
  175. <xsl:attribute name="NeighJoin_way_dn_len" select="$NeighJoin_way_dn_len"/>
  176. </xsl:when>
  177. <xsl:otherwise>
  178. <xsl:attribute name="NeighJoin_way_dn_len" select="-1"/>
  179. </xsl:otherwise>
  180. </xsl:choose>
  181. <!-- chk w dol -->
  182. <xsl:if test=" number($debug) &gt; 3">
  183. <debug186>
  184. <xsl:copy-of select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]"/>
  185. </debug186>
  186. </xsl:if>
  187. </xsl:when>
  188. <xsl:otherwise>
  189. <xsl:comment>No connection to other roads found</xsl:comment>
  190. </xsl:otherwise>
  191. </xsl:choose>
  192. </PathsCrossed>
  193. </xsl:for-each-group>
  194. </xsl:if>
  195. </xsl:when>
  196. <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
  197. <xsl:attribute name="point_count" select="0"/>
  198. </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  199. </xsl:choose>
  200. </distance>
  201. </xsl:for-each>
  202. </EconomicDistanceCut>
  203. </xsl:variable>
  204. <xsl:if test="$debug">
  205. <debug_174>
  206. <xsl:copy-of select="$EconomicDistanceCut"/>
  207. </debug_174>
  208. </xsl:if>
  209. <xsl:variable name="EconomicDistanceCut2">
  210. <EconomicDistanceCut2>
  211. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  212. <distance2>
  213. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  214. <xsl:copy-of select="@ID_Join"/>
  215. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  216. <xsl:choose>
  217. <xsl:when test="number(@point_count)&gt;0">
  218. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  219. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  220. ]/@pos)"/>
  221. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  222. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  223. number(@pos )&lt; number(current()/@pos )
  224. and number(@pos) &gt;= number($max_pos_z_pkt)
  225. ]/@len)"/>
  226. <xsl:attribute name="disttopkt" select="$disttopkt" />
  227. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * number(@point_count)"/>
  228. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  229. <xsl:attribute name="point_count" select="@point_count"/>
  230. <xsl:attribute name="Ways_count" select="@Ways_count"/>
  231. <xsl:choose> <!-- to powinno przeciac grupe ale moze nie? -->
  232. <xsl:when test="$cost_dist &gt; $PE_Price">
  233. <xsl:attribute name="cut_by_pe" select="1"/>
  234. </xsl:when>
  235. <xsl:otherwise><xsl:attribute name="cut_by_pe" select="0"/></xsl:otherwise>
  236. </xsl:choose>
  237. <xsl:attribute name="not_id" select="@not_id"/> <!-- to jest z ID way - way ma 2 pointsy! -->
  238. </xsl:when>
  239. <xsl:otherwise>
  240. <xsl:choose>
  241. <xsl:when test="number(@Ways_count)&gt;0">
  242. <xsl:attribute name="point_count" select="@Ways_count"/>
  243. </xsl:when>
  244. <xsl:otherwise><xsl:attribute name="point_count" select="0"/></xsl:otherwise>
  245. </xsl:choose>
  246. </xsl:otherwise>
  247. </xsl:choose>
  248. <xsl:attribute name="id_path" select="@id_path"/>
  249. <xsl:copy-of select="@point_count"/>
  250. <xsl:copy-of select="@pos"/><!-- position() -->
  251. <xsl:copy-of select="@len"/>
  252. <xsl:copy-of select="@ForceCutByPrice"/>
  253. <xsl:copy-of select="PathsCrossed"/>
  254. <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
  255. </distance2>
  256. </xsl:for-each>
  257. </EconomicDistanceCut2>
  258. </xsl:variable>
  259. <debug_Cut2_183>
  260. <xsl:copy-of select="$EconomicDistanceCut2"/>
  261. </debug_Cut2_183>
  262. <xsl:variable name="EconomicDistanceCut2">
  263. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  264. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  265. <distance2>
  266. <xsl:copy-of select="@*"/>
  267. <xsl:choose>
  268. <xsl:when test=" position() mod $max_combinate_groups_elements = 0"> <!--- minus puste sum($EconomicDistanceCut/EconomicDistanceCut/distance[ number(@pos) &lt; number(current()/@pos) ]/number(@NotPoints)) ) --><!-- nabija grupe do przeliczenia-->
  269. <xsl:attribute name="PosCut3Flag" select="1"/>
  270. </xsl:when>
  271. <xsl:otherwise>
  272. <xsl:attribute name="PosCut3Flag" select="0"/>
  273. </xsl:otherwise>
  274. </xsl:choose>
  275. <xsl:copy-of select="PathsCrossed"/>
  276. </distance2>
  277. </xsl:for-each>
  278. </EconomicDistanceCut2>
  279. </xsl:variable>
  280. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  281. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  282. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  283. <distance2>
  284. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  285. <xsl:copy-of select="@*"/>
  286. <xsl:copy-of select="PathsCrossed"/>
  287. </distance2>
  288. </xsl:for-each>
  289. </EconomicDistanceCut2>
  290. </xsl:variable>
  291. <!-- debug -->
  292. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  293. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  294. <distance2>
  295. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  296. <xsl:copy-of select="@PosCut3GrId"/>
  297. <xsl:copy-of select="@CurSumNotPoints"/>
  298. <xsl:copy-of select="@NotPoints"/>
  299. <!-\-<xsl:copy-of select="@pos"/>-\->
  300. </distance2>
  301. </xsl:for-each>
  302. </EconomicDistanceCut2>-->
  303. <!-- debug -->
  304. <!--<debug>
  305. <xsl:copy-of select="$EconomicDistanceCut2"/>
  306. </debug>-->
  307. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  308. <!--<xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price]) )"/>--><!-- max licbza PE-->
  309. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  310. <xsl:variable name="PointMatrixGroup">
  311. <PointMatrixGroup>
  312. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  313. <PointMatrixGroupPos>
  314. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  315. <xsl:variable name="countGr" select="count(current-group())"/>
  316. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  317. <xsl:message>Nowa grupa Ways:<xsl:value-of select="@PosCut3GrId"/>; distanceGr=<xsl:value-of select="@PosCut3GrId"/>;elements_cnt_Pos=<xsl:value-of select="$elements_cnt_Pos"/>; @bit_max_Pos=<xsl:value-of select="$bit_max_Pos"/>; @id_path=<xsl:value-of select="@id_path"/>; countGr=<xsl:value-of select="$countGr"/>; point_count_Pos=<xsl:value-of select="sum(current-group()/@point_count)"/>; len_sum=<xsl:value-of select="sum(current-group()/@len)"/> ; distanceBeg/distanceEnd= <xsl:value-of select="min(current-group()/number(@distance))"/>/<xsl:value-of select="max(current-group()/number(@distance))"/>
  318. </xsl:message>
  319. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  320. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  321. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  322. <xsl:attribute name="id_path" select="@id_path"/>
  323. <xsl:attribute name="point_count_Pos" select="sum(current-group()/@point_count)"/><!-- po przesortowaniu z usunieciem wezlow bez skojarzen przylaczy - jest to nieprawdziwe - rzebaa dodac te dane z poprzednich sciezek itp -->
  324. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  325. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  326. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  327. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  328. <xsl:attribute name="countGr" select="$countGr"/>
  329. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  330. <xsl:for-each select="current-group()">
  331. <distance2>
  332. <xsl:attribute name="PosMatrGroup" select="position()"/>
  333. <xsl:copy-of select="@*"></xsl:copy-of>
  334. <xsl:copy-of select="PathsCrossed"/>
  335. </distance2>
  336. </xsl:for-each>
  337. </PointMatrixGroupPos>
  338. </xsl:for-each-group>
  339. </PointMatrixGroup>
  340. </xsl:variable>
  341. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  342. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  343. -->
  344. <!-- debug -->
  345. <xsl:if test="number($debug) &gt; 3">
  346. <debug_356>
  347. <xsl:copy-of select="$PointMatrixGroup"/>
  348. </debug_356>
  349. </xsl:if>
  350. <PointMatrixGroupPE>
  351. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  352. <xsl:for-each select="PointMatrixGroupPos">
  353. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  354. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  355. <xsl:variable name="distanceGr" select="@distanceGr"/>
  356. <PointMatrixGroup>
  357. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  358. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  359. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  360. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  361. <xsl:attribute name="len_sum" select="@len_sum"/>
  362. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  363. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  364. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  365. <xsl:message>#239: calc @distanceGr=<xsl:value-of select="$distanceGr"/>; @point_count_Pos=<xsl:value-of select="@point_count_Pos"/>;@LineStringCount ; @len_sum=<xsl:value-of select="@len_sum"/>; @distanceBeg=<xsl:value-of select="@distanceBeg"/>; @distanceEnd=<xsl:value-of select="@distanceEnd"/>;
  366. </xsl:message>
  367. <!-- ida kandydaci -->
  368. <xsl:variable name="candidates">
  369. <xsl:for-each select="distance2[ @point_count &gt;0 ]"> <!--@point_count &gt;0--> <!-- ( $logic='sorted' and ( ( position() &lt;= $bit_max_Pos and @point_count &gt;0 ) or ( position()=1 and $point_count_Pos &gt; 0 ) ) or position()= last() ) or ( @point_count &gt;0 and $logic='grouped' ) --> <!--( position() &lt;= $bit_max_Pos and @point_count &gt;0 ) or ( position()=1 and $point_count_Pos &gt; 0 ) or position()= last() --> <!-- jak jest maly wspolczynnik to chociaz jeden punkt jak sa punkty jakies w tej grupie -->
  370. <!--<xsl:sort select="@cost_dist" order="descending"/>-->
  371. <bp:Path_Point>
  372. <xsl:copy-of select="@ID_Join"/>
  373. <xsl:attribute name="DebugPosPoint" select="position()"/>
  374. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  375. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  376. <xsl:attribute name="pos" select="@pos"/>
  377. <xsl:attribute name="len" select="@len"/>
  378. <xsl:attribute name="distance" select="@distance"/>
  379. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  380. <xsl:attribute name="id_path" select="@id_path"/>
  381. <xsl:attribute name="point_count" select="@point_count"/>
  382. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  383. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  384. <xsl:copy-of select="PathsCrossed"/>
  385. </bp:Path_Point>
  386. </xsl:for-each>
  387. </xsl:variable>
  388. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  389. $last = A
  390. - najprosciej przez pliki oszukujac silnik xsl
  391. - tozsamowsci $ID_Way $distanceGr
  392. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  393. -->
  394. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  395. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  396. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  397. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  398. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  399. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  400. </xsl:if>
  401. </xsl:variable>
  402. <!--<poprzednie_odpalam_liczenie_or_nie>
  403. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  404. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  405. </poprzednie_odpalam_liczenie_or_nie>-->
  406. <xsl:variable name="odpalam_liczenie_or_nie">
  407. <xsl:choose>
  408. <xsl:when test="1=1"> <!-- bylo count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1-->
  409. <xsl:variable name="max_bit">
  410. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  411. </xsl:variable>
  412. <odpalam_liczenie>
  413. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  414. <!--<disabled>temporary blad after #410 OK - przeliczony wariant bit=000000010000 ( nr 4095;)
  415. [xslt] #239: calc @distanceGr=23; @point_count_Pos=19;@LineStringCount ; @len_sum=177; @distanceBeg=5055; @distanceEnd=5475;
  416. [xslt]
  417. [xslt] /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/edge_paths_with_PE_controll.xsl:571: Fatal Error! Cannot convert string to double: ""
  418. [xslt] Failed to process /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/edge_joins_filled_paths.xml</disabled>-->
  419. <xsl:variable name="IfPathsCrossed" >
  420. <xsl:choose>
  421. <xsl:when test="$candidates/bp:Path_Point/PathsCrossed[@NeighJoin_way_up_ID_Join or @NeighJoin_way_dn_ID_Join]">
  422. <xsl:message>#534 there are PathsCrossed - allow to decrease -1</xsl:message>
  423. <xsl:value-of select="0"/>
  424. </xsl:when>
  425. <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
  426. </xsl:choose>
  427. </xsl:variable>
  428. <xsl:call-template name="calculate_optimum">
  429. <xsl:with-param name="candidates" select="$candidates"/>
  430. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  431. <xsl:with-param name="max_bit" select="$max_bit"/>
  432. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  433. <xsl:with-param name="variant" select="$IfPathsCrossed"/>
  434. </xsl:call-template>
  435. </odpalam_liczenie>
  436. </xsl:when>
  437. <xsl:otherwise>
  438. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  439. <xsl:for-each select="$candidates/bp:Path_Point">
  440. <bp:Path_Point>
  441. <xsl:copy-of select="@*"/>
  442. <xsl:attribute name="bin_pos" select="1"/>
  443. </bp:Path_Point>
  444. </xsl:for-each>
  445. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  446. </xsl:otherwise>
  447. </xsl:choose>
  448. </xsl:variable>
  449. <xsl:if test="number($debug) &gt; 0">
  450. <debug423>
  451. <xsl:attribute name="liczenie_dla"/>
  452. <candidates>
  453. <xsl:copy-of select="$candidates"/>
  454. </candidates>
  455. <poprzednie_odpalam_liczenie_or_nie>
  456. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  457. </poprzednie_odpalam_liczenie_or_nie>
  458. </debug423>
  459. </xsl:if>
  460. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  461. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  462. <poprzednie_odpalam_liczenie_or_nie>
  463. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  464. <xsl:if test="position() = last()">
  465. <xsl:copy-of select="."/>
  466. </xsl:if>
  467. </xsl:for-each>
  468. <nizej_zwykly></nizej_zwykly>
  469. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  470. <xsl:if test="position() = last()">
  471. <xsl:copy-of select="."/>
  472. </xsl:if>
  473. </xsl:for-each>
  474. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  475. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  476. </poprzednie_odpalam_liczenie_or_nie>
  477. </xsl:result-document>
  478. </PointMatrixGroup>
  479. </xsl:for-each>
  480. </xsl:for-each>
  481. </PointMatrixGroupPE>
  482. <!--<PointMatrix>
  483. <xsl:attribute name="bit_max" select="$bit_max"/>
  484. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  485. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  486. <!-\-<xsl:call-template name="PE_wariant">
  487. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  488. <xsl:with-param name="bit_max" select="$bit_max"/>
  489. </xsl:call-template>-\->
  490. </PointMatrix>-->
  491. </Path>
  492. </xsl:template>
  493. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  494. <xsl:apply-templates mode="PathsCrossed"/>
  495. </xsl:template>
  496. <xsl:template match="bp:Path_Point_Cable|bp:Path_Point" mode="PathsCrossed">
  497. <xsl:copy-of select="."/>
  498. </xsl:template>
  499. <xsl:template match="*|text()" mode="PathsCrossed"/>
  500. <xsl:template name="calculate_optimum">
  501. <xsl:param name="candidates" required="yes"/>
  502. <xsl:param name="elements_cnt" required="yes"/>
  503. <xsl:param name="variant" select="1"/>
  504. <xsl:param name="max_bit" required="yes"/>
  505. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  506. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  507. <xsl:param name="PathsCrossed" select="0"/><!-- do jednorazowego wyzwolenia przez fukcje, aby tylko raz odjelo wariant zerowy -->
  508. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  509. <xsl:variable name="cand_to_calc">
  510. <xsl:for-each select="$candidates/bp:Path_Point">
  511. <!--<xsl:sort select="number(@distance)"/>-->
  512. <bp:Path_Point>
  513. <!--<xsl:attribute name="bit" select="$bit"/>-->
  514. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  515. <xsl:copy-of select="@*"/>
  516. <!--<xsl:copy-of select="bp:Path_Point"/>-->
  517. <xsl:copy-of select="PathsCrossed"/>
  518. </bp:Path_Point>
  519. </xsl:for-each>
  520. </xsl:variable>
  521. <!-- debug -->
  522. <xsl:if test=" number($debug) &gt; 2">
  523. <variant><xsl:attribute name="variant" select="$variant"/>
  524. <xsl:attribute name="cur_bit" select="$bit"/>
  525. <xsl:attribute name="best_cost" select="$best_cost"/>
  526. <xsl:attribute name="best_variant" select="$best_variant"/>
  527. <xsl:copy-of select="$cand_to_calc"/>
  528. </variant>
  529. </xsl:if>
  530. <xsl:variable name="calc_cost_way">
  531. <xsl:call-template name="calc_cost_way">
  532. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  533. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  534. </xsl:call-template>
  535. </xsl:variable>
  536. <xsl:variable name="cost_sum">
  537. <costs>
  538. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  539. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  540. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  541. <xsl:copy-of select="$calc_cost_way"/>
  542. </costs>
  543. </xsl:variable>
  544. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  545. <xsl:variable name="best">
  546. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  547. <xsl:choose>
  548. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  549. <best>
  550. <xsl:attribute name="best_cost" select="$cur_Price"/>
  551. <xsl:attribute name="best_variant" select="$bit"/>
  552. </best>
  553. </xsl:when>
  554. <xsl:otherwise>
  555. <best>
  556. <xsl:attribute name="best_cost" select="$best_cost"/>
  557. <xsl:attribute name="best_variant" select="$best_variant"/>
  558. </best>
  559. </xsl:otherwise>
  560. </xsl:choose>
  561. </xsl:variable>
  562. <xsl:if test=" number($debug) &gt; 3 "><xsl:copy-of select="$best"/></xsl:if>
  563. <xsl:choose>
  564. <xsl:when test="$bit = $max_bit">
  565. <koniec_wariantow>
  566. <xsl:message>#410 OK - przeliczony wariant bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  567. <xsl:attribute name="best_variant" select="$best_variant"/>
  568. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  569. <xsl:variable name="cand_to_calc_best">
  570. <xsl:for-each select="$candidates/bp:Path_Point">
  571. <!--<xsl:sort select="@distance"/>-->
  572. <bp:Path_Point>
  573. <!--<xsl:attribute name="bit" select="$bit"/>-->
  574. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  575. <xsl:copy-of select="@*"/>
  576. <xsl:copy-of select="bp:Path_Point"/>
  577. </bp:Path_Point>
  578. </xsl:for-each>
  579. </xsl:variable>
  580. <xsl:variable name="show_cables">
  581. <xsl:call-template name="calc_cost_way">
  582. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  583. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  584. <xsl:with-param name="show_cables" select="1"/>
  585. </xsl:call-template>
  586. </xsl:variable>
  587. <xsl:for-each select="$candidates/bp:Path_Point">
  588. <!--<xsl:sort select="number(@distance)"/>-->
  589. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  590. <bp:Path_Point>
  591. <xsl:attribute name="bit" select="$best_variant"/>
  592. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  593. <xsl:copy-of select="@*"/>
  594. <xsl:attribute name="Price" select="$best_cost"/>
  595. <xsl:copy-of select="bp:Path_Point"/>
  596. </bp:Path_Point>
  597. </xsl:if>
  598. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  599. <bp:Path_Point_Cable>
  600. <xsl:attribute name="bit" select="$best_variant"/>
  601. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  602. <xsl:copy-of select="@*"/>
  603. <xsl:attribute name="Price" select="$best_cost"/>
  604. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  605. <!-- todo do jakiego Join zostal przybity -->
  606. <xsl:copy-of select="bp:Path_Point"/>
  607. <!--<xsl:if test="$debug">
  608. <debug_show_cables>
  609. <xsl:copy-of select="$show_cables"></xsl:copy-of>
  610. </debug_show_cables>
  611. </xsl:if>-->
  612. </bp:Path_Point_Cable>
  613. </xsl:if>
  614. </xsl:for-each>
  615. </koniec_wariantow>
  616. </xsl:when>
  617. <xsl:otherwise>
  618. <xsl:call-template name="calculate_optimum">
  619. <xsl:with-param name="candidates" select="$candidates"/>
  620. <xsl:with-param name="max_bit" select="$max_bit"/>
  621. <xsl:with-param name="variant" select="$variant + 1"/>
  622. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  623. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  624. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  625. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  626. </xsl:call-template>
  627. </xsl:otherwise>
  628. </xsl:choose>
  629. </xsl:template>
  630. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  631. <xsl:param name="cand_to_calc" required="yes"/>
  632. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  633. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  634. <xsl:variable name="candidates_merged_with_poprzednie">
  635. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  636. <bp:Path_Point>
  637. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  638. <xsl:copy-of select="@*"/>
  639. <xsl:attribute name="distance_Neigh" select="0"/>
  640. </bp:Path_Point>
  641. </xsl:for-each>
  642. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  643. <bp:Path_Point>
  644. <xsl:copy-of select="@*"/>
  645. <xsl:attribute name="distance_Neigh" select="0"/>
  646. </bp:Path_Point>
  647. </xsl:for-each>
  648. <!-- dorzucenie Crossed -->
  649. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  650. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  651. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  652. <xsl:message>#681: PathsCrossed up $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>; @NeighJoin_way_up_len=<xsl:value-of select="@NeighJoin_way_up_len"/></xsl:message>
  653. <bp:Path_Point>
  654. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  655. <xsl:attribute name="bin_pos" select="1"/>
  656. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  657. <xsl:choose>
  658. <xsl:when test="$PathCrossLast">
  659. <xsl:message>adding distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>; </xsl:message>
  660. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>
  661. </xsl:when>
  662. <xsl:otherwise>
  663. <xsl:message>reducing distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>; </xsl:message>
  664. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>
  665. </xsl:otherwise>
  666. </xsl:choose>
  667. <xsl:attribute name="pos" select="-1"/>
  668. </bp:Path_Point>
  669. </xsl:for-each>
  670. </xsl:for-each>
  671. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  672. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  673. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  674. <xsl:message>#681: PathsCrossed dwn $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_dn_len"/>; @distance=<xsl:value-of select="@NeighJoin_way_dn_len"/>; </xsl:message>
  675. <bp:Path_Point>
  676. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  677. <xsl:attribute name="bin_pos" select="1"/>
  678. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  679. <xsl:choose>
  680. <xsl:when test="$PathCrossLast">
  681. <xsl:message>adding distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>; </xsl:message>
  682. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>
  683. </xsl:when>
  684. <xsl:otherwise>
  685. <xsl:message>reducing distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>; </xsl:message>
  686. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>
  687. </xsl:otherwise>
  688. </xsl:choose>
  689. <xsl:attribute name="pos" select="-1"/>
  690. </bp:Path_Point>
  691. </xsl:for-each>
  692. </xsl:for-each>
  693. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  694. </xsl:variable>
  695. <xsl:if test="number($debug) &gt;1">
  696. <candidates_merged_with_poprzednie>
  697. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  698. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  699. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  700. </candidates_merged_with_poprzednie>
  701. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  702. </xsl:if>
  703. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  704. <xsl:sort select="number(@distance)"/>
  705. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  706. <xsl:choose>
  707. <xsl:when test="@poprzednia_grupa">
  708. <cost>
  709. <xsl:attribute name="Cable_Price" select="0"/>
  710. <xsl:attribute name="PE_Price" select="0"/>
  711. <xsl:attribute name="Price" select="0"/>
  712. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  713. </cost>
  714. </xsl:when>
  715. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  716. <xsl:variable name="way_up_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &lt; current()/number(@distance )]/number(@id_path))"/>
  717. <xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>
  718. <xsl:variable name="way_up_len" >
  719. <xsl:choose>
  720. <xsl:when test="$way_up_id">
  721. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@id_path=$way_up_id]/@distance)"/></xsl:when>
  722. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  723. </xsl:choose>
  724. </xsl:variable>
  725. <xsl:variable name="way_dn_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &gt; current()/number(@distance) ]/number(@id_path)) " />
  726. <xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_dn_id ]/@ID_Join"/>
  727. <xsl:variable name="way_dn_len">
  728. <xsl:choose>
  729. <xsl:when test="$way_dn_id">
  730. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@id_path=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  731. </xsl:when>
  732. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  733. </xsl:choose>
  734. </xsl:variable>
  735. <xsl:choose><!-- czy w gore czy w dol -->
  736. <xsl:when test=" number($way_up_len) &gt;= number($way_dn_len) and number($way_dn_len) &gt; 0 or $way_up_len=-1"> <!--and not($way_dn_len='NaN') -->
  737. <cost>
  738. <xsl:variable name="Cable_Price_sum">
  739. <xsl:choose>
  740. <xsl:when test="number(@point_count) &gt; 0 ">
  741. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  742. </xsl:when>
  743. <xsl:otherwise>
  744. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  745. </xsl:otherwise>
  746. </xsl:choose>
  747. </xsl:variable>
  748. <!-- todo @point_count -->
  749. <xsl:if test="$show_cables">
  750. <xsl:attribute name="choosed" select="'down'"/>
  751. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  752. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  753. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  754. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  755. <xsl:attribute name="PE_Price" select="0"/>
  756. <xsl:attribute name="Target_ID_Join" select="$ID_Join_dn"/>
  757. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  758. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  759. </xsl:if>
  760. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  761. </cost>
  762. </xsl:when>
  763. <xsl:otherwise>
  764. <cost>
  765. <xsl:variable name="Cable_Price_sum">
  766. <xsl:choose>
  767. <xsl:when test="number(@point_count) &gt; 0 ">
  768. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  769. </xsl:when>
  770. <xsl:otherwise>
  771. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  772. </xsl:otherwise>
  773. </xsl:choose>
  774. </xsl:variable>
  775. <xsl:if test="$show_cables or $debug">
  776. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  777. <xsl:attribute name="PE_Price" select="0"/>
  778. <xsl:attribute name="choosed" select="'up'"/>
  779. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  780. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  781. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  782. <xsl:attribute name="Target_ID_Join" select="$ID_Join_up"/>
  783. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  784. </xsl:if>
  785. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  786. </cost>
  787. </xsl:otherwise>
  788. </xsl:choose>
  789. </xsl:when>
  790. <xsl:otherwise>
  791. <cost>
  792. <xsl:attribute name="Cable_Price" select="0"/>
  793. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  794. <xsl:attribute name="Price" select="$PE_Price"/>
  795. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  796. </cost>
  797. </xsl:otherwise>
  798. </xsl:choose>
  799. </xsl:for-each>
  800. </xsl:template>
  801. </xsl:stylesheet>