edge_paths_with_PE_controll.xsl 34 KB

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