edge_paths_with_PE_controll.xsl 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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="8"/> <!-- 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" select="1"/>
  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. <xsl:param name="edge_paths_with_PE_controll_paths_temp" select="'edge_paths_with_PE_controll_paths_temp'"/> <!-- do przechowywania calych sciezek do PathCrossed-->
  20. <xsl:param name="edge_joins_filled_paths" select="'edge_joins_filled_paths'"/>
  21. <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
  22. <xsl:template match="edge_joins_filled_paths_xml"><!-- w przypadku wyzwolenia dla pojedynczego pliku -->
  23. <xsl:message>Running script for params:
  24. PE_Price=<xsl:value-of select="$PE_Price"/>
  25. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  26. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  27. logic=<xsl:value-of select="$logic"/> .EOF
  28. </xsl:message>
  29. <edge_paths_with_PE_controll>
  30. <xsl:attribute name="logic" select="$logic"/>
  31. <!-- <xsl:attribute name="id" select="@id"/>
  32. <xsl:attribute name="len" select="@len"/>
  33. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>-->
  34. <xsl:apply-templates mode="PointMatrixGroup">
  35. <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()-->
  36. </xsl:apply-templates>
  37. </edge_paths_with_PE_controll>
  38. </xsl:template>
  39. <xsl:template match="edge_joins_filled_paths">
  40. <xsl:message>Running script for params:
  41. PE_Price=<xsl:value-of select="$PE_Price"/>
  42. Cable_Price=<xsl:value-of select="$Cable_Price"/>
  43. max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>
  44. logic=<xsl:value-of select="$logic"/> .EOF
  45. </xsl:message>
  46. <xsl:variable name="edge_joins_filled_paths_len">
  47. <xsl:for-each select="item">
  48. <xsl:sort select="number(asText/@len)" order="descending"/>
  49. <Path>
  50. <xsl:attribute name="id" select="@id"/>
  51. <xsl:attribute name="len" select="asText/@len"/>
  52. <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
  53. </Path>
  54. </xsl:for-each>
  55. </xsl:variable>
  56. <edge_paths_with_PE_controll>
  57. <xsl:attribute name="logic" select="$logic"/>
  58. <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
  59. </edge_paths_with_PE_controll>
  60. <!--<xsl:result-document href="edge_paths_with_PE.xml">
  61. <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
  62. </xsl:result-document>-->
  63. </xsl:template>
  64. <xsl:template match="Path|asText_XMl" mode="PointMatrixGroup">
  65. <xsl:param name="edge_joins_filled_path" select=" doc(concat($edge_joins_filled_paths,'/edge_joins_filled_paths.',@id,'.xml'))"/>
  66. <Path>
  67. <xsl:attribute name="id" select="@id"/>
  68. <xsl:variable name="ID_Way" select="@id"/>
  69. <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
  70. <xsl:variable name="Points_cnt" select="@Points_cnt"/>
  71. <xsl:attribute name="len" select="@len"/>
  72. <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
  73. <xsl:variable name="len" select="@len"/>
  74. <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)"/>
  75. Points_cnt=<xsl:value-of select="@Points_cnt"/>
  76. </xsl:message>
  77. <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
  78. <EdgeWayJoinsPair>
  79. <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
  80. </EdgeWayJoinsPair>
  81. <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
  82. <!-- sciagamy dane drog, z ktorymi sie przecinamy -->
  83. <xsl:variable name="PathsCrossed">
  84. <PathsCrossed>
  85. <xsl:for-each-group select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString/Ways" group-by="@ID_WAY">
  86. <Ways>
  87. <xsl:variable name="ID_WAY_joining" select="@ID_WAY"/>
  88. <xsl:attribute name="ID_WAY" select="$ID_WAY_joining"/>
  89. <xsl:variable name="ways_id_joining" select="@ways_id"/>
  90. <xsl:attribute name="ways_id_joining" select="$ways_id_joining"/>
  91. <xsl:variable name="ID_Join_joining" select="parent::node()/@ID_Join"/>
  92. <xsl:attribute name="ID_Join_joining" select="$ID_Join_joining"/>
  93. <xsl:choose>
  94. <xsl:when test="doc-available(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))">
  95. <xsl:variable name="Neigh_controll">
  96. <xsl:copy-of select="doc(concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml'))"/>
  97. </xsl:variable>
  98. <!-- wykryc gdzie sie lacza i jakie sa odleglosci prawdziwe -->
  99. <!-- jak nasza droga sie laczy do przeciwnej? ktory nasz Way w nim siedzi -->
  100. <!-- zignorowac wezel zwiazany z podlaczonym tam joinem -->
  101. <!-- <IgnoreLocaldistance>
  102. <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
  103. </IgnoreLocaldistance>
  104. <IgnoreLocaldistance>
  105. <xsl:attribute name="ID_Join" select="$ID_Join_joining"/>
  106. </IgnoreLocaldistance>-->
  107. <!--<xsl:for-each select="$Neigh_controll/edge_paths_with_PE_controll/Path/PointMatrixGroupPE/PointMatrixGroup/odpalam_liczenie/(bp:Path_Point|bp:Path_Point_Cable)">
  108. <xsl:copy-of select="."/>
  109. </xsl:for-each>-->
  110. <xsl:apply-templates mode="PathsCrossed" select="$Neigh_controll"/>
  111. </xsl:when>
  112. <xsl:otherwise>
  113. <xsl:message> WARNING path should be analyzed and aviable in:<xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></xsl:message>
  114. <Warning> WARNING path should be analyzed and aviable in: <xsl:value-of select="concat($edge_paths_with_PE_controll_paths_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/> , because logest first than shortest: for : <xsl:value-of select="concat($edge_paths_with_PE_controll_temp,'/','edge_paths_with_PE_controll.xsl.',@ID_WAY,'.xml')"/></Warning>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. </Ways>
  118. </xsl:for-each-group>
  119. </PathsCrossed>
  120. </xsl:variable>
  121. <xsl:copy-of select="$PathsCrossed"/>
  122. <!-- rozmieszczamy prawidlowo PE na danej trasie -->
  123. <xsl:variable name="EconomicDistanceCut">
  124. <EconomicDistanceCut>
  125. <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[not(@error)]">
  126. <distance>
  127. <xsl:attribute name="pos" select="position()"/>
  128. <xsl:attribute name="not_id" select="@not_id"/>
  129. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  130. <xsl:attribute name="len" select="@len"/>
  131. <xsl:attribute name="id_path" select="@id_path"/>
  132. <xsl:variable name="Points" select="count(Points)"/>
  133. <xsl:attribute name="Points" select="$Points"/>
  134. <xsl:variable name="Ways" select="count(Ways)"/>
  135. <xsl:attribute name="Ways_count" select="$Ways"/>
  136. <xsl:choose>
  137. <xsl:when test="$Ways or $Points">
  138. <xsl:attribute name="point_count" select="$Points + $Ways"/>
  139. <!--<xsl:attribute name="NotPoints" select="0"/>--><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  140. <xsl:if test="Ways">
  141. <!-- sprawdzamy jak sie dowiazuje i ile ma do najblizszego wezla -->
  142. <xsl:for-each-group select="Ways" group-by="@ID_WAY">
  143. <PathsCrossed>
  144. <xsl:attribute name="ID_WAY" select="@ID_WAY"/><xsl:attribute name="debug" select="'created at #163 by parsing Ways'"/>
  145. <xsl:variable name="Joining_ID_Join_from" select="parent::node()/@ID_Join"/>
  146. <xsl:choose>
  147. <xsl:when test="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos">
  148. <xsl:variable name="NeighJoin_pos" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@ID_Join= $Joining_ID_Join_from]/@pos"/>
  149. <xsl:variable name="NeighJoin_pos_distance" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[@pos= $NeighJoin_pos]/@distance)"/>
  150. <xsl:attribute name="NeighJoin_pos" select="$NeighJoin_pos"/>
  151. <!--<xsl:attribute name="NeighJoin_pos_distance" select="$NeighJoin_pos_distance"/>-->
  152. <xsl:attribute name="Deb_Cur_ID_WAY" select="@ID_WAY"/>
  153. <xsl:attribute name="Joining_ID_Join_from" select="$Joining_ID_Join_from"/>
  154. <!-- chk w gore -->
  155. <xsl:variable name="NeighJoin_way_up_pos" select="max($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos) &lt; number($NeighJoin_pos) ] /@pos)"/>
  156. <xsl:choose>
  157. <xsl:when test="$NeighJoin_way_up_pos">
  158. <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
  159. <xsl:variable name="NeighJoin_way_up_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@ID_Join" />
  160. <xsl:variable name="NeighJoin_way_up_len" select="number($NeighJoin_pos_distance) - number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_up_pos] /@distance) "/>
  161. <xsl:attribute name="NeighJoin_way_up_len" select="$NeighJoin_way_up_len"/>
  162. <xsl:attribute name="NeighJoin_way_up_pos" select="$NeighJoin_way_up_pos"/>
  163. <xsl:attribute name="NeighJoin_way_up_ID_Join" select="$NeighJoin_way_up_ID_Join"/>
  164. </xsl:when>
  165. <xsl:otherwise>
  166. <xsl:attribute name="NeighJoin_way_up_len" select="-1"/>
  167. </xsl:otherwise>
  168. </xsl:choose>
  169. <xsl:variable name="NeighJoin_way_dn_pos" select="min($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ number(@pos) &gt; number($NeighJoin_pos) ] /@pos)"/>
  170. <xsl:choose>
  171. <xsl:when test="$NeighJoin_way_dn_pos">
  172. <xsl:variable name="NeighJoin_way_dn_ID_Join" select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@ID_Join"/>
  173. <xsl:variable name="NeighJoin_way_dn_len" select="number($PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]/(bp:Path_Point)[ @pos=$NeighJoin_way_dn_pos] /@distance) - number($NeighJoin_pos_distance) "/>
  174. <xsl:attribute name="NeighJoin_way_dn_pos" select="$NeighJoin_way_dn_pos"/>
  175. <xsl:attribute name="NeighJoin_way_dn_ID_Join" select="$NeighJoin_way_dn_ID_Join"/>
  176. <xsl:attribute name="NeighJoin_way_dn_len" select="$NeighJoin_way_dn_len"/>
  177. </xsl:when>
  178. <xsl:otherwise>
  179. <xsl:attribute name="NeighJoin_way_dn_len" select="-1"/>
  180. </xsl:otherwise>
  181. </xsl:choose>
  182. <!-- chk w dol -->
  183. <xsl:if test=" number($debug) &gt; 3">
  184. <debug186>
  185. <xsl:copy-of select="$PathsCrossed/PathsCrossed/Ways[@ID_WAY= current()/@ID_WAY]"/>
  186. </debug186>
  187. </xsl:if>
  188. </xsl:when>
  189. <xsl:otherwise>
  190. <xsl:comment>No connection to other roads found</xsl:comment>
  191. </xsl:otherwise>
  192. </xsl:choose>
  193. </PathsCrossed>
  194. </xsl:for-each-group>
  195. </xsl:if>
  196. </xsl:when>
  197. <xsl:otherwise><xsl:attribute name="NotPoints" select="1"/>
  198. <xsl:attribute name="point_count" select="0"/>
  199. </xsl:otherwise><!-- do Grupowanai potrzebne aby nie liczyc tych w count -->
  200. </xsl:choose>
  201. </distance>
  202. </xsl:for-each>
  203. </EconomicDistanceCut>
  204. </xsl:variable>
  205. <xsl:if test="$debug">
  206. <debug_174>
  207. <xsl:copy-of select="$EconomicDistanceCut"/>
  208. </debug_174>
  209. </xsl:if>
  210. <xsl:variable name="EconomicDistanceCut2">
  211. <EconomicDistanceCut2>
  212. <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
  213. <distance2>
  214. <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )&lt; number(current()/@pos )]/@len)"/>
  215. <xsl:copy-of select="@ID_Join"/>
  216. <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
  217. <xsl:choose>
  218. <xsl:when test="number(@point_count)&gt;0">
  219. <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
  220. number(@pos )&lt; number(current()/@pos ) and number(@point_count)&gt;0
  221. ]/@pos)"/>
  222. <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
  223. <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
  224. number(@pos )&lt; number(current()/@pos )
  225. and number(@pos) &gt;= number($max_pos_z_pkt)
  226. ]/@len)"/>
  227. <xsl:attribute name="disttopkt" select="$disttopkt" />
  228. <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * number(@point_count)"/>
  229. <xsl:attribute name="cost_dist" select="$cost_dist"/>
  230. <xsl:attribute name="point_count" select="@point_count"/>
  231. <xsl:attribute name="Ways_count" select="@Ways_count"/>
  232. <xsl:choose> <!-- to powinno przeciac grupe ale moze nie? -->
  233. <xsl:when test="$cost_dist &gt; $PE_Price">
  234. <xsl:attribute name="cut_by_pe" select="1"/>
  235. </xsl:when>
  236. <xsl:otherwise><xsl:attribute name="cut_by_pe" select="0"/></xsl:otherwise>
  237. </xsl:choose>
  238. <xsl:attribute name="not_id" select="@not_id"/> <!-- to jest z ID way - way ma 2 pointsy! -->
  239. </xsl:when>
  240. <xsl:otherwise>
  241. <xsl:choose>
  242. <xsl:when test="number(@Ways_count)&gt;0">
  243. <xsl:attribute name="point_count" select="@Ways_count"/>
  244. </xsl:when>
  245. <xsl:otherwise><xsl:attribute name="point_count" select="0"/></xsl:otherwise>
  246. </xsl:choose>
  247. </xsl:otherwise>
  248. </xsl:choose>
  249. <xsl:attribute name="id_path" select="@id_path"/>
  250. <xsl:copy-of select="@point_count"/>
  251. <xsl:copy-of select="@pos"/><!-- position() -->
  252. <xsl:copy-of select="@len"/>
  253. <xsl:copy-of select="@ForceCutByPrice"/>
  254. <xsl:copy-of select="PathsCrossed"/>
  255. <!--<xsl:copy-of select="@NotPoints"/>--><!--debug -->
  256. </distance2>
  257. </xsl:for-each>
  258. </EconomicDistanceCut2>
  259. </xsl:variable>
  260. <debug_Cut2_183>
  261. <xsl:copy-of select="$EconomicDistanceCut2"/>
  262. </debug_Cut2_183>
  263. <!-- narzucenie max ilosci grup oraz wyliczenie ile jest -->
  264. <!--<xsl:variable name="$max_combinate_groups_elements"/>-->
  265. <xsl:variable name="max_combinate_groups_elements_for_group">
  266. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/>
  267. <xsl:variable name="cost_dist_Cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ ( number(@cost_dist) &gt; number($PE_Price) ) or number(@len) &gt; ( number($PE_Price) div number($Cable_Price) ) ])"/>
  268. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt ) + 1"/>
  269. <xsl:choose>
  270. <xsl:when test="number($bit_max) &lt; number(15) "> <!-- do przyjecia przez procesor kombinacji-->
  271. <xsl:message>#296 max_combinate_groups_elements_for_group number($bit_max=<xsl:value-of select="$bit_max"/>) &lt; number(15)</xsl:message>
  272. <xsl:choose>
  273. <xsl:when test="number($elements_cnt) &gt; 25">
  274. <xsl:message>#297 narzucam fixed liczbe 40 z uwagi na $bit_max=<xsl:value-of select="$bit_max"/> &lt; 15 ilosc max = $elements_cnt=<xsl:value-of select="$elements_cnt"/>; </xsl:message>
  275. <xsl:value-of select="25"/>
  276. </xsl:when>
  277. <xsl:otherwise>
  278. <xsl:message>#302 max_combinate_groups_elements_for_group setting to current count - number($elements_cnt=<xsl:value-of select="$elements_cnt"/>); </xsl:message>
  279. <xsl:value-of select="number($elements_cnt)"/>
  280. </xsl:otherwise>
  281. </xsl:choose>
  282. </xsl:when>
  283. <xsl:otherwise>
  284. <xsl:message>#309 max_combinate_groups_elements_for_group otherwise setting to default $max_combinate_groups_elements=<xsl:value-of select="$max_combinate_groups_elements"/>; </xsl:message>
  285. <xsl:value-of select="$max_combinate_groups_elements"/>
  286. </xsl:otherwise>
  287. </xsl:choose>
  288. </xsl:variable>
  289. <xsl:variable name="EconomicDistanceCut2">
  290. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  291. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  292. <distance2>
  293. <xsl:copy-of select="@*"/>
  294. <xsl:choose>
  295. <xsl:when test=" position() mod $max_combinate_groups_elements_for_group = 0"> <!--- minus puste sum($EconomicDistanceCut/EconomicDistanceCut/distance[ number(@pos) &lt; number(current()/@pos) ]/number(@NotPoints)) ) --><!-- nabija grupe do przeliczenia-->
  296. <xsl:attribute name="PosCut3Flag" select="1"/>
  297. </xsl:when>
  298. <xsl:otherwise>
  299. <xsl:attribute name="PosCut3Flag" select="0"/>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. <xsl:copy-of select="PathsCrossed"/>
  303. </distance2>
  304. </xsl:for-each>
  305. </EconomicDistanceCut2>
  306. </xsl:variable>
  307. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  308. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  309. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  310. <distance2>
  311. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  312. <xsl:copy-of select="@*"/>
  313. <xsl:copy-of select="PathsCrossed"/>
  314. </distance2>
  315. </xsl:for-each>
  316. </EconomicDistanceCut2>
  317. </xsl:variable>
  318. <!-- debug -->
  319. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  320. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  321. <distance2>
  322. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  323. <xsl:copy-of select="@PosCut3GrId"/>
  324. <xsl:copy-of select="@CurSumNotPoints"/>
  325. <xsl:copy-of select="@NotPoints"/>
  326. <!-\-<xsl:copy-of select="@pos"/>-\->
  327. </distance2>
  328. </xsl:for-each>
  329. </EconomicDistanceCut2>-->
  330. <!-- debug -->
  331. <!--<debug>
  332. <xsl:copy-of select="$EconomicDistanceCut2"/>
  333. </debug>-->
  334. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/><!-- liczba wezlow potencjalnych licbza PE-->
  335. <xsl:variable name="cost_dist_Cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ ( number(@cost_dist) &gt; number($PE_Price) ) or number(@len) &gt; ( number($PE_Price) div number($Cable_Price) ) ])"/>
  336. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt )"/>
  337. <!-- max licbza PE-->
  338. <xsl:message>#341Calc $cost_dist_Cnt=<xsl:value-of select="$cost_dist_Cnt"/>; $elements_cnt=<xsl:value-of select="$elements_cnt"/>; $bit_max=<xsl:value-of select="$bit_max"/> ; </xsl:message>
  339. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  340. <xsl:variable name="PointMatrixGroup">
  341. <PointMatrixGroup>
  342. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  343. <PointMatrixGroupPos>
  344. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  345. <xsl:variable name="countGr" select="count(current-group())"/>
  346. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/number(@disttopkt) ) div ( number($PE_Price) div number($Cable_Price) ) )"/>
  347. <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))"/>
  348. </xsl:message>
  349. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  350. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  351. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  352. <xsl:attribute name="id_path" select="@id_path"/>
  353. <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 -->
  354. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  355. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  356. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  357. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  358. <xsl:attribute name="countGr" select="$countGr"/>
  359. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  360. <xsl:for-each select="current-group()">
  361. <distance2>
  362. <xsl:attribute name="PosMatrGroup" select="position()"/>
  363. <xsl:copy-of select="@*"></xsl:copy-of>
  364. <xsl:copy-of select="PathsCrossed"/>
  365. </distance2>
  366. </xsl:for-each>
  367. </PointMatrixGroupPos>
  368. </xsl:for-each-group>
  369. </PointMatrixGroup>
  370. </xsl:variable>
  371. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  372. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  373. -->
  374. <!-- debug -->
  375. <xsl:if test="number($debug) &gt; 3">
  376. <debug_356>
  377. <xsl:copy-of select="$PointMatrixGroup"/>
  378. </debug_356>
  379. </xsl:if>
  380. <PointMatrixGroupPE>
  381. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  382. <xsl:for-each select="PointMatrixGroupPos">
  383. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  384. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  385. <xsl:variable name="distanceGr" select="@distanceGr"/>
  386. <PointMatrixGroup>
  387. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  388. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  389. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  390. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  391. <xsl:attribute name="len_sum" select="@len_sum"/>
  392. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  393. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  394. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  395. <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"/>;
  396. </xsl:message>
  397. <!-- ida kandydaci -->
  398. <xsl:variable name="candidates">
  399. <xsl:for-each select="distance2[ @point_count &gt;0 ]"> <!--@point_count &gt;0--> <!-- ( $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' ) --> <!--( 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 -->
  400. <!--<xsl:sort select="@cost_dist" order="descending"/>-->
  401. <bp:Path_Point>
  402. <xsl:copy-of select="@ID_Join"/>
  403. <xsl:attribute name="DebugPosPoint" select="position()"/>
  404. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  405. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  406. <xsl:attribute name="pos" select="@pos"/>
  407. <xsl:attribute name="len" select="@len"/>
  408. <xsl:attribute name="distance" select="@distance"/>
  409. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  410. <xsl:attribute name="id_path" select="@id_path"/>
  411. <xsl:attribute name="point_count" select="@point_count"/>
  412. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  413. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  414. <xsl:copy-of select="PathsCrossed"/>
  415. </bp:Path_Point>
  416. </xsl:for-each>
  417. </xsl:variable>
  418. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  419. $last = A
  420. - najprosciej przez pliki oszukujac silnik xsl
  421. - tozsamowsci $ID_Way $distanceGr
  422. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  423. -->
  424. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  425. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  426. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  427. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  428. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  429. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  430. </xsl:if>
  431. </xsl:variable>
  432. <!--<poprzednie_odpalam_liczenie_or_nie>
  433. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  434. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  435. </poprzednie_odpalam_liczenie_or_nie>-->
  436. <xsl:variable name="odpalam_liczenie_or_nie">
  437. <xsl:choose>
  438. <xsl:when test="1=1"> <!-- bylo count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1-->
  439. <odpalam_liczenie>
  440. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  441. <!--<disabled>temporary blad after #410 OK - przeliczony wariant bit=000000010000 ( nr 4095;)
  442. [xslt] #239: calc @distanceGr=23; @point_count_Pos=19;@LineStringCount ; @len_sum=177; @distanceBeg=5055; @distanceEnd=5475;
  443. [xslt]
  444. [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: ""
  445. [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>-->
  446. <xsl:variable name="IfPathsCrossed" >
  447. <xsl:choose>
  448. <xsl:when test="$candidates/bp:Path_Point/PathsCrossed[@NeighJoin_way_up_ID_Join or @NeighJoin_way_dn_ID_Join]">
  449. <xsl:message>#534 there are PathsCrossed - allow to decrease -1</xsl:message>
  450. <xsl:value-of select="0"/>
  451. </xsl:when>
  452. <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
  453. </xsl:choose>
  454. </xsl:variable>
  455. <xsl:variable name="max_possible_bit"><!-- produkuje 11111111 -->
  456. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  457. </xsl:variable>
  458. <xsl:call-template name="calculate_optimum">
  459. <xsl:with-param name="candidates" select="$candidates"/>
  460. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  461. <xsl:with-param name="max_bit" select="$bit_max_Pos"/>
  462. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  463. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  464. <xsl:with-param name="variant" select="$IfPathsCrossed"/>
  465. </xsl:call-template>
  466. </odpalam_liczenie>
  467. </xsl:when>
  468. <xsl:otherwise>
  469. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  470. <xsl:for-each select="$candidates/bp:Path_Point">
  471. <bp:Path_Point>
  472. <xsl:copy-of select="@*"/>
  473. <xsl:attribute name="bin_pos" select="1"/>
  474. </bp:Path_Point>
  475. </xsl:for-each>
  476. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  477. </xsl:otherwise>
  478. </xsl:choose>
  479. </xsl:variable>
  480. <xsl:if test="number($debug) &gt; 0">
  481. <debug423>
  482. <xsl:attribute name="liczenie_dla"/>
  483. <candidates>
  484. <xsl:copy-of select="$candidates"/>
  485. </candidates>
  486. <poprzednie_odpalam_liczenie_or_nie>
  487. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  488. </poprzednie_odpalam_liczenie_or_nie>
  489. </debug423>
  490. </xsl:if>
  491. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  492. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  493. <poprzednie_odpalam_liczenie_or_nie>
  494. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  495. <xsl:if test="position() = last()">
  496. <xsl:copy-of select="."/>
  497. </xsl:if>
  498. </xsl:for-each>
  499. <nizej_zwykly></nizej_zwykly>
  500. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  501. <xsl:if test="position() = last()">
  502. <xsl:copy-of select="."/>
  503. </xsl:if>
  504. </xsl:for-each>
  505. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  506. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  507. </poprzednie_odpalam_liczenie_or_nie>
  508. </xsl:result-document>
  509. </PointMatrixGroup>
  510. </xsl:for-each>
  511. </xsl:for-each>
  512. </PointMatrixGroupPE>
  513. <!--<PointMatrix>
  514. <xsl:attribute name="bit_max" select="$bit_max"/>
  515. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  516. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  517. <!-\-<xsl:call-template name="PE_wariant">
  518. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  519. <xsl:with-param name="bit_max" select="$bit_max"/>
  520. </xsl:call-template>-\->
  521. </PointMatrix>-->
  522. </Path>
  523. </xsl:template>
  524. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  525. <xsl:apply-templates mode="PathsCrossed"/>
  526. </xsl:template>
  527. <xsl:template match="bp:Path_Point" mode="PathsCrossed"> <!-- nie potrzebujemy kabli ! bp:Path_Point_Cable-->
  528. <xsl:copy-of select="."/>
  529. </xsl:template>
  530. <xsl:template match="*|text()" mode="PathsCrossed"/>
  531. <xsl:template name="calculate_optimum">
  532. <xsl:param name="candidates" required="yes"/>
  533. <xsl:param name="elements_cnt" required="yes"/>
  534. <xsl:param name="variant" select="1"/>
  535. <xsl:param name="max_bit" required="yes"/>
  536. <xsl:param name="max_possible_bit" required="yes"/>
  537. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  538. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  539. <!-- do jednorazowego wyzwolenia przez fukcje, aby tylko raz odjelo wariant zerowy -->
  540. <!-- znajduje kolejny korzystny wariant bit -->
  541. <xsl:variable name="variant">
  542. <xsl:choose>
  543. <xsl:when test="number($max_bit) &gt;= number($elements_cnt)">
  544. <xsl:message>#576 $max_bit <xsl:value-of select="$max_bit"/> &gt;$elements_cnt=<xsl:value-of select="$elements_cnt"/>; in $variant=<xsl:value-of select="$variant"/>;</xsl:message>
  545. <xsl:value-of select="$variant"/>
  546. </xsl:when>
  547. <xsl:when test="number($max_bit) &gt; 0">
  548. <xsl:message>#80 try to find next $max_bit <xsl:value-of select="$max_bit"/> &gt;$elements_cnt=<xsl:value-of select="$elements_cnt"/>; in $variant=<xsl:value-of select="$variant"/>;</xsl:message>
  549. <xsl:variable name="variant_found" select="bp:next_bit_max($variant,$max_bit,$elements_cnt,0)"/>
  550. <xsl:value-of select="$variant_found"/>
  551. <xsl:message>... $variant_found <xsl:value-of select="$variant_found"/>;</xsl:message>
  552. </xsl:when>
  553. <xsl:otherwise>
  554. <xsl:value-of select="$variant"/>
  555. </xsl:otherwise>
  556. </xsl:choose>
  557. </xsl:variable>
  558. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  559. <xsl:variable name="cand_to_calc">
  560. <xsl:for-each select="$candidates/bp:Path_Point">
  561. <!--<xsl:sort select="number(@distance)"/>-->
  562. <bp:Path_Point>
  563. <!--<xsl:attribute name="bit" select="$bit"/>-->
  564. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  565. <xsl:copy-of select="@*"/>
  566. <!--<xsl:copy-of select="bp:Path_Point"/>-->
  567. <xsl:copy-of select="PathsCrossed"/>
  568. </bp:Path_Point>
  569. </xsl:for-each>
  570. </xsl:variable>
  571. <!-- debug -->
  572. <xsl:if test=" number($debug) &gt; 2">
  573. <variant><xsl:attribute name="variant" select="$variant"/>
  574. <xsl:attribute name="cur_bit" select="$bit"/>
  575. <xsl:attribute name="best_cost" select="$best_cost"/>
  576. <xsl:attribute name="best_variant" select="$best_variant"/>
  577. <xsl:copy-of select="$cand_to_calc"/>
  578. </variant>
  579. </xsl:if>
  580. <xsl:variable name="calc_cost_way">
  581. <xsl:call-template name="calc_cost_way">
  582. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  583. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  584. </xsl:call-template>
  585. </xsl:variable>
  586. <xsl:variable name="cost_sum">
  587. <costs>
  588. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  589. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  590. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  591. <xsl:copy-of select="$calc_cost_way"/>
  592. </costs>
  593. </xsl:variable>
  594. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  595. <xsl:variable name="best">
  596. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  597. <xsl:choose>
  598. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  599. <best>
  600. <xsl:attribute name="best_cost" select="$cur_Price"/>
  601. <xsl:attribute name="best_variant" select="$bit"/>
  602. </best>
  603. </xsl:when>
  604. <xsl:otherwise>
  605. <best>
  606. <xsl:attribute name="best_cost" select="$best_cost"/>
  607. <xsl:attribute name="best_variant" select="$best_variant"/>
  608. </best>
  609. </xsl:otherwise>
  610. </xsl:choose>
  611. </xsl:variable>
  612. <xsl:if test=" number($debug) &gt; 3 ">
  613. <xsl:copy-of select="$best"/>
  614. <xsl:message>#688 (C$<xsl:value-of select="$cost_sum/costs/@Cable_Price"/>+P$<xsl:value-of select="$cost_sum/costs/@PE_Price"/> =<xsl:value-of select="$cost_sum/costs/@Price"/>) v:<xsl:value-of select="$variant"/>; b:<xsl:value-of select="$bit"/>; bestV=<xsl:value-of select="$best_variant"/>; bestC=<xsl:value-of select="$best_cost"/> </xsl:message>
  615. </xsl:if>
  616. <xsl:choose>
  617. <xsl:when test="$bit = $max_possible_bit">
  618. <koniec_wariantow>
  619. <xsl:message>#410 OK - cost:<xsl:value-of select="$best_cost"/>; bit=<xsl:value-of select="$best_variant"/> ( nr <xsl:value-of select="$variant"/>;) </xsl:message>
  620. <xsl:attribute name="best_variant" select="$best_variant"/>
  621. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  622. <xsl:variable name="cand_to_calc_best">
  623. <xsl:for-each select="$candidates/bp:Path_Point">
  624. <!--<xsl:sort select="@distance"/>-->
  625. <bp:Path_Point>
  626. <!--<xsl:attribute name="bit" select="$bit"/>-->
  627. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  628. <xsl:copy-of select="@*"/>
  629. <xsl:copy-of select="bp:Path_Point"/>
  630. </bp:Path_Point>
  631. </xsl:for-each>
  632. </xsl:variable>
  633. <xsl:variable name="show_cables">
  634. <xsl:call-template name="calc_cost_way">
  635. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  636. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  637. <xsl:with-param name="show_cables" select="1"/>
  638. </xsl:call-template>
  639. </xsl:variable>
  640. <xsl:for-each select="$candidates/bp:Path_Point">
  641. <!--<xsl:sort select="number(@distance)"/>-->
  642. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  643. <bp:Path_Point>
  644. <xsl:attribute name="bit" select="$best_variant"/>
  645. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  646. <xsl:copy-of select="@*"/>
  647. <xsl:attribute name="Price" select="$best_cost"/>
  648. <xsl:copy-of select="bp:Path_Point"/>
  649. </bp:Path_Point>
  650. </xsl:if>
  651. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  652. <bp:Path_Point_Cable>
  653. <xsl:attribute name="bit" select="$best_variant"/>
  654. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  655. <xsl:copy-of select="@*"/>
  656. <xsl:attribute name="Price" select="$best_cost"/>
  657. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  658. <!-- todo do jakiego Join zostal przybity -->
  659. <xsl:copy-of select="bp:Path_Point"/>
  660. <!-- <xsl:if test="$debug">-->
  661. <debug_show_cables>
  662. <xsl:copy-of select="$show_cables/cost[@ID_Join= current()/@ID_Join]"/>
  663. </debug_show_cables>
  664. <!--</xsl:if>-->
  665. </bp:Path_Point_Cable>
  666. </xsl:if>
  667. </xsl:for-each>
  668. </koniec_wariantow>
  669. </xsl:when>
  670. <xsl:otherwise>
  671. <!--<xsl:if test="$variant &lt; 10 ">--><!-- debug limit -->
  672. <xsl:call-template name="calculate_optimum">
  673. <xsl:with-param name="candidates" select="$candidates"/>
  674. <xsl:with-param name="max_bit" select="$max_bit"/>
  675. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  676. <xsl:with-param name="variant" select="$variant + 1"/>
  677. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  678. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  679. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  680. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  681. </xsl:call-template>
  682. <!--</xsl:if>-->
  683. </xsl:otherwise>
  684. </xsl:choose>
  685. </xsl:template>
  686. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  687. <xsl:param name="cand_to_calc" required="yes"/>
  688. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  689. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  690. <xsl:variable name="candidates_merged_with_poprzednie">
  691. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  692. <bp:Path_Point>
  693. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  694. <xsl:copy-of select="@*"/>
  695. <xsl:attribute name="distance_Neigh" select="0"/>
  696. </bp:Path_Point>
  697. </xsl:for-each>
  698. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  699. <bp:Path_Point>
  700. <xsl:copy-of select="@*"/>
  701. <xsl:attribute name="distance_Neigh" select="0"/>
  702. </bp:Path_Point>
  703. </xsl:for-each>
  704. <!-- dorzucenie Crossed -->
  705. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  706. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  707. <xsl:variable name="PathCrossFirst" select="position() = 1"/>
  708. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  709. <!--<xsl:message>#681: PathsCrossed up $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>; @NeighJoin_way_up_len=<xsl:value-of select="@NeighJoin_way_up_len"/></xsl:message>-->
  710. <bp:Path_Point>
  711. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  712. <xsl:attribute name="bin_pos" select="1"/>
  713. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  714. <xsl:choose>
  715. <xsl:when test="$PathCrossLast">
  716. <!--<xsl:message>adding distance to local from:<xsl:value-of select="number(parent::node()/@distance)"/>; to:<xsl:value-of select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>; </xsl:message>-->
  717. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>
  718. </xsl:when>
  719. <xsl:when test="$PathCrossFirst">
  720. <!--<xsl:message>reducing distance to local:from:<xsl:value-of select="number(parent::node()/@distance)"/>; to: <xsl:value-of select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>; </xsl:message>-->
  721. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>
  722. </xsl:when>
  723. <xsl:otherwise>
  724. <xsl:message terminate="no">#720 dowiazanie Crossed w srodku grupy @NeighJoin_way_up_ID_Join=<xsl:value-of select="@NeighJoin_way_up_ID_Join"/>!</xsl:message>
  725. </xsl:otherwise>
  726. </xsl:choose>
  727. <xsl:attribute name="pos" select="-1"/>
  728. </bp:Path_Point>
  729. </xsl:for-each>
  730. </xsl:for-each>
  731. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  732. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  733. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  734. <!--<xsl:message>#681: PathsCrossed dwn $PathCrossLast=<xsl:value-of select="$PathCrossLast"/>; to up:<xsl:value-of select="@NeighJoin_way_dn_len"/>; @distance=<xsl:value-of select="@NeighJoin_way_dn_len"/>; </xsl:message>-->
  735. <bp:Path_Point>
  736. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  737. <xsl:attribute name="bin_pos" select="1"/>
  738. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  739. <xsl:choose>
  740. <xsl:when test="$PathCrossLast">
  741. <xsl:message>adding distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>; </xsl:message>
  742. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>
  743. </xsl:when>
  744. <xsl:otherwise>
  745. <xsl:message>reducing distance to local:<xsl:value-of select="number(parent::node()/@distance)"/>== <xsl:value-of select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>; </xsl:message>
  746. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>
  747. </xsl:otherwise>
  748. </xsl:choose>
  749. <xsl:attribute name="pos" select="-1"/>
  750. </bp:Path_Point>
  751. </xsl:for-each>
  752. </xsl:for-each>
  753. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  754. </xsl:variable>
  755. <xsl:if test="number($debug) &gt;1">
  756. <candidates_merged_with_poprzednie>
  757. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  758. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  759. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  760. </candidates_merged_with_poprzednie>
  761. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  762. </xsl:if>
  763. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  764. <xsl:sort select="number(@distance)"/>
  765. <!--<xsl:message>#764 test @distance=<xsl:value-of select="@distance"/>; z @bin_pos=<xsl:value-of select="@bin_pos"/>; @distance=<xsl:value-of select="@distance"/>;@id_path=<xsl:value-of select="@id_path"/> </xsl:message>-->
  766. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  767. <xsl:choose>
  768. <xsl:when test="@poprzednia_grupa">
  769. <cost>
  770. <xsl:attribute name="Cable_Price" select="0"/>
  771. <xsl:attribute name="PE_Price" select="0"/>
  772. <xsl:attribute name="Price" select="0"/>
  773. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  774. </cost>
  775. </xsl:when>
  776. <!--<xsl:when test="number(string-length(@bin_pos))=0">
  777. <xsl:message>#768 debug @bin_pos=<xsl:value-of select="@bin_pos"/>; </xsl:message>
  778. </xsl:when>-->
  779. <xsl:when test="@bin_pos='0'"><!-- szukamy gdzie ma najblizej i za ile -->
  780. <xsl:variable name="way_up_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &lt; current()/number(@distance )]/number(@ID_Join))"/>
  781. <!--<xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>-->
  782. <xsl:variable name="way_up_len" >
  783. <xsl:choose>
  784. <xsl:when test="$way_up_id">
  785. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/>
  786. </xsl:when>
  787. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  788. </xsl:choose>
  789. </xsl:variable>
  790. <xsl:variable name="way_dn_id" select="max($candidates_merged_with_poprzednie/bp:Path_Point[@bin_pos=1 and number(@distance) &gt; current()/number(@distance) ]/number(@ID_Join)) " />
  791. <!--<xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join =$way_dn_id ]/@ID_Join"/>-->
  792. <xsl:variable name="way_dn_len">
  793. <xsl:choose>
  794. <xsl:when test="$way_dn_id">
  795. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  796. </xsl:when>
  797. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  798. </xsl:choose>
  799. </xsl:variable>
  800. <xsl:choose><!-- czy w gore czy w dol -->
  801. <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') -->
  802. <cost>
  803. <xsl:variable name="Cable_Price_sum">
  804. <xsl:choose>
  805. <xsl:when test="number(@point_count) &gt; 0 ">
  806. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  807. </xsl:when>
  808. <xsl:otherwise>
  809. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  810. </xsl:otherwise>
  811. </xsl:choose>
  812. </xsl:variable>
  813. <!-- todo @point_count -->
  814. <xsl:if test="$show_cables">
  815. <xsl:attribute name="choosed" select="'down'"/>
  816. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  817. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  818. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  819. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  820. <xsl:attribute name="PE_Price" select="0"/>
  821. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  822. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  823. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  824. </xsl:if>
  825. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  826. </cost>
  827. </xsl:when>
  828. <xsl:otherwise>
  829. <cost>
  830. <xsl:variable name="Cable_Price_sum">
  831. <xsl:choose>
  832. <xsl:when test="number(@point_count) &gt; 0 ">
  833. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  834. </xsl:when>
  835. <xsl:otherwise>
  836. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  837. </xsl:otherwise>
  838. </xsl:choose>
  839. </xsl:variable>
  840. <xsl:if test="$show_cables or $debug">
  841. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  842. <xsl:attribute name="PE_Price" select="0"/>
  843. <xsl:attribute name="choosed" select="'up'"/>
  844. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  845. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  846. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  847. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  848. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  849. </xsl:if>
  850. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  851. </cost>
  852. </xsl:otherwise>
  853. </xsl:choose>
  854. </xsl:when>
  855. <xsl:otherwise>
  856. <cost>
  857. <xsl:attribute name="Cable_Price" select="0"/>
  858. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  859. <xsl:attribute name="Price" select="$PE_Price"/>
  860. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  861. </cost>
  862. </xsl:otherwise>
  863. </xsl:choose>
  864. </xsl:for-each>
  865. </xsl:template>
  866. </xsl:stylesheet>