edge_paths_with_PE_controll.xsl 35 KB

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