edge_paths_with_PE_controll.xsl 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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="10"/> <!-- 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_xml"><!-- w przypadku wyzwolenia dla pojedynczego pliku -->
  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. <edge_paths_with_PE_controll>
  28. <xsl:attribute name="logic" select="$logic"/>
  29. <!-- <xsl:attribute name="id" select="@id"/>
  30. <xsl:attribute name="len" select="@len"/>
  31. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>-->
  32. <xsl:apply-templates mode="PointMatrixGroup">
  33. <xsl:with-param name="edge_joins_filled_path" select="parent::node()"/><!-- jak lecimy natywnie dla pliku edge_joins_filled_paths_xml to dane sa w node()-->
  34. </xsl:apply-templates>
  35. </edge_paths_with_PE_controll>
  36. </xsl:template>
  37. <xsl:template match="edge_joins_filled_paths">
  38. <xsl:message>Running script for params:
  39. PE_Price=<xsl:value-of select="$PE_Price"/>
  40. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  41. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  42. logic=<xsl:value-of select="$logic"/> .EOF
  43. </xsl:message>
  44. <xsl:variable name="edge_joins_filled_paths_len">
  45. <xsl:for-each select="item">
  46. <xsl:sort select="number(asText/@len)" order="descending"/>
  47. <Path>
  48. <xsl:attribute name="id" select="@id"/>
  49. <xsl:attribute name="len" select="asText/@len"/>
  50. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  51. </Path>
  52. </xsl:for-each>
  53. </xsl:variable>
  54. <edge_paths_with_PE_controll>
  55. <xsl:attribute name="logic" select="$logic"/>
  56. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  57. </edge_paths_with_PE_controll>
  58. <!--<xsl:result-document href="edge_paths_with_PE.xml">
  59. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  60. </xsl:result-document>-->
  61. </xsl:template>
  62. <xsl:template match="Path|asText_XMl" mode="PointMatrixGroup">
  63. <xsl:param name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
  64. <Path>
  65. <xsl:attribute name="id" select="@id"/>
  66. <xsl:variable name="ID_Way" select="@id"/>
  67. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  68. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  69. <xsl:attribute name="len" select="@len"/>
  70. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  71. <xsl:variable name="len" select="@len"/>
  72. <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)"/>
  73. Points_cnt=<xsl:value-of select="@Points_cnt"/>
  74. </xsl:message>
  75. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  76. <EdgeWayJoinsPair>
  77. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  78. </EdgeWayJoinsPair>
  79. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  80. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  81. <xsl:variable name="EconomicDistanceCut">
  82. <EconomicDistanceCut>
  83. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[not(@error)]">
  84. <distance>
  85. <xsl:attribute name="pos" select="position()"/>
  86. <xsl:attribute name="not_id" select="@not_id"/>
  87. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  88. <xsl:attribute name="len" select="@len"/>
  89. <xsl:attribute name="id_path" select="@id_path"/>
  90. <xsl:variable name="Points" select="count(Points)"/>
  91. <xsl:attribute name="Points" select="$Points"/>
  92. <xsl:variable name="Ways" select="count(Ways)"/>
  93. <xsl:attribute name="Ways_count" select="$Ways"/>
  94. <xsl:choose>
  95. <xsl:when test="$Ways or $Points">
  96. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  97. <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  98. </xsl:when>
  99. <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
  100. <xsl:attribute name="point_count" select="0"/>
  101. </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  102. </xsl:choose>
  103. </distance>
  104. </xsl:for-each>
  105. </EconomicDistanceCut>
  106. </xsl:variable>
  107. <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
  108. <xsl:variable name="EconomicDistanceCut2">
  109. <EconomicDistanceCut2>
  110. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  111. <distance2>
  112. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  113. <xsl:copy-of select="@ID_Join"/>
  114. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  115. <xsl:choose>
  116. <xsl:when test="number(@point_count)&gt;0">
  117. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  118. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  119. ]/@pos)"/>
  120. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  121. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  122. number(@pos )&lt; number(current()/@pos )
  123. and number(@pos) &gt;= number($max_pos_z_pkt)
  124. ]/@len)"/>
  125. <xsl:attribute name="disttopkt" select="$disttopkt" />
  126. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * number(@point_count)"/>
  127. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  128. <xsl:attribute name="point_count" select="@point_count"/>
  129. <xsl:attribute name="Ways_count" select="@Ways_count"/>
  130. <xsl:choose> <!-- to powinno przeciac grupe ale moze nie? -->
  131. <xsl:when test="$cost_dist &gt; $PE_Price">
  132. <xsl:attribute name="cut_by_pe" select="1"/>
  133. </xsl:when>
  134. <xsl:otherwise><xsl:attribute name="cut_by_pe" select="0"/></xsl:otherwise>
  135. </xsl:choose>
  136. <xsl:attribute name="not_id" select="@not_id"/> <!-- to jest z ID way - way ma 2 pointsy! -->
  137. </xsl:when>
  138. <xsl:otherwise>
  139. <xsl:choose>
  140. <xsl:when test="number(@Ways_count)&gt;0">
  141. <xsl:attribute name="point_count" select="@Ways_count"/>
  142. </xsl:when>
  143. <xsl:otherwise><xsl:attribute name="point_count" select="0"/></xsl:otherwise>
  144. </xsl:choose>
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. <xsl:attribute name="id_path" select="@id_path"/>
  148. <xsl:copy-of select="@point_count"/>
  149. <xsl:copy-of select="@pos"/><!-- position() -->
  150. <xsl:copy-of select="@len"/>
  151. <xsl:copy-of select="@ForceCutByPrice"/>
  152. <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
  153. </distance2>
  154. </xsl:for-each>
  155. </EconomicDistanceCut2>
  156. </xsl:variable>
  157. <debug_Cut2_183>
  158. <xsl:copy-of select="$EconomicDistanceCut2"/>
  159. </debug_Cut2_183>
  160. <xsl:variable name="EconomicDistanceCut2">
  161. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  162. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  163. <distance2>
  164. <xsl:copy-of select="@*"/>
  165. <xsl:choose>
  166. <xsl:when test=" position() mod $max_combinate_groups_elements = 0"> <!--- minus puste sum($EconomicDistanceCut/EconomicDistanceCut/distance[ number(@pos) &lt; number(current()/@pos) ]/number(@NotPoints)) ) --><!-- nabija grupe do przeliczenia-->
  167. <xsl:attribute name="PosCut3Flag" select="1"/>
  168. </xsl:when>
  169. <xsl:otherwise>
  170. <xsl:attribute name="PosCut3Flag" select="0"/>
  171. </xsl:otherwise>
  172. </xsl:choose>
  173. </distance2>
  174. </xsl:for-each>
  175. </EconomicDistanceCut2>
  176. </xsl:variable>
  177. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  178. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  179. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  180. <distance2>
  181. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  182. <xsl:copy-of select="@*"/>
  183. </distance2>
  184. </xsl:for-each>
  185. </EconomicDistanceCut2>
  186. </xsl:variable>
  187. <!-- debug -->
  188. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  189. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  190. <distance2>
  191. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  192. <xsl:copy-of select="@PosCut3GrId"/>
  193. <xsl:copy-of select="@CurSumNotPoints"/>
  194. <xsl:copy-of select="@NotPoints"/>
  195. <!-\-<xsl:copy-of select="@pos"/>-\->
  196. </distance2>
  197. </xsl:for-each>
  198. </EconomicDistanceCut2>-->
  199. <!-- debug -->
  200. <!--<debug>
  201. <xsl:copy-of select="$EconomicDistanceCut2"/>
  202. </debug>-->
  203. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count &gt; 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
  204. <!--<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-->
  205. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  206. <xsl:variable name="PointMatrixGroup">
  207. <PointMatrixGroup>
  208. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  209. <PointMatrixGroupPos>
  210. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  211. <xsl:variable name="countGr" select="count(current-group())"/>
  212. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
  213. <xsl:message>Nowa grupa Ways:<xsl:value-of select="@PosCut3GrId"/>; distanceGr=<xsl:value-of select="@PosCut3GrId"/>;elements_cnt_Pos=<xsl:value-of select="$elements_cnt_Pos"/>; @bit_max_Pos=<xsl:value-of select="$bit_max_Pos"/>; @id_path=<xsl:value-of select="@id_path"/>; countGr=<xsl:value-of select="$countGr"/>; point_count_Pos=<xsl:value-of select="sum(current-group()/@point_count)"/>; len_sum=<xsl:value-of select="sum(current-group()/@len)"/> ; distanceBeg/distanceEnd= <xsl:value-of select="min(current-group()/number(@distance))"/>/<xsl:value-of select="max(current-group()/number(@distance))"/>
  214. </xsl:message>
  215. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  216. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  217. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  218. <xsl:attribute name="id_path" select="@id_path"/>
  219. <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 -->
  220. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  221. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  222. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  223. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  224. <xsl:attribute name="countGr" select="$countGr"/>
  225. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  226. <xsl:for-each select="current-group()">
  227. <distance2>
  228. <xsl:attribute name="PosMatrGroup" select="position()"/>
  229. <xsl:copy-of select="@*"></xsl:copy-of>
  230. </distance2>
  231. </xsl:for-each>
  232. </PointMatrixGroupPos>
  233. </xsl:for-each-group>
  234. </PointMatrixGroup>
  235. </xsl:variable>
  236. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  237. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  238. -->
  239. <!-- debug -->
  240. <!--<xsl:copy-of select="$PointMatrixGroup"/>-->
  241. <PointMatrixGroupPE>
  242. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  243. <xsl:for-each select="PointMatrixGroupPos">
  244. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  245. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  246. <xsl:variable name="distanceGr" select="@distanceGr"/>
  247. <PointMatrixGroup>
  248. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  249. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  250. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  251. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  252. <xsl:attribute name="len_sum" select="@len_sum"/>
  253. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  254. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  255. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  256. <xsl:message>#239: calc @distanceGr=<xsl:value-of select="$distanceGr"/>; @point_count_Pos=<xsl:value-of select="@point_count_Pos"/>;@LineStringCount ; @len_sum=<xsl:value-of select="@len_sum"/>; @distanceBeg=<xsl:value-of select="@distanceBeg"/>; @distanceEnd=<xsl:value-of select="@distanceEnd"/>;
  257. </xsl:message>
  258. <!-- ida kandydaci -->
  259. <xsl:variable name="candidates">
  260. <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 -->
  261. <xsl:sort select="@cost_dist" order="descending"/>
  262. <bp:Path_Point>
  263. <xsl:copy-of select="@ID_Join"/>
  264. <xsl:attribute name="DebugPosPoint" select="position()"/>
  265. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  266. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  267. <xsl:attribute name="pos" select="@pos"/>
  268. <xsl:attribute name="len" select="@len"/>
  269. <xsl:attribute name="distance" select="@distance"/>
  270. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  271. <xsl:attribute name="id_path" select="@id_path"/>
  272. <xsl:attribute name="point_count" select="@point_count"/>
  273. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  274. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  275. </bp:Path_Point>
  276. </xsl:for-each>
  277. </xsl:variable>
  278. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  279. $last = A
  280. - najprosciej przez pliki oszukujac silnik xsl
  281. - tozsamowsci $ID_Way $distanceGr
  282. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  283. -->
  284. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  285. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  286. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  287. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  288. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  289. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  290. </xsl:if>
  291. </xsl:variable>
  292. <!--<poprzednie_odpalam_liczenie_or_nie>
  293. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  294. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  295. </poprzednie_odpalam_liczenie_or_nie>-->
  296. <xsl:variable name="odpalam_liczenie_or_nie">
  297. <xsl:choose>
  298. <xsl:when test="count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1">
  299. <xsl:variable name="max_bit">
  300. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  301. </xsl:variable>
  302. <odpalam_liczenie>
  303. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  304. <!--<disabled>temporary blad after #410 OK - przeliczony wariant bit=000000010000 ( nr 4095;)
  305. [xslt] #239: calc @distanceGr=23; @point_count_Pos=19;@LineStringCount ; @len_sum=177; @distanceBeg=5055; @distanceEnd=5475;
  306. [xslt]
  307. [xslt] /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/edge_paths_with_PE_controll.xsl:571: Fatal Error! Cannot convert string to double: ""
  308. [xslt] Failed to process /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/edge_joins_filled_paths.xml</disabled>-->
  309. <xsl:call-template name="calculate_optimum">
  310. <xsl:with-param name="candidates" select="$candidates"/>
  311. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  312. <xsl:with-param name="max_bit" select="$max_bit"/>
  313. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  314. </xsl:call-template>
  315. <debug352_cand><xsl:copy-of select="$candidates"></xsl:copy-of> </debug352_cand>
  316. </odpalam_liczenie>
  317. </xsl:when>
  318. <xsl:otherwise>
  319. <xsl:for-each select="$candidates/bp:Path_Point">
  320. <bp:Path_Point>
  321. <xsl:copy-of select="@*"/>
  322. <xsl:attribute name="bin_pos" select="1"/>
  323. </bp:Path_Point>
  324. </xsl:for-each>
  325. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  326. </xsl:otherwise>
  327. </xsl:choose>
  328. </xsl:variable>
  329. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  330. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  331. <poprzednie_odpalam_liczenie_or_nie>
  332. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  333. <xsl:if test="position() = last()">
  334. <xsl:copy-of select="."/>
  335. </xsl:if>
  336. </xsl:for-each>
  337. <nizej_zwykly></nizej_zwykly>
  338. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  339. <xsl:if test="position() = last()">
  340. <xsl:copy-of select="."/>
  341. </xsl:if>
  342. </xsl:for-each>
  343. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  344. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  345. </poprzednie_odpalam_liczenie_or_nie>
  346. </xsl:result-document>
  347. </PointMatrixGroup>
  348. </xsl:for-each>
  349. </xsl:for-each>
  350. </PointMatrixGroupPE>
  351. <!--<PointMatrix>
  352. <xsl:attribute name="bit_max" select="$bit_max"/>
  353. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  354. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  355. <!-\-<xsl:call-template name="PE_wariant">
  356. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  357. <xsl:with-param name="bit_max" select="$bit_max"/>
  358. </xsl:call-template>-\->
  359. </PointMatrix>-->
  360. </Path>
  361. </xsl:template>
  362. <xsl:template name="calculate_optimum">
  363. <xsl:param name="candidates" required="yes"/>
  364. <xsl:param name="elements_cnt" required="yes"/>
  365. <xsl:param name="variant" select="1"/>
  366. <xsl:param name="max_bit" required="yes"/>
  367. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  368. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  369. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  370. <xsl:variable name="cand_to_calc">
  371. <xsl:for-each select="$candidates/bp:Path_Point">
  372. <xsl:sort select="@distance"/>
  373. <bp:Path_Point>
  374. <!--<xsl:attribute name="bit" select="$bit"/>-->
  375. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  376. <xsl:copy-of select="@*"/>
  377. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  378. </bp:Path_Point>
  379. </xsl:for-each>
  380. </xsl:variable>
  381. <!-- debug -->
  382. <xsl:if test="$debug">
  383. <variant><xsl:attribute name="variant" select="$variant"/>
  384. <xsl:attribute name="cur_bit" select="$bit"/>
  385. <xsl:attribute name="best_cost" select="$best_cost"/>
  386. <xsl:attribute name="best_variant" select="$best_variant"/>
  387. <xsl:copy-of select="$cand_to_calc"/>
  388. </variant>
  389. </xsl:if>
  390. <xsl:variable name="calc_cost_way">
  391. <xsl:call-template name="calc_cost_way">
  392. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  393. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  394. </xsl:call-template>
  395. </xsl:variable>
  396. <xsl:variable name="cost_sum">
  397. <costs>
  398. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  399. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  400. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  401. <xsl:copy-of select="$calc_cost_way"/>
  402. </costs>
  403. </xsl:variable>
  404. <xsl:if test="$debug"><xsl:copy-of select="$cost_sum"/></xsl:if>
  405. <xsl:variable name="best">
  406. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  407. <xsl:choose>
  408. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  409. <best>
  410. <xsl:attribute name="best_cost" select="$cur_Price"/>
  411. <xsl:attribute name="best_variant" select="$bit"/>
  412. </best>
  413. </xsl:when>
  414. <xsl:otherwise>
  415. <best>
  416. <xsl:attribute name="best_cost" select="$best_cost"/>
  417. <xsl:attribute name="best_variant" select="$best_variant"/>
  418. </best>
  419. </xsl:otherwise>
  420. </xsl:choose>
  421. </xsl:variable>
  422. <xsl:if test="$debug"><xsl:copy-of select="$best"/></xsl:if>
  423. <xsl:choose>
  424. <xsl:when test="$bit = $max_bit">
  425. <koniec_wariantow>
  426. <xsl:message>#410 OK - przeliczony wariant bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  427. <xsl:attribute name="best_variant" select="$best_variant"/>
  428. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  429. <xsl:variable name="cand_to_calc_best">
  430. <xsl:for-each select="$candidates/bp:Path_Point">
  431. <xsl:sort select="@distance"/>
  432. <bp:Path_Point>
  433. <!--<xsl:attribute name="bit" select="$bit"/>-->
  434. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  435. <xsl:copy-of select="@*"/>
  436. <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
  437. </bp:Path_Point>
  438. </xsl:for-each>
  439. </xsl:variable>
  440. <xsl:variable name="show_cables">
  441. <xsl:call-template name="calc_cost_way">
  442. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  443. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  444. <xsl:with-param name="show_cables" select="1"/>
  445. </xsl:call-template>
  446. </xsl:variable>
  447. <xsl:for-each select="$candidates/bp:Path_Point">
  448. <xsl:sort select="@distance"/>
  449. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  450. <bp:Path_Point>
  451. <xsl:attribute name="bit" select="$best_variant"/>
  452. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  453. <xsl:copy-of select="@*"/>
  454. <xsl:attribute name="Price" select="$best_cost"/>
  455. <xsl:copy-of select="bp:Path_Point"/>
  456. </bp:Path_Point>
  457. </xsl:if>
  458. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  459. <bp:Path_Point_Cable>
  460. <xsl:attribute name="bit" select="$best_variant"/>
  461. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  462. <xsl:copy-of select="@*"/>
  463. <xsl:attribute name="Price" select="$best_cost"/>
  464. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  465. <!-- todo do jakiego Join zostal przybity -->
  466. <xsl:copy-of select="bp:Path_Point"/>
  467. <!--<xsl:if test="$debug">
  468. <debug_show_cables>
  469. <xsl:copy-of select="$show_cables"></xsl:copy-of>
  470. </debug_show_cables>
  471. </xsl:if>-->
  472. </bp:Path_Point_Cable>
  473. </xsl:if>
  474. </xsl:for-each>
  475. </koniec_wariantow>
  476. </xsl:when>
  477. <xsl:otherwise>
  478. <xsl:call-template name="calculate_optimum">
  479. <xsl:with-param name="candidates" select="$candidates"/>
  480. <xsl:with-param name="max_bit" select="$max_bit"/>
  481. <xsl:with-param name="variant" select="$variant + 1"/>
  482. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  483. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  484. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  485. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  486. </xsl:call-template>
  487. </xsl:otherwise>
  488. </xsl:choose>
  489. </xsl:template>
  490. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  491. <xsl:param name="cand_to_calc" required="yes"/>
  492. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  493. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  494. <xsl:variable name="candidates_merged_with_poprzednie">
  495. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  496. <bp:Path_Point>
  497. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  498. <xsl:copy-of select="@*"/>
  499. </bp:Path_Point>
  500. </xsl:for-each>
  501. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  502. <bp:Path_Point>
  503. <xsl:copy-of select="@*"/>
  504. </bp:Path_Point>
  505. </xsl:for-each>
  506. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  507. </xsl:variable>
  508. <xsl:if test="$debug">
  509. <candidates_merged_with_poprzednie>
  510. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  511. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  512. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  513. </candidates_merged_with_poprzednie>
  514. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  515. </xsl:if>
  516. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  517. <xsl:choose>
  518. <xsl:when test="@poprzednia_grupa">
  519. <cost>
  520. <xsl:attribute name="Cable_Price" select="0"/>
  521. <xsl:attribute name="PE_Price" select="0"/>
  522. <xsl:attribute name="Price" select="0"/>
  523. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  524. </cost>
  525. </xsl:when>
  526. <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
  527. <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_Join))"/>
  528. <xsl:variable name="way_up_len" >
  529. <xsl:choose>
  530. <xsl:when test="$way_up_id">
  531. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/></xsl:when>
  532. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  533. </xsl:choose>
  534. </xsl:variable>
  535. <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_Join)) " />
  536. <xsl:variable name="way_dn_len">
  537. <xsl:choose>
  538. <xsl:when test="$way_dn_id">
  539. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/@distance"/>
  540. </xsl:when>
  541. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  542. </xsl:choose>
  543. </xsl:variable>
  544. <xsl:choose><!-- czy w gore czy w dol -->
  545. <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') -->
  546. <cost>
  547. <xsl:variable name="Cable_Price_sum">
  548. <xsl:choose>
  549. <xsl:when test="number(@point_count) &gt; 0 ">
  550. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  551. </xsl:when>
  552. <xsl:otherwise>
  553. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  554. </xsl:otherwise>
  555. </xsl:choose>
  556. </xsl:variable>
  557. <!-- todo @point_count -->
  558. <xsl:if test="$show_cables">
  559. <xsl:attribute name="choosed" select="'down'"/>
  560. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  561. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  562. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  563. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  564. <xsl:attribute name="PE_Price" select="0"/>
  565. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  566. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  567. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  568. </xsl:if>
  569. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  570. </cost>
  571. </xsl:when>
  572. <xsl:otherwise>
  573. <cost>
  574. <xsl:variable name="Cable_Price_sum">
  575. <xsl:choose>
  576. <xsl:when test="number(@point_count) &gt; 0 ">
  577. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  578. </xsl:when>
  579. <xsl:otherwise>
  580. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  581. </xsl:otherwise>
  582. </xsl:choose>
  583. </xsl:variable>
  584. <xsl:if test="$show_cables">
  585. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  586. <xsl:attribute name="PE_Price" select="0"/>
  587. <xsl:attribute name="choosed" select="'up'"/>
  588. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  589. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  590. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  591. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  592. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  593. </xsl:if>
  594. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  595. </cost>
  596. </xsl:otherwise>
  597. </xsl:choose>
  598. </xsl:when>
  599. <xsl:otherwise>
  600. <cost>
  601. <xsl:attribute name="Cable_Price" select="0"/>
  602. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  603. <xsl:attribute name="Price" select="$PE_Price"/>
  604. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  605. </cost>
  606. </xsl:otherwise>
  607. </xsl:choose>
  608. </xsl:for-each>
  609. </xsl:template>
  610. </xsl:stylesheet>