edge_paths_with_PE_controll.xsl 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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:call-template name="calculate_optimum">
  420. <xsl:with-param name="candidates" select="$candidates"/>
  421. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  422. <xsl:with-param name="max_bit" select="$max_bit"/>
  423. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  424. </xsl:call-template>
  425. </odpalam_liczenie>
  426. </xsl:when>
  427. <xsl:otherwise>
  428. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  429. <xsl:for-each select="$candidates/bp:Path_Point">
  430. <bp:Path_Point>
  431. <xsl:copy-of select="@*"/>
  432. <xsl:attribute name="bin_pos" select="1"/>
  433. </bp:Path_Point>
  434. </xsl:for-each>
  435. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  436. </xsl:otherwise>
  437. </xsl:choose>
  438. </xsl:variable>
  439. <xsl:if test="number($debug) &gt; 0">
  440. <debug423>
  441. <xsl:attribute name="liczenie_dla"/>
  442. <candidates>
  443. <xsl:copy-of select="$candidates"/>
  444. </candidates>
  445. <poprzednie_odpalam_liczenie_or_nie>
  446. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  447. </poprzednie_odpalam_liczenie_or_nie>
  448. </debug423>
  449. </xsl:if>
  450. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  451. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  452. <poprzednie_odpalam_liczenie_or_nie>
  453. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  454. <xsl:if test="position() = last()">
  455. <xsl:copy-of select="."/>
  456. </xsl:if>
  457. </xsl:for-each>
  458. <nizej_zwykly></nizej_zwykly>
  459. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  460. <xsl:if test="position() = last()">
  461. <xsl:copy-of select="."/>
  462. </xsl:if>
  463. </xsl:for-each>
  464. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  465. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  466. </poprzednie_odpalam_liczenie_or_nie>
  467. </xsl:result-document>
  468. </PointMatrixGroup>
  469. </xsl:for-each>
  470. </xsl:for-each>
  471. </PointMatrixGroupPE>
  472. <!--<PointMatrix>
  473. <xsl:attribute name="bit_max" select="$bit_max"/>
  474. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  475. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  476. <!-\-<xsl:call-template name="PE_wariant">
  477. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  478. <xsl:with-param name="bit_max" select="$bit_max"/>
  479. </xsl:call-template>-\->
  480. </PointMatrix>-->
  481. </Path>
  482. </xsl:template>
  483. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  484. <xsl:apply-templates mode="PathsCrossed"/>
  485. </xsl:template>
  486. <xsl:template match="bp:Path_Point_Cable|bp:Path_Point" mode="PathsCrossed">
  487. <xsl:copy-of select="."/>
  488. </xsl:template>
  489. <xsl:template match="*|text()" mode="PathsCrossed"/>
  490. <xsl:template name="calculate_optimum">
  491. <xsl:param name="candidates" required="yes"/>
  492. <xsl:param name="elements_cnt" required="yes"/>
  493. <xsl:param name="variant" select="1"/>
  494. <xsl:param name="max_bit" required="yes"/>
  495. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  496. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  497. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  498. <xsl:variable name="cand_to_calc">
  499. <xsl:for-each select="$candidates/bp:Path_Point">
  500. <!--<xsl:sort select="number(@distance)"/>-->
  501. <bp:Path_Point>
  502. <!--<xsl:attribute name="bit" select="$bit"/>-->
  503. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  504. <xsl:copy-of select="@*"/>
  505. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  506. </bp:Path_Point>
  507. </xsl:for-each>
  508. </xsl:variable>
  509. <!-- debug -->
  510. <xsl:if test=" number($debug) &gt; 2">
  511. <variant><xsl:attribute name="variant" select="$variant"/>
  512. <xsl:attribute name="cur_bit" select="$bit"/>
  513. <xsl:attribute name="best_cost" select="$best_cost"/>
  514. <xsl:attribute name="best_variant" select="$best_variant"/>
  515. <xsl:copy-of select="$cand_to_calc"/>
  516. </variant>
  517. </xsl:if>
  518. <xsl:variable name="calc_cost_way">
  519. <xsl:call-template name="calc_cost_way">
  520. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  521. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  522. </xsl:call-template>
  523. </xsl:variable>
  524. <xsl:variable name="cost_sum">
  525. <costs>
  526. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  527. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  528. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  529. <xsl:copy-of select="$calc_cost_way"/>
  530. </costs>
  531. </xsl:variable>
  532. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  533. <xsl:variable name="best">
  534. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  535. <xsl:choose>
  536. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  537. <best>
  538. <xsl:attribute name="best_cost" select="$cur_Price"/>
  539. <xsl:attribute name="best_variant" select="$bit"/>
  540. </best>
  541. </xsl:when>
  542. <xsl:otherwise>
  543. <best>
  544. <xsl:attribute name="best_cost" select="$best_cost"/>
  545. <xsl:attribute name="best_variant" select="$best_variant"/>
  546. </best>
  547. </xsl:otherwise>
  548. </xsl:choose>
  549. </xsl:variable>
  550. <xsl:if test=" number($debug) &gt; 3 "><xsl:copy-of select="$best"/></xsl:if>
  551. <xsl:choose>
  552. <xsl:when test="$bit = $max_bit">
  553. <koniec_wariantow>
  554. <xsl:message>#410 OK - przeliczony wariant bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  555. <xsl:attribute name="best_variant" select="$best_variant"/>
  556. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  557. <xsl:variable name="cand_to_calc_best">
  558. <xsl:for-each select="$candidates/bp:Path_Point">
  559. <!--<xsl:sort select="@distance"/>-->
  560. <bp:Path_Point>
  561. <!--<xsl:attribute name="bit" select="$bit"/>-->
  562. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  563. <xsl:copy-of select="@*"/>
  564. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  565. </bp:Path_Point>
  566. </xsl:for-each>
  567. </xsl:variable>
  568. <xsl:variable name="show_cables">
  569. <xsl:call-template name="calc_cost_way">
  570. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  571. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  572. <xsl:with-param name="show_cables" select="1"/>
  573. </xsl:call-template>
  574. </xsl:variable>
  575. <xsl:for-each select="$candidates/bp:Path_Point">
  576. <!--<xsl:sort select="number(@distance)"/>-->
  577. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  578. <bp:Path_Point>
  579. <xsl:attribute name="bit" select="$best_variant"/>
  580. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  581. <xsl:copy-of select="@*"/>
  582. <xsl:attribute name="Price" select="$best_cost"/>
  583. <xsl:copy-of select="bp:Path_Point"/>
  584. </bp:Path_Point>
  585. </xsl:if>
  586. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  587. <bp:Path_Point_Cable>
  588. <xsl:attribute name="bit" select="$best_variant"/>
  589. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  590. <xsl:copy-of select="@*"/>
  591. <xsl:attribute name="Price" select="$best_cost"/>
  592. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  593. <!-- todo do jakiego Join zostal przybity -->
  594. <xsl:copy-of select="bp:Path_Point"/>
  595. <!--<xsl:if test="$debug">
  596. <debug_show_cables>
  597. <xsl:copy-of select="$show_cables"></xsl:copy-of>
  598. </debug_show_cables>
  599. </xsl:if>-->
  600. </bp:Path_Point_Cable>
  601. </xsl:if>
  602. </xsl:for-each>
  603. </koniec_wariantow>
  604. </xsl:when>
  605. <xsl:otherwise>
  606. <xsl:call-template name="calculate_optimum">
  607. <xsl:with-param name="candidates" select="$candidates"/>
  608. <xsl:with-param name="max_bit" select="$max_bit"/>
  609. <xsl:with-param name="variant" select="$variant + 1"/>
  610. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  611. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  612. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  613. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  614. </xsl:call-template>
  615. </xsl:otherwise>
  616. </xsl:choose>
  617. </xsl:template>
  618. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  619. <xsl:param name="cand_to_calc" required="yes"/>
  620. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  621. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  622. <xsl:variable name="candidates_merged_with_poprzednie">
  623. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  624. <bp:Path_Point>
  625. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  626. <xsl:copy-of select="@*"/>
  627. <xsl:attribute name="distance_Neigh" select="0"/>
  628. </bp:Path_Point>
  629. </xsl:for-each>
  630. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  631. <bp:Path_Point>
  632. <xsl:copy-of select="@*"/>
  633. <xsl:attribute name="distance_Neigh" select="0"/>
  634. </bp:Path_Point>
  635. </xsl:for-each>
  636. <!-- dorzucenie Crossed -->
  637. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  638. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  639. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  640. <xsl:message>#681: PathsCrossed up $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>;</xsl:message>
  641. <bp:Path_Point>
  642. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  643. <xsl:attribute name="bin_pos" select="1"/>
  644. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  645. <xsl:choose>
  646. <xsl:when test="$PathCrossLast">
  647. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@distance)"/>
  648. </xsl:when>
  649. <xsl:otherwise>
  650. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@distance)"/>
  651. </xsl:otherwise>
  652. </xsl:choose>
  653. <xsl:attribute name="pos" select="-1"/>
  654. </bp:Path_Point>
  655. </xsl:for-each>
  656. </xsl:for-each>
  657. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  658. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  659. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  660. <xsl:message>#681: PathsCrossed dwn $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_dn_ID_Join"/>;</xsl:message>
  661. <bp:Path_Point>
  662. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  663. <xsl:attribute name="bin_pos" select="1"/>
  664. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  665. <xsl:choose>
  666. <xsl:when test="$PathCrossLast">
  667. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@distance)"/>
  668. </xsl:when>
  669. <xsl:otherwise>
  670. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@distance)"/>
  671. </xsl:otherwise>
  672. </xsl:choose>
  673. <xsl:attribute name="pos" select="-1"/>
  674. </bp:Path_Point>
  675. </xsl:for-each>
  676. </xsl:for-each>
  677. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  678. </xsl:variable>
  679. <xsl:if test="number($debug) &gt;1">
  680. <candidates_merged_with_poprzednie>
  681. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  682. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  683. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  684. </candidates_merged_with_poprzednie>
  685. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  686. </xsl:if>
  687. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  688. <xsl:sort select="number(@distance)"/>
  689. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  690. <xsl:choose>
  691. <xsl:when test="@poprzednia_grupa">
  692. <cost>
  693. <xsl:attribute name="Cable_Price" select="0"/>
  694. <xsl:attribute name="PE_Price" select="0"/>
  695. <xsl:attribute name="Price" select="0"/>
  696. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  697. </cost>
  698. </xsl:when>
  699. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  700. <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))"/>
  701. <xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>
  702. <xsl:variable name="way_up_len" >
  703. <xsl:choose>
  704. <xsl:when test="$way_up_id">
  705. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@id_path=$way_up_id]/@distance)"/></xsl:when>
  706. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  707. </xsl:choose>
  708. </xsl:variable>
  709. <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)) " />
  710. <xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_dn_id ]/@ID_Join"/>
  711. <xsl:variable name="way_dn_len">
  712. <xsl:choose>
  713. <xsl:when test="$way_dn_id">
  714. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@id_path=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  715. </xsl:when>
  716. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  717. </xsl:choose>
  718. </xsl:variable>
  719. <xsl:choose><!-- czy w gore czy w dol -->
  720. <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') -->
  721. <cost>
  722. <xsl:variable name="Cable_Price_sum">
  723. <xsl:choose>
  724. <xsl:when test="number(@point_count) &gt; 0 ">
  725. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  726. </xsl:when>
  727. <xsl:otherwise>
  728. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  729. </xsl:otherwise>
  730. </xsl:choose>
  731. </xsl:variable>
  732. <!-- todo @point_count -->
  733. <xsl:if test="$show_cables">
  734. <xsl:attribute name="choosed" select="'down'"/>
  735. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  736. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  737. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  738. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  739. <xsl:attribute name="PE_Price" select="0"/>
  740. <xsl:attribute name="Target_ID_Join" select="$ID_Join_dn"/>
  741. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  742. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  743. </xsl:if>
  744. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  745. </cost>
  746. </xsl:when>
  747. <xsl:otherwise>
  748. <cost>
  749. <xsl:variable name="Cable_Price_sum">
  750. <xsl:choose>
  751. <xsl:when test="number(@point_count) &gt; 0 ">
  752. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  753. </xsl:when>
  754. <xsl:otherwise>
  755. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  756. </xsl:otherwise>
  757. </xsl:choose>
  758. </xsl:variable>
  759. <xsl:if test="$show_cables or $debug">
  760. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  761. <xsl:attribute name="PE_Price" select="0"/>
  762. <xsl:attribute name="choosed" select="'up'"/>
  763. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  764. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  765. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  766. <xsl:attribute name="Target_ID_Join" select="$ID_Join_up"/>
  767. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  768. </xsl:if>
  769. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  770. </cost>
  771. </xsl:otherwise>
  772. </xsl:choose>
  773. </xsl:when>
  774. <xsl:otherwise>
  775. <cost>
  776. <xsl:attribute name="Cable_Price" select="0"/>
  777. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  778. <xsl:attribute name="Price" select="$PE_Price"/>
  779. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  780. </cost>
  781. </xsl:otherwise>
  782. </xsl:choose>
  783. </xsl:for-each>
  784. </xsl:template>
  785. </xsl:stylesheet>