edge_paths_with_PE_controll.xsl 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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="countGr" select="count(current-group())"/>
  158. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  159. <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"/>
  160. @bit_max_Pos=<xsl:value-of select="$bit_max_Pos"/>; @id_path=<xsl:value-of select="@id_path"/>;
  161. 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)"/> ;
  162. distanceBeg/distanceEnd= <xsl:value-of select="min(current-group()/number(@distance))"/>/<xsl:value-of select="max(current-group()/number(@distance))"/>
  163. </xsl:message>
  164. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  165. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  166. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  167. <xsl:attribute name="id_path" select="@id_path"/>
  168. <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 -->
  169. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  170. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  171. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  172. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  173. <xsl:attribute name="countGr" select="$countGr"/>
  174. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  175. <xsl:for-each select="current-group()">
  176. <distance2>
  177. <xsl:attribute name="PosMatrGroup" select="position()"/>
  178. <xsl:copy-of select="@*"></xsl:copy-of>
  179. </distance2>
  180. </xsl:for-each>
  181. </PointMatrixGroupPos>
  182. </xsl:for-each-group>
  183. </PointMatrixGroup>
  184. </xsl:variable>
  185. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  186. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  187. -->
  188. <!-- debug -->
  189. <!--<xsl:copy-of select="$PointMatrixGroup"/>-->
  190. <PointMatrixGroupPE>
  191. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  192. <xsl:for-each select="PointMatrixGroupPos">
  193. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  194. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  195. <xsl:variable name="distanceGr" select="@distanceGr"/>
  196. <PointMatrixGroup>
  197. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  198. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  199. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  200. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  201. <xsl:attribute name="len_sum" select="@len_sum"/>
  202. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  203. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  204. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  205. <!-- ida kandydaci -->
  206. <xsl:variable name="candidates">
  207. <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 -->
  208. <xsl:sort select="@cost_dist" order="descending"/>
  209. <bp:Path_Point>
  210. <xsl:attribute name="DebugPosPoint" select="position()"/>
  211. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  212. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  213. <xsl:attribute name="pos" select="@pos"/>
  214. <xsl:attribute name="len" select="@len"/>
  215. <xsl:attribute name="distance" select="@distance"/>
  216. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  217. <xsl:attribute name="id_path" select="@id_path"/>
  218. <xsl:attribute name="point_count" select="@point_count"/>
  219. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  220. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  221. </bp:Path_Point>
  222. </xsl:for-each>
  223. </xsl:variable>
  224. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  225. $last = A
  226. - najprosciej przez pliki oszukujac silnik xsl
  227. - tozsamowsci $ID_Way $distanceGr
  228. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  229. -->
  230. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  231. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  232. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  233. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  234. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  235. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  236. </xsl:if>
  237. </xsl:variable>
  238. <!--<poprzednie_odpalam_liczenie_or_nie>
  239. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  240. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  241. </poprzednie_odpalam_liczenie_or_nie>-->
  242. <xsl:variable name="odpalam_liczenie_or_nie">
  243. <xsl:choose>
  244. <xsl:when test="count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1">
  245. <xsl:variable name="max_bit">
  246. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  247. </xsl:variable>
  248. <odpalam_liczenie>
  249. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  250. <xsl:call-template name="calculate_optimum">
  251. <xsl:with-param name="candidates" select="$candidates"/>
  252. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  253. <xsl:with-param name="max_bit" select="$max_bit"/>
  254. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  255. </xsl:call-template>
  256. </odpalam_liczenie>
  257. </xsl:when>
  258. <xsl:otherwise>
  259. <xsl:for-each select="$candidates/bp:Path_Point">
  260. <bp:Path_Point>
  261. <xsl:copy-of select="@*"/>
  262. <xsl:attribute name="bin_pos" select="1"/>
  263. </bp:Path_Point>
  264. </xsl:for-each>
  265. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  266. </xsl:otherwise>
  267. </xsl:choose>
  268. </xsl:variable>
  269. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  270. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  271. <poprzednie_odpalam_liczenie_or_nie>
  272. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  273. <xsl:if test="position() = last()">
  274. <xsl:copy-of select="."/>
  275. </xsl:if>
  276. </xsl:for-each>
  277. <nizej_zwykly></nizej_zwykly>
  278. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  279. <xsl:if test="position() = last()">
  280. <xsl:copy-of select="."/>
  281. </xsl:if>
  282. </xsl:for-each>
  283. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  284. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  285. </poprzednie_odpalam_liczenie_or_nie>
  286. </xsl:result-document>
  287. </PointMatrixGroup>
  288. </xsl:for-each>
  289. </xsl:for-each>
  290. </PointMatrixGroupPE>
  291. <!--<PointMatrix>
  292. <xsl:attribute name="bit_max" select="$bit_max"/>
  293. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  294. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  295. <!-\-<xsl:call-template name="PE_wariant">
  296. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  297. <xsl:with-param name="bit_max" select="$bit_max"/>
  298. </xsl:call-template>-\->
  299. </PointMatrix>-->
  300. </Path>
  301. </xsl:template>
  302. <xsl:template name="calculate_optimum">
  303. <xsl:param name="candidates" required="yes"/>
  304. <xsl:param name="elements_cnt" required="yes"/>
  305. <xsl:param name="variant" select="1"/>
  306. <xsl:param name="max_bit" required="yes"/>
  307. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  308. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  309. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  310. <xsl:variable name="cand_to_calc">
  311. <xsl:for-each select="$candidates/bp:Path_Point">
  312. <xsl:sort select="@distance"/>
  313. <bp:Path_Point>
  314. <!--<xsl:attribute name="bit" select="$bit"/>-->
  315. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  316. <xsl:copy-of select="@*"/>
  317. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  318. </bp:Path_Point>
  319. </xsl:for-each>
  320. </xsl:variable>
  321. <!-- debug -->
  322. <xsl:if test="$debug">
  323. <variant><xsl:attribute name="variant" select="$variant"/>
  324. <xsl:attribute name="cur_bit" select="$bit"/>
  325. <xsl:attribute name="best_cost" select="$best_cost"/>
  326. <xsl:attribute name="best_variant" select="$best_variant"/>
  327. <xsl:copy-of select="$cand_to_calc"/>
  328. </variant>
  329. </xsl:if>
  330. <xsl:variable name="calc_cost_way">
  331. <xsl:call-template name="calc_cost_way">
  332. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  333. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  334. </xsl:call-template>
  335. </xsl:variable>
  336. <xsl:variable name="cost_sum">
  337. <costs>
  338. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  339. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  340. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  341. <xsl:copy-of select="$calc_cost_way"/>
  342. </costs>
  343. </xsl:variable>
  344. <xsl:if test="$debug"><xsl:copy-of select="$cost_sum"/></xsl:if>
  345. <xsl:variable name="best">
  346. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  347. <xsl:choose>
  348. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  349. <best>
  350. <xsl:attribute name="best_cost" select="$cur_Price"/>
  351. <xsl:attribute name="best_variant" select="$bit"/>
  352. </best>
  353. </xsl:when>
  354. <xsl:otherwise>
  355. <best>
  356. <xsl:attribute name="best_cost" select="$best_cost"/>
  357. <xsl:attribute name="best_variant" select="$best_variant"/>
  358. </best>
  359. </xsl:otherwise>
  360. </xsl:choose>
  361. </xsl:variable>
  362. <xsl:copy-of select="$best"/>
  363. <xsl:choose>
  364. <xsl:when test="$bit = $max_bit">
  365. <koniec_wariantow>
  366. <xsl:message>#410 OK - przeliczony wariant bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  367. <xsl:attribute name="best_variant" select="$best_variant"/>
  368. <xsl:for-each select="$candidates/bp:Path_Point">
  369. <xsl:sort select="@distance"/>
  370. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  371. <bp:Path_Point>
  372. <xsl:attribute name="bit" select="$best_variant"/>
  373. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  374. <xsl:copy-of select="@*"/>
  375. <xsl:attribute name="Price" select="$best_cost"/>
  376. <xsl:copy-of select="bp:Path_Point"/>
  377. </bp:Path_Point>
  378. </xsl:if>
  379. </xsl:for-each>
  380. </koniec_wariantow>
  381. </xsl:when>
  382. <xsl:otherwise>
  383. <xsl:call-template name="calculate_optimum">
  384. <xsl:with-param name="candidates" select="$candidates"/>
  385. <xsl:with-param name="max_bit" select="$max_bit"/>
  386. <xsl:with-param name="variant" select="$variant + 1"/>
  387. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  388. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  389. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  390. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  391. </xsl:call-template>
  392. </xsl:otherwise>
  393. </xsl:choose>
  394. </xsl:template>
  395. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  396. <xsl:param name="cand_to_calc" required="yes"/>
  397. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  398. <xsl:variable name="candidates_merged_with_poprzednie">
  399. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/*">
  400. <bp:Path_Point>
  401. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  402. <xsl:copy-of select="@*"/>
  403. </bp:Path_Point>
  404. </xsl:for-each>
  405. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  406. <bp:Path_Point>
  407. <xsl:copy-of select="@*"/>
  408. </bp:Path_Point>
  409. </xsl:for-each>
  410. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  411. </xsl:variable>
  412. <xsl:if test="$debug">
  413. <candidates_merged_with_poprzednie>
  414. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  415. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  416. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  417. </candidates_merged_with_poprzednie>
  418. </xsl:if>
  419. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  420. <xsl:choose>
  421. <xsl:when test="@poprzednia_grupa">
  422. <cost>
  423. <xsl:attribute name="Cable_Price" select="0"/>
  424. <xsl:attribute name="PE_Price" select="0"/>
  425. <xsl:attribute name="Price" select="0"/>
  426. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  427. </cost>
  428. </xsl:when>
  429. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  430. <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))"/>
  431. <xsl:variable name="way_up_len" >
  432. <xsl:choose>
  433. <xsl:when test="$way_up_id">
  434. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@id_path=$way_up_id]/@distance)"/></xsl:when>
  435. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  436. </xsl:choose>
  437. </xsl:variable>
  438. <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)) " />
  439. <xsl:variable name="way_dn_len">
  440. <xsl:choose>
  441. <xsl:when test="$way_dn_id">
  442. <xsl:value-of select=" number($candidates_merged_with_poprzednie/bp:Path_Point[@id_path=$way_dn_id]/@distance ) - current()/@distance"/>
  443. </xsl:when>
  444. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  445. </xsl:choose>
  446. </xsl:variable>
  447. <xsl:choose><!-- czy w gore czy w dol -->
  448. <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') -->
  449. <cost>
  450. <xsl:variable name="Cable_Price_sum">
  451. <xsl:choose>
  452. <xsl:when test="number(@point_count) &gt; 0 ">
  453. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  454. </xsl:when>
  455. <xsl:otherwise>
  456. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  457. </xsl:otherwise>
  458. </xsl:choose>
  459. </xsl:variable>
  460. <!-- todo @point_count -->
  461. <xsl:attribute name="PE_Price" select="0"/>
  462. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  463. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  464. <xsl:attribute name="choosed" select="'down'"/>
  465. <xsl:attribute name="way_up_id" select="$way_up_id"/><xsl:attribute name="way_up_len" select="$way_up_len"/>
  466. <xsl:attribute name="way_dn_id" select="$way_dn_id"/><xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  467. </cost>
  468. </xsl:when>
  469. <xsl:otherwise>
  470. <cost>
  471. <xsl:variable name="Cable_Price_sum">
  472. <xsl:choose>
  473. <xsl:when test="number(@point_count) &gt; 0 ">
  474. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  475. </xsl:when>
  476. <xsl:otherwise>
  477. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  478. </xsl:otherwise>
  479. </xsl:choose>
  480. </xsl:variable>
  481. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  482. <xsl:attribute name="PE_Price" select="0"/>
  483. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  484. <xsl:attribute name="choosed" select="'up'"/>
  485. <xsl:attribute name="way_up_id" select="$way_up_id"/><xsl:attribute name="way_up_len" select="$way_up_len"/>
  486. <xsl:attribute name="way_dn_id" select="$way_dn_id"/><xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  487. </cost>
  488. </xsl:otherwise>
  489. </xsl:choose>
  490. </xsl:when>
  491. <xsl:otherwise>
  492. <cost>
  493. <xsl:attribute name="Cable_Price" select="0"/>
  494. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  495. <xsl:attribute name="Price" select="$PE_Price"/>
  496. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  497. </cost>
  498. </xsl:otherwise>
  499. </xsl:choose>
  500. </xsl:for-each>
  501. </xsl:template>
  502. </xsl:stylesheet>