edge_paths_with_PE_controll.xsl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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="1500"/>
  11. <xsl:param name="Cable_Price" select="10"/>
  12. <xsl:param name="edge_paths_with_PE.xml"/>
  13. <xsl:param name="edge_paths_with_PE_controll_temp" select="'edge_paths_with_PE_controll_temp'"/> <!-- cache do przekazywani danych z petli-->
  14. <xsl:param name="edge_paths_with_PE_controll_temp.alias" select="'edge_paths_with_PE_controll_temp.alias'" />
  15. <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
  16. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie"/>
  17. <xsl:template match="edge_joins_filled_paths">
  18. <xsl:variable name="edge_joins_filled_paths_len">
  19. <xsl:for-each select="item">
  20. <xsl:sort select="number(asText/@len)" order="descending"/>
  21. <Path>
  22. <xsl:attribute name="id" select="@id"/>
  23. <xsl:attribute name="len" select="asText/@len"/>
  24. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  25. </Path>
  26. </xsl:for-each>
  27. </xsl:variable>
  28. <edge_paths_with_PE_controll>
  29. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  30. </edge_paths_with_PE_controll>
  31. <!--<xsl:result-document href="edge_paths_with_PE.xml">
  32. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  33. </xsl:result-document>-->
  34. </xsl:template>
  35. <xsl:template match="Path" mode="PointMatrixGroup">
  36. <Path>
  37. <xsl:variable name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
  38. <xsl:attribute name="id" select="@id"/>
  39. <xsl:variable name="ID_Way" select="@id"/>
  40. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  41. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  42. <xsl:attribute name="len" select="@len"/>
  43. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  44. <xsl:variable name="len" select="@len"/>
  45. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  46. <!--<EdgeWayJoinsPair>
  47. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  48. </EdgeWayJoinsPair>-->
  49. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  50. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  51. <xsl:variable name="EconomicDistanceCut">
  52. <EconomicDistanceCut>
  53. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString">
  54. <distance>
  55. <xsl:attribute name="pos" select="position()"/>
  56. <xsl:attribute name="not_id" select="@not_id"/>
  57. <xsl:attribute name="len" select="@len"/>
  58. <xsl:attribute name="id_path" select="@id_path"/>
  59. <xsl:attribute name="Points" select="count(Points)"/>
  60. <xsl:variable name="Points" select="count(Points)"/>
  61. <xsl:variable name="Ways" select="count(Ways)"/>
  62. <xsl:choose>
  63. <xsl:when test="$Ways or $Points">
  64. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  65. </xsl:when>
  66. </xsl:choose>
  67. </distance>
  68. </xsl:for-each>
  69. </EconomicDistanceCut>
  70. </xsl:variable>
  71. <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
  72. <xsl:variable name="EconomicDistanceCut2">
  73. <EconomicDistanceCut2>
  74. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  75. <distance2>
  76. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  77. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  78. <xsl:choose>
  79. <xsl:when test="@point_count&gt;0">
  80. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  81. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  82. ]/@pos)"/>
  83. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  84. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  85. number(@pos )&lt; number(current()/@pos )
  86. and number(@pos) &gt;= number($max_pos_z_pkt)
  87. ]/@len)"/>
  88. <xsl:attribute name="disttopkt" select="$disttopkt" />
  89. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * @point_count"/>
  90. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  91. <xsl:attribute name="point_count" select="@point_count"/>
  92. <xsl:if test="$cost_dist &gt; $PE_Price">
  93. <xsl:attribute name="cut_by_pe" select="1"/>
  94. </xsl:if>
  95. <xsl:attribute name="not_id" select="@not_id"/>
  96. </xsl:when>
  97. <xsl:otherwise>
  98. <xsl:attribute name="point_count" select="0"/>
  99. </xsl:otherwise>
  100. </xsl:choose>
  101. <xsl:attribute name="id_path" select="@id_path"/>
  102. <xsl:copy-of select="@point_count"/>
  103. <xsl:copy-of select="@pos"/>
  104. <xsl:copy-of select="@len"/>
  105. </distance2>
  106. </xsl:for-each>
  107. </EconomicDistanceCut2>
  108. </xsl:variable>
  109. <xsl:copy-of select="$EconomicDistanceCut2"/>
  110. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  111. <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-->
  112. <!-- pogrupujemy elementy co 50 metrow -->
  113. <xsl:variable name="PointMatrixGroup">
  114. <PointMatrixGroup>
  115. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="round( @distance div ( $PE_Price div $Cable_Price + 50 ))">
  116. <PointMatrixGroupPos>
  117. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  118. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  119. <xsl:attribute name="distanceGr" select=" current-grouping-key()"/>
  120. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  121. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  122. <xsl:attribute name="id_path" select="@id_path"/>
  123. <xsl:attribute name="point_count_Pos" select="sum(current-group()/@point_count)"/>
  124. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  125. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  126. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  127. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  128. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  129. <xsl:for-each select="current-group()">
  130. <distance2>
  131. <xsl:attribute name="PosMatrGroup" select="position()"/>
  132. <xsl:copy-of select="@*"></xsl:copy-of>
  133. </distance2>
  134. </xsl:for-each>
  135. </PointMatrixGroupPos>
  136. </xsl:for-each-group>
  137. </PointMatrixGroup>
  138. </xsl:variable>
  139. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  140. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  141. -->
  142. <!-- debug -->
  143. <xsl:copy-of select="$PointMatrixGroup"/>
  144. <PointMatrixGroupPE>
  145. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  146. <xsl:for-each select="PointMatrixGroupPos">
  147. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  148. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  149. <xsl:variable name="distanceGr" select="@distanceGr"/>
  150. <PointMatrixGroup>
  151. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/><xsl:attribute name="point_count_Pos" select="$point_count_Pos"/><xsl:attribute name="distanceGr" select="$distanceGr"/>
  152. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  153. <xsl:attribute name="len_sum" select="@len_sum"/>
  154. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  155. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  156. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  157. <!-- ida kandydaci -->
  158. <xsl:variable name="candidates">
  159. <xsl:for-each select="distance2[( 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 -->
  160. <xsl:sort select="@cost_dist" order="descending"/>
  161. <bp:Path_Point>
  162. <xsl:attribute name="DebugPosPoint" select="position()"/>
  163. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  164. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  165. <xsl:attribute name="pos" select="@pos"/>
  166. <xsl:attribute name="len" select="@len"/>
  167. <xsl:attribute name="distance" select="@distance"/>
  168. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  169. <xsl:attribute name="id_path" select="@id_path"/>
  170. <xsl:attribute name="point_count" select="@point_count"/>
  171. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  172. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  173. </bp:Path_Point>
  174. </xsl:for-each>
  175. </xsl:variable>
  176. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  177. $last = A
  178. - najprosciej przez pliki oszukujac silnik xsl
  179. - tozsamowsci $ID_Way $distanceGr
  180. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  181. -->
  182. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  183. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  184. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  185. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  186. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  187. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  188. </xsl:if>
  189. </xsl:variable>
  190. <!--<poprzednie_odpalam_liczenie_or_nie>
  191. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  192. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  193. </poprzednie_odpalam_liczenie_or_nie>-->
  194. <xsl:variable name="odpalam_liczenie_or_nie">
  195. <xsl:choose>
  196. <xsl:when test="count($candidates/bp:Path_Point) &lt; 10 and count($candidates/bp:Path_Point)&gt;1">
  197. <xsl:variable name="max_bit">
  198. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  199. </xsl:variable>
  200. <odpalam_liczenie>
  201. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  202. <xsl:call-template name="calculate_optimum">
  203. <xsl:with-param name="candidates" select="$candidates"/>
  204. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  205. <xsl:with-param name="max_bit" select="$max_bit"/>
  206. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  207. </xsl:call-template>
  208. </odpalam_liczenie>
  209. </xsl:when>
  210. <xsl:otherwise>
  211. <xsl:for-each select="$candidates/bp:Path_Point">
  212. <bp:Path_Point>
  213. <xsl:copy-of select="@*"/>
  214. <xsl:attribute name="bin_pos" select="1"/>
  215. </bp:Path_Point>
  216. </xsl:for-each>
  217. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  218. </xsl:otherwise>
  219. </xsl:choose>
  220. </xsl:variable>
  221. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  222. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  223. <poprzednie_odpalam_liczenie_or_nie>
  224. <xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  225. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>
  226. </poprzednie_odpalam_liczenie_or_nie>
  227. </xsl:result-document>
  228. </PointMatrixGroup>
  229. </xsl:for-each>
  230. </xsl:for-each>
  231. </PointMatrixGroupPE>
  232. <!--<PointMatrix>
  233. <xsl:attribute name="bit_max" select="$bit_max"/>
  234. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  235. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  236. <!-\-<xsl:call-template name="PE_wariant">
  237. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  238. <xsl:with-param name="bit_max" select="$bit_max"/>
  239. </xsl:call-template>-\->
  240. </PointMatrix>-->
  241. </Path>
  242. </xsl:template>
  243. <xsl:template name="calculate_optimum">
  244. <xsl:param name="candidates" required="yes"/>
  245. <xsl:param name="elements_cnt" required="yes"/>
  246. <xsl:param name="variant" select="1"/>
  247. <xsl:param name="max_bit" required="yes"/>
  248. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  249. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  250. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  251. <xsl:variable name="cand_to_calc">
  252. <xsl:for-each select="$candidates/bp:Path_Point">
  253. <xsl:sort select="@distance"/>
  254. <bp:Path_Point>
  255. <!--<xsl:attribute name="bit" select="$bit"/>-->
  256. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  257. <xsl:copy-of select="@*"/>
  258. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  259. </bp:Path_Point>
  260. </xsl:for-each>
  261. </xsl:variable>
  262. <!-- debug -->
  263. <variant><xsl:attribute name="variant" select="$variant"/>
  264. <xsl:attribute name="cur_bit" select="$bit"/>
  265. <xsl:attribute name="best_cost" select="$best_cost"/>
  266. <xsl:attribute name="best_variant" select="$best_variant"/>
  267. <xsl:copy-of select="$cand_to_calc"/>
  268. </variant>
  269. <xsl:variable name="calc_cost_way">
  270. <xsl:call-template name="calc_cost_way">
  271. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  272. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  273. </xsl:call-template>
  274. </xsl:variable>
  275. <xsl:variable name="cost_sum">
  276. <costs>
  277. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  278. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  279. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  280. <xsl:copy-of select="$calc_cost_way"/>
  281. </costs>
  282. </xsl:variable>
  283. <xsl:copy-of select="$cost_sum"></xsl:copy-of>
  284. <xsl:variable name="best">
  285. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  286. <xsl:choose>
  287. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  288. <best>
  289. <xsl:attribute name="best_cost" select="$cur_Price"/>
  290. <xsl:attribute name="best_variant" select="$bit"/>
  291. </best>
  292. </xsl:when>
  293. <xsl:otherwise>
  294. <best>
  295. <xsl:attribute name="best_cost" select="$best_cost"/>
  296. <xsl:attribute name="best_variant" select="$best_variant"/>
  297. </best>
  298. </xsl:otherwise>
  299. </xsl:choose>
  300. </xsl:variable>
  301. <!--<xsl:copy-of select="$best"/>-->
  302. <xsl:choose>
  303. <xsl:when test="$bit = $max_bit">
  304. <koniec_wariantow>
  305. <xsl:attribute name="best_variant" select="$best_variant"/>
  306. <xsl:for-each select="$candidates/bp:Path_Point">
  307. <xsl:sort select="@distance"/>
  308. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  309. <bp:Path_Point>
  310. <xsl:attribute name="bit" select="$best_variant"/>
  311. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  312. <xsl:copy-of select="@*"/>
  313. <xsl:attribute name="Price" select="$best_cost"/>
  314. <xsl:copy-of select="bp:Path_Point"/>
  315. </bp:Path_Point>
  316. </xsl:if>
  317. </xsl:for-each>
  318. </koniec_wariantow>
  319. </xsl:when>
  320. <xsl:otherwise>
  321. <xsl:call-template name="calculate_optimum">
  322. <xsl:with-param name="candidates" select="$candidates"/>
  323. <xsl:with-param name="max_bit" select="$max_bit"/>
  324. <xsl:with-param name="variant" select="$variant + 1"/>
  325. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  326. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  327. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  328. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  329. </xsl:call-template>
  330. </xsl:otherwise>
  331. </xsl:choose>
  332. </xsl:template>
  333. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  334. <xsl:param name="cand_to_calc" required="yes"/>
  335. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  336. <xsl:variable name="candidates_merged_with_poprzednie">
  337. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/*">
  338. <bp:Path_Point>
  339. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  340. <xsl:copy-of select="@*"/>
  341. </bp:Path_Point>
  342. </xsl:for-each>
  343. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  344. <bp:Path_Point>
  345. <xsl:copy-of select="@*"/>
  346. </bp:Path_Point>
  347. </xsl:for-each>
  348. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  349. </xsl:variable>
  350. <!--<candidates_merged_with_poprzednie>
  351. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  352. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  353. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  354. </candidates_merged_with_poprzednie>-->
  355. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  356. <xsl:choose>
  357. <xsl:when test="@poprzednia_grupa">
  358. <cost>
  359. <xsl:attribute name="Cable_Price" select="0"/>
  360. <xsl:attribute name="PE_Price" select="0"/>
  361. <xsl:attribute name="Price" select="0"/>
  362. <xsl:attribute name="debug" select="'ignore by last DistGroup'"/>
  363. </cost>
  364. </xsl:when>
  365. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  366. <xsl:variable name="way_up_id" select="max($cand_to_calc/bp:Path_Point[@bin_pos=1 and @id_path &lt; current()/@id_path ]/number(@id_path))"/>
  367. <xsl:variable name="way_up_len" >
  368. <xsl:choose>
  369. <xsl:when test="$way_up_id">
  370. <xsl:value-of select="number( current()/@distance) - number($cand_to_calc/bp:Path_Point[@id_path=$way_up_id]/@distance)"/></xsl:when>
  371. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  372. </xsl:choose>
  373. </xsl:variable>
  374. <xsl:variable name="way_dn_id" select="max($cand_to_calc/bp:Path_Point[@bin_pos=1 and @id_path &gt; current()/@id_path ]/number(@id_path)) " />
  375. <xsl:variable name="way_dn_len">
  376. <xsl:choose>
  377. <xsl:when test="$way_dn_id">
  378. <xsl:value-of select=" number($cand_to_calc/bp:Path_Point[@id_path=$way_dn_id]/@distance ) - current()/@distance"/>
  379. </xsl:when>
  380. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  381. </xsl:choose>
  382. </xsl:variable>
  383. <xsl:choose><!-- czy w gore czy w dol -->
  384. <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') -->
  385. <cost>
  386. <xsl:variable name="Cable_Price_sum">
  387. <xsl:choose>
  388. <xsl:when test="number(@point_count) &gt; 0 ">
  389. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  390. </xsl:when>
  391. <xsl:otherwise>
  392. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  393. </xsl:otherwise>
  394. </xsl:choose>
  395. </xsl:variable>
  396. <!-- todo @point_count -->
  397. <xsl:attribute name="PE_Price" select="0"/>
  398. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  399. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  400. <xsl:attribute name="choosed" select="'down'"/>
  401. <xsl:attribute name="way_up_id" select="$way_up_id"/><xsl:attribute name="way_up_len" select="$way_up_len"/>
  402. <xsl:attribute name="way_dn_id" select="$way_dn_id"/><xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  403. </cost>
  404. </xsl:when>
  405. <xsl:otherwise>
  406. <cost>
  407. <xsl:variable name="Cable_Price_sum">
  408. <xsl:choose>
  409. <xsl:when test="number(@point_count) &gt; 0 ">
  410. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  411. </xsl:when>
  412. <xsl:otherwise>
  413. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  414. </xsl:otherwise>
  415. </xsl:choose>
  416. </xsl:variable>
  417. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  418. <xsl:attribute name="PE_Price" select="0"/>
  419. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  420. <xsl:attribute name="choosed" select="'up'"/>
  421. <xsl:attribute name="way_up_id" select="$way_up_id"/><xsl:attribute name="way_up_len" select="$way_up_len"/>
  422. <xsl:attribute name="way_dn_id" select="$way_dn_id"/><xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  423. </cost>
  424. </xsl:otherwise>
  425. </xsl:choose>
  426. </xsl:when>
  427. <xsl:otherwise>
  428. <cost>
  429. <xsl:attribute name="Cable_Price" select="0"/>
  430. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  431. <xsl:attribute name="Price" select="$PE_Price"/>
  432. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  433. </cost>
  434. </xsl:otherwise>
  435. </xsl:choose>
  436. </xsl:for-each>
  437. </xsl:template>
  438. </xsl:stylesheet>