edge_paths_with_PE_controll.xsl 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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; 40">
  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="40"/>
  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. <!-- tune max bit-->
  290. <xsl:variable name="bit_max">
  291. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/>
  292. <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) ) ])"/>
  293. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt ) + 1"/>
  294. <xsl:choose>
  295. <xsl:when test=" number($bit_max) = number(1)">
  296. <xsl:value-of select="2"/>
  297. </xsl:when>
  298. <xsl:when test=" number($bit_max) = number(0)">
  299. <xsl:value-of select="2"/>
  300. </xsl:when>
  301. <xsl:otherwise>
  302. <xsl:value-of select="$bit_max"/>
  303. </xsl:otherwise>
  304. </xsl:choose>
  305. </xsl:variable>
  306. <xsl:variable name="EconomicDistanceCut2">
  307. <EconomicDistanceCut2><xsl:attribute name="debug" select="'bez pustych punktow tylko grupowanie'"/>
  308. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; 0 ]">
  309. <distance2>
  310. <xsl:copy-of select="@*"/>
  311. <xsl:choose>
  312. <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-->
  313. <xsl:attribute name="PosCut3Flag" select="1"/>
  314. </xsl:when>
  315. <xsl:otherwise>
  316. <xsl:attribute name="PosCut3Flag" select="0"/>
  317. </xsl:otherwise>
  318. </xsl:choose>
  319. <xsl:copy-of select="PathsCrossed"/>
  320. </distance2>
  321. </xsl:for-each>
  322. </EconomicDistanceCut2>
  323. </xsl:variable>
  324. <xsl:variable name="EconomicDistanceCut2"> <!-- dla potrzeb przegrupowania po iles do wyliczen grup i posortowania -->
  325. <EconomicDistanceCut2><xsl:attribute name="debug" select="'add mod gr'"/>
  326. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2"> <!-- [@point_count &gt; 0] -->
  327. <distance2>
  328. <xsl:attribute name="PosCut3GrId" select="sum($EconomicDistanceCut2/EconomicDistanceCut2/distance2[ number(@pos) &lt; number(current()/@pos) ]/number(@PosCut3Flag))"/>
  329. <xsl:copy-of select="@*"/>
  330. <xsl:copy-of select="PathsCrossed"/>
  331. </distance2>
  332. </xsl:for-each>
  333. </EconomicDistanceCut2>
  334. </xsl:variable>
  335. <!-- debug -->
  336. <!--<EconomicDistanceCut2><xsl:attribute name="debug" select="'#183 just show PosCut3GrId data'"/>
  337. <xsl:for-each select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2">
  338. <distance2>
  339. <xsl:attribute name="fl" select="@PosCut3Flag"/>
  340. <xsl:copy-of select="@PosCut3GrId"/>
  341. <xsl:copy-of select="@CurSumNotPoints"/>
  342. <xsl:copy-of select="@NotPoints"/>
  343. <!-\-<xsl:copy-of select="@pos"/>-\->
  344. </distance2>
  345. </xsl:for-each>
  346. </EconomicDistanceCut2>-->
  347. <!-- debug -->
  348. <!--<debug>
  349. <xsl:copy-of select="$EconomicDistanceCut2"/>
  350. </debug>-->
  351. <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[number(@point_count) &gt; number(0) ])"/><!-- liczba wezlow potencjalnych licbza PE-->
  352. <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) ) ])"/>
  353. <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + $cost_dist_Cnt )"/>
  354. <!-- max licbza PE-->
  355. <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>
  356. <!-- pogrupujemy elementy co 50 metrow lub grupy ilosciowe -->
  357. <xsl:variable name="PointMatrixGroup">
  358. <PointMatrixGroup>
  359. <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="@PosCut3GrId "> <!-- stare : round( @distance div ( $PE_Price div $Cable_Price + 50 ))-->
  360. <PointMatrixGroupPos>
  361. <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count &gt; 0])"/>
  362. <xsl:variable name="countGr" select="count(current-group())"/>
  363. <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/number(@disttopkt) ) div ( number($PE_Price) div number($Cable_Price) ) )"/>
  364. <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))"/>
  365. </xsl:message>
  366. <xsl:attribute name="distanceGr" select="@PosCut3GrId "/> <!-- bylo current-grouping-key() -->
  367. <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
  368. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  369. <xsl:attribute name="id_path" select="@id_path"/>
  370. <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 -->
  371. <xsl:attribute name="LineStringCount" select="count( current-group())"/>
  372. <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
  373. <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
  374. <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
  375. <xsl:attribute name="countGr" select="$countGr"/>
  376. <!--<xsl:attribute name="GroupPos" select="position()"/>-->
  377. <xsl:for-each select="current-group()">
  378. <distance2>
  379. <xsl:attribute name="PosMatrGroup" select="position()"/>
  380. <xsl:copy-of select="@*"></xsl:copy-of>
  381. <xsl:copy-of select="PathsCrossed"/>
  382. </distance2>
  383. </xsl:for-each>
  384. </PointMatrixGroupPos>
  385. </xsl:for-each-group>
  386. </PointMatrixGroup>
  387. </xsl:variable>
  388. <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
  389. gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
  390. -->
  391. <!-- debug -->
  392. <xsl:if test="number($debug) &gt; 3">
  393. <debug_356>
  394. <xsl:copy-of select="$PointMatrixGroup"/>
  395. </debug_356>
  396. </xsl:if>
  397. <PointMatrixGroupPE>
  398. <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
  399. <xsl:for-each select="PointMatrixGroupPos">
  400. <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
  401. <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
  402. <xsl:variable name="distanceGr" select="@distanceGr"/>
  403. <PointMatrixGroup>
  404. <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
  405. <xsl:attribute name="point_count_Pos" select="$point_count_Pos"/>
  406. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  407. <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
  408. <xsl:attribute name="len_sum" select="@len_sum"/>
  409. <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
  410. <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
  411. <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
  412. <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"/>;
  413. </xsl:message>
  414. <!-- ida kandydaci -->
  415. <xsl:variable name="candidates">
  416. <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 -->
  417. <!--<xsl:sort select="@cost_dist" order="descending"/>-->
  418. <bp:Path_Point>
  419. <xsl:copy-of select="@ID_Join"/>
  420. <xsl:attribute name="DebugPosPoint" select="position()"/>
  421. <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
  422. <xsl:attribute name="distanceGr" select="$distanceGr"/>
  423. <xsl:attribute name="pos" select="@pos"/>
  424. <xsl:attribute name="len" select="@len"/>
  425. <xsl:attribute name="distance" select="@distance"/>
  426. <xsl:attribute name="cost_dist" select="@cost_dist"/>
  427. <xsl:attribute name="id_path" select="@id_path"/>
  428. <xsl:attribute name="point_count" select="@point_count"/>
  429. <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
  430. <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
  431. <xsl:copy-of select="PathsCrossed"/>
  432. </bp:Path_Point>
  433. </xsl:for-each>
  434. </xsl:variable>
  435. <!-- potrzebuje wywolac petle raz, aby sie do niej odniesc drugi raz z poprzednim wynikiem
  436. $last = A
  437. - najprosciej przez pliki oszukujac silnik xsl
  438. - tozsamowsci $ID_Way $distanceGr
  439. - do edge_paths_with_PE_controll_temp, read z edge_paths_with_PE_controll_temp.alias
  440. -->
  441. <xsl:variable name="cache_file_name" select="concat($edge_paths_with_PE_controll_temp,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$distanceGr,'.xml')"/>
  442. <xsl:variable name="PrevdistanceGr" select="number($distanceGr) - 1"/>
  443. <xsl:variable name="cache_file_name_previous" select="concat( $edge_paths_with_PE_controll_temp.alias,'/odpalam_liczenie_or_nie_',$ID_Way,'_',$PrevdistanceGr,'.xml')"/>
  444. <xsl:variable name="poprzednie_odpalam_liczenie_or_nie">
  445. <xsl:if test="$PrevdistanceGr &gt; 0 ">
  446. <xsl:copy-of select="doc($cache_file_name_previous)"/>
  447. </xsl:if>
  448. </xsl:variable>
  449. <!--<poprzednie_odpalam_liczenie_or_nie>
  450. <xsl:attribute name="cache_file_name_previous" select="$cache_file_name_previous"/>
  451. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  452. </poprzednie_odpalam_liczenie_or_nie>-->
  453. <xsl:variable name="odpalam_liczenie_or_nie">
  454. <xsl:choose>
  455. <xsl:when test="1=1"> <!-- bylo count($candidates/bp:Path_Point) &lt;= $max_combinate_groups_elements and count($candidates/bp:Path_Point)&gt;1-->
  456. <odpalam_liczenie>
  457. <!-- todo dolozyc poprzedni wezel dodany aby mogl od niego zawsze liczyc -->
  458. <!--<disabled>temporary blad after #410 OK - przeliczony wariant bit=000000010000 ( nr 4095;)
  459. [xslt] #239: calc @distanceGr=23; @point_count_Pos=19;@LineStringCount ; @len_sum=177; @distanceBeg=5055; @distanceEnd=5475;
  460. [xslt]
  461. [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: ""
  462. [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>-->
  463. <xsl:variable name="IfPathsCrossed" >
  464. <xsl:choose>
  465. <xsl:when test="$candidates/bp:Path_Point/PathsCrossed[@NeighJoin_way_up_ID_Join or @NeighJoin_way_dn_ID_Join]">
  466. <xsl:message>#534 there are PathsCrossed - allow to decrease -1</xsl:message>
  467. <xsl:value-of select="0"/>
  468. </xsl:when>
  469. <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
  470. </xsl:choose>
  471. </xsl:variable>
  472. <xsl:variable name="max_possible_bit"><!-- produkuje 11111111 -->
  473. <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
  474. </xsl:variable>
  475. <!-- tune -->
  476. <xsl:variable name="bit_max_Pos">
  477. <xsl:choose>
  478. <xsl:when test="number($bit_max_Pos) &lt; 1">
  479. <xsl:value-of select="1"/>
  480. </xsl:when>
  481. <xsl:otherwise><xsl:value-of select="$bit_max_Pos"/></xsl:otherwise>
  482. </xsl:choose>
  483. </xsl:variable>
  484. <xsl:call-template name="calculate_optimum">
  485. <xsl:with-param name="candidates" select="$candidates"/>
  486. <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
  487. <xsl:with-param name="max_bit" select="$bit_max_Pos"/>
  488. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  489. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/>
  490. <xsl:with-param name="variant" select="$IfPathsCrossed"/>
  491. </xsl:call-template>
  492. </odpalam_liczenie>
  493. </xsl:when>
  494. <xsl:otherwise>
  495. <xsl:message terminate="yes">#440 niewlasciwe wyzwlowneie - powinno byc domyslnie when </xsl:message>
  496. <xsl:for-each select="$candidates/bp:Path_Point">
  497. <bp:Path_Point>
  498. <xsl:copy-of select="@*"/>
  499. <xsl:attribute name="bin_pos" select="1"/>
  500. </bp:Path_Point>
  501. </xsl:for-each>
  502. <!--<xsl:copy-of select="$candidates"></xsl:copy-of>-->
  503. </xsl:otherwise>
  504. </xsl:choose>
  505. </xsl:variable>
  506. <xsl:if test="number($debug) &gt; 0">
  507. <debug423>
  508. <xsl:attribute name="liczenie_dla"/>
  509. <candidates>
  510. <xsl:copy-of select="$candidates"/>
  511. </candidates>
  512. <poprzednie_odpalam_liczenie_or_nie>
  513. <xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie"/>
  514. </poprzednie_odpalam_liczenie_or_nie>
  515. </debug423>
  516. </xsl:if>
  517. <xsl:copy-of select="$odpalam_liczenie_or_nie"/>
  518. <xsl:result-document href="{$cache_file_name}"> <!-- zapisanie do cache, aby odczytac w kolejnej petli-->
  519. <poprzednie_odpalam_liczenie_or_nie>
  520. <xsl:for-each select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point">
  521. <xsl:if test="position() = last()">
  522. <xsl:copy-of select="."/>
  523. </xsl:if>
  524. </xsl:for-each>
  525. <nizej_zwykly></nizej_zwykly>
  526. <xsl:for-each select="$odpalam_liczenie_or_nie/bp:Path_Point">
  527. <xsl:if test="position() = last()">
  528. <xsl:copy-of select="."/>
  529. </xsl:if>
  530. </xsl:for-each>
  531. <!--<xsl:copy-of select="$odpalam_liczenie_or_nie/odpalam_liczenie/koniec_wariantow/bp:Path_Point"/>
  532. <xsl:copy-of select="$odpalam_liczenie_or_nie/bp:Path_Point"/>-->
  533. </poprzednie_odpalam_liczenie_or_nie>
  534. </xsl:result-document>
  535. </PointMatrixGroup>
  536. </xsl:for-each>
  537. </xsl:for-each>
  538. </PointMatrixGroupPE>
  539. <!--<PointMatrix>
  540. <xsl:attribute name="bit_max" select="$bit_max"/>
  541. <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
  542. <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist &gt; $PE_Price])"/>
  543. <!-\-<xsl:call-template name="PE_wariant">
  544. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  545. <xsl:with-param name="bit_max" select="$bit_max"/>
  546. </xsl:call-template>-\->
  547. </PointMatrix>-->
  548. </Path>
  549. </xsl:template>
  550. <xsl:template match="edge_paths_with_PE_controll|Path|PointMatrixGroupPE|PointMatrixGroup|odpalam_liczenie|koniec_wariantow" mode="PathsCrossed">
  551. <xsl:apply-templates mode="PathsCrossed"/>
  552. </xsl:template>
  553. <xsl:template match="bp:Path_Point" mode="PathsCrossed"> <!-- nie potrzebujemy kabli ! bp:Path_Point_Cable-->
  554. <xsl:copy-of select="."/>
  555. </xsl:template>
  556. <xsl:template match="*|text()" mode="PathsCrossed"/>
  557. <xsl:template name="calculate_optimum">
  558. <xsl:param name="candidates" required="yes"/>
  559. <xsl:param name="elements_cnt" required="yes"/>
  560. <xsl:param name="variant" select="1"/>
  561. <xsl:param name="max_bit" required="yes"/>
  562. <xsl:param name="max_possible_bit" required="yes"/>
  563. <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
  564. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  565. <!-- do jednorazowego wyzwolenia przez fukcje, aby tylko raz odjelo wariant zerowy -->
  566. <!-- znajduje kolejny korzystny wariant bit , trzeba to wyzwolic jak jest wiecej jedynek-->
  567. <xsl:variable name="variant">
  568. <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
  569. <xsl:variable name="digits">
  570. <xsl:for-each select="1 to string-length($bit)">
  571. <xsl:if test="substring($bit,.,1) = '1'">
  572. <xsl:value-of select="number(1)"/>
  573. </xsl:if>
  574. </xsl:for-each>
  575. </xsl:variable>
  576. <xsl:choose>
  577. <xsl:when test=" string-length($digits) &gt; number($max_bit)">
  578. <xsl:choose>
  579. <xsl:when test="$bit = $max_possible_bit">
  580. <xsl:value-of select="$variant"/><!-- osiagnieto max -->
  581. <xsl:message>#627 Osiagnieto MAX $bit<xsl:value-of select="$bit"/>; = $max_possible_bit=<xsl:value-of select="$max_possible_bit"/>;</xsl:message>
  582. </xsl:when>
  583. <xsl:when test="number($max_bit) &gt;= number($elements_cnt)">
  584. <xsl:message>#576 olac $max_bit <xsl:value-of select="$max_possible_bit"/> &gt;$elements_cnt=<xsl:value-of select="$elements_cnt"/>; in $variant=<xsl:value-of select="$variant"/>;</xsl:message>
  585. <xsl:value-of select="number($variant)"/>
  586. </xsl:when>
  587. <xsl:when test="number($max_bit) &gt; 0">
  588. <xsl:if test="$variant mod 64 = 0 ">
  589. <xsl:message>#80 try to find next $bit=<xsl:value-of select="$bit"/>; $max_possible_bit=<xsl:value-of select="$max_possible_bit"/>; $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>
  590. </xsl:if>
  591. <!--<xsl:variable name="variant_found" select="bp:next_bit_max(number($variant),$max_bit,$max_possible_bit,0)"/>-->
  592. <xsl:variable name="variant_found">
  593. <xsl:call-template name="bp:next_bit_max">
  594. <xsl:with-param name="variant" select="$variant"/>
  595. <xsl:with-param name="bit_limit" select="$max_bit"/> <!-- like 6 -->
  596. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/><!-- like 1111111 -->
  597. <xsl:with-param name="loop" select="0"/>
  598. </xsl:call-template>
  599. </xsl:variable>
  600. <xsl:value-of select="$variant_found"/>
  601. </xsl:when>
  602. <xsl:otherwise>
  603. <xsl:value-of select="number($variant)"/>
  604. </xsl:otherwise>
  605. </xsl:choose>
  606. </xsl:when>
  607. <xsl:otherwise><xsl:value-of select="$variant"/></xsl:otherwise>
  608. </xsl:choose>
  609. </xsl:variable>
  610. <xsl:variable name="bit">
  611. <xsl:choose><!-- funkcja nearest possible bit moze zwrocic zero! -->
  612. <xsl:when test=" string-length($variant) &gt; 0"><xsl:value-of select="string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/></xsl:when>
  613. <xsl:otherwise><xsl:value-of select="$max_possible_bit"/></xsl:otherwise>
  614. </xsl:choose>
  615. </xsl:variable>
  616. <xsl:if test=" string-length($bit) = 0"><xsl:message>#650 zerowy $bit ! nie moze byc tak!</xsl:message></xsl:if>
  617. <xsl:if test="$variant mod 64 = 0 ">
  618. <xsl:message>...#625 $variant curr found <xsl:value-of select="$variant"/>; $max_bit=<xsl:value-of select="$max_bit"/>; $bit=<xsl:value-of select="$bit"/>, $elements_cnt=<xsl:value-of select="$elements_cnt"/>;</xsl:message>
  619. </xsl:if>
  620. <xsl:variable name="cand_to_calc">
  621. <xsl:for-each select="$candidates/bp:Path_Point">
  622. <!--<xsl:sort select="number(@distance)"/>-->
  623. <bp:Path_Point>
  624. <!--<xsl:attribute name="bit" select="$bit"/>-->
  625. <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
  626. <xsl:copy-of select="@*"/>
  627. <!--<xsl:copy-of select="bp:Path_Point"/>-->
  628. <xsl:copy-of select="PathsCrossed"/>
  629. </bp:Path_Point>
  630. </xsl:for-each>
  631. </xsl:variable>
  632. <!-- debug -->
  633. <xsl:if test=" number($debug) &gt; 2">
  634. <variant><xsl:attribute name="variant" select="$variant"/>
  635. <xsl:attribute name="cur_bit" select="$bit"/>
  636. <xsl:attribute name="best_cost" select="$best_cost"/>
  637. <xsl:attribute name="best_variant" select="$best_variant"/>
  638. <xsl:copy-of select="$cand_to_calc"/>
  639. </variant>
  640. </xsl:if>
  641. <xsl:variable name="calc_cost_way">
  642. <xsl:call-template name="calc_cost_way">
  643. <xsl:with-param name="cand_to_calc" select="$cand_to_calc"/>
  644. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  645. </xsl:call-template>
  646. </xsl:variable>
  647. <xsl:variable name="cost_sum">
  648. <costs>
  649. <xsl:attribute name="Cable_Price" select="sum($calc_cost_way/cost/@Cable_Price)" />
  650. <xsl:attribute name="PE_Price" select="sum($calc_cost_way/cost/@PE_Price)"/>
  651. <xsl:attribute name="Price" select="sum($calc_cost_way/cost/@Price)"/>
  652. <xsl:copy-of select="$calc_cost_way"/>
  653. </costs>
  654. </xsl:variable>
  655. <xsl:if test="number($debug) &gt;2 "><xsl:copy-of select="$cost_sum"/></xsl:if>
  656. <xsl:variable name="best">
  657. <xsl:variable name="cur_Price" select="$cost_sum/costs/@Price"/>
  658. <xsl:choose>
  659. <xsl:when test="number($cur_Price) &lt; number($best_cost) or not($best_cost) ">
  660. <best>
  661. <xsl:attribute name="best_cost" select="$cur_Price"/>
  662. <xsl:attribute name="best_variant" select="$bit"/>
  663. </best>
  664. </xsl:when>
  665. <xsl:otherwise>
  666. <best>
  667. <xsl:attribute name="best_cost" select="$best_cost"/>
  668. <xsl:attribute name="best_variant" select="$best_variant"/>
  669. </best>
  670. </xsl:otherwise>
  671. </xsl:choose>
  672. </xsl:variable>
  673. <xsl:if test=" number($debug) &gt; 3 ">
  674. <xsl:copy-of select="$best"/>
  675. <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>
  676. </xsl:if>
  677. <xsl:choose>
  678. <xsl:when test="$bit = $max_possible_bit">
  679. <koniec_wariantow>
  680. <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>
  681. <xsl:attribute name="best_variant" select="$best_variant"/>
  682. <!-- trzeba przygotowac stary set dla best do pokazania kabli -->
  683. <xsl:variable name="cand_to_calc_best">
  684. <xsl:for-each select="$candidates/bp:Path_Point">
  685. <!--<xsl:sort select="@distance"/>-->
  686. <bp:Path_Point>
  687. <!--<xsl:attribute name="bit" select="$bit"/>-->
  688. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  689. <xsl:copy-of select="@*"/>
  690. <xsl:copy-of select="bp:Path_Point"/>
  691. </bp:Path_Point>
  692. </xsl:for-each>
  693. </xsl:variable>
  694. <xsl:variable name="show_cables">
  695. <xsl:call-template name="calc_cost_way">
  696. <xsl:with-param name="cand_to_calc" select="$cand_to_calc_best"/>
  697. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  698. <xsl:with-param name="show_cables" select="1"/>
  699. </xsl:call-template>
  700. </xsl:variable>
  701. <xsl:for-each select="$candidates/bp:Path_Point">
  702. <!--<xsl:sort select="number(@distance)"/>-->
  703. <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
  704. <bp:Path_Point>
  705. <xsl:attribute name="bit" select="$best_variant"/>
  706. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  707. <xsl:copy-of select="@*"/>
  708. <xsl:attribute name="Price" select="$best_cost"/>
  709. <xsl:copy-of select="bp:Path_Point"/>
  710. </bp:Path_Point>
  711. </xsl:if>
  712. <xsl:if test="substring($best_variant, position(),1)='0'"><!-- wyznaczenie od razu kabla -->
  713. <bp:Path_Point_Cable>
  714. <xsl:attribute name="bit" select="$best_variant"/>
  715. <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
  716. <xsl:copy-of select="@*"/>
  717. <xsl:attribute name="Price" select="$best_cost"/>
  718. <xsl:attribute name="Target_ID_Join" select="$show_cables/cost[@ID_Join = current()/@ID_Join]/@Target_ID_Join"/>
  719. <!-- todo do jakiego Join zostal przybity -->
  720. <xsl:copy-of select="bp:Path_Point"/>
  721. <!-- <xsl:if test="$debug">-->
  722. <debug_show_cables>
  723. <xsl:copy-of select="$show_cables/cost[@ID_Join= current()/@ID_Join]"/>
  724. </debug_show_cables>
  725. <!--</xsl:if>-->
  726. </bp:Path_Point_Cable>
  727. </xsl:if>
  728. </xsl:for-each>
  729. </koniec_wariantow>
  730. </xsl:when>
  731. <xsl:otherwise>
  732. <!--<xsl:if test="$variant &lt; 10 ">--><!-- debug limit -->
  733. <xsl:call-template name="calculate_optimum">
  734. <xsl:with-param name="candidates" select="$candidates"/>
  735. <xsl:with-param name="max_bit" select="$max_bit"/>
  736. <xsl:with-param name="max_possible_bit" select="$max_possible_bit"/>
  737. <xsl:with-param name="variant" select="$variant + 1"/>
  738. <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
  739. <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
  740. <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
  741. <xsl:with-param name="poprzednie_odpalam_liczenie_or_nie" select="$poprzednie_odpalam_liczenie_or_nie"/>
  742. </xsl:call-template>
  743. <!--</xsl:if>-->
  744. </xsl:otherwise>
  745. </xsl:choose>
  746. </xsl:template>
  747. <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
  748. <xsl:param name="cand_to_calc" required="yes"/>
  749. <xsl:param name="poprzednie_odpalam_liczenie_or_nie"/>
  750. <xsl:param name="show_cables"/><!-- do ostatneigo wyzwolenia w koniec_wariantow aby pokazac skad dokad sa kable-->
  751. <xsl:variable name="candidates_merged_with_poprzednie">
  752. <xsl:for-each select="$poprzednie_odpalam_liczenie_or_nie/bp:Path_Point">
  753. <bp:Path_Point>
  754. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  755. <xsl:copy-of select="@*"/>
  756. <xsl:attribute name="distance_Neigh" select="0"/>
  757. </bp:Path_Point>
  758. </xsl:for-each>
  759. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  760. <bp:Path_Point>
  761. <xsl:copy-of select="@*"/>
  762. <xsl:attribute name="distance_Neigh" select="0"/>
  763. </bp:Path_Point>
  764. </xsl:for-each>
  765. <!-- dorzucenie Crossed -->
  766. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  767. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  768. <xsl:variable name="PathCrossFirst" select="position() = 1"/>
  769. <xsl:for-each select="PathsCrossed[@NeighJoin_way_up_ID_Join]">
  770. <!--<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>-->
  771. <bp:Path_Point>
  772. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  773. <xsl:attribute name="bin_pos" select="1"/>
  774. <xsl:attribute name="ID_Join" select="@NeighJoin_way_up_ID_Join"/>
  775. <xsl:choose>
  776. <xsl:when test="$PathCrossLast">
  777. <!--<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>-->
  778. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_up_len)"/>
  779. </xsl:when>
  780. <xsl:when test="$PathCrossFirst">
  781. <!--<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>-->
  782. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_up_len)"/>
  783. </xsl:when>
  784. <xsl:otherwise>
  785. <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>
  786. </xsl:otherwise>
  787. </xsl:choose>
  788. <xsl:attribute name="pos" select="-1"/>
  789. </bp:Path_Point>
  790. </xsl:for-each>
  791. </xsl:for-each>
  792. <xsl:for-each select="$cand_to_calc/bp:Path_Point">
  793. <xsl:variable name="PathCrossLast" select="position() = last()"/>
  794. <xsl:for-each select="PathsCrossed[@NeighJoin_way_dn_ID_Join]">
  795. <!--<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>-->
  796. <bp:Path_Point>
  797. <xsl:attribute name="poprzednia_grupa" select="true()"/>
  798. <xsl:attribute name="bin_pos" select="1"/>
  799. <xsl:attribute name="ID_Join" select="@NeighJoin_way_dn_ID_Join"/>
  800. <xsl:choose>
  801. <xsl:when test="$PathCrossLast">
  802. <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>
  803. <xsl:attribute name="distance" select="number(parent::node()/@distance) + number(@NeighJoin_way_dn_len)"/>
  804. </xsl:when>
  805. <xsl:otherwise>
  806. <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>
  807. <xsl:attribute name="distance" select="number(parent::node()/@distance) - number(@NeighJoin_way_dn_len)"/>
  808. </xsl:otherwise>
  809. </xsl:choose>
  810. <xsl:attribute name="pos" select="-1"/>
  811. </bp:Path_Point>
  812. </xsl:for-each>
  813. </xsl:for-each>
  814. <!--<xsl:copy-of select="$cand_to_calc/bp:Path_Point"/>-->
  815. </xsl:variable>
  816. <xsl:if test="number($debug) &gt;1">
  817. <candidates_merged_with_poprzednie>
  818. <cand_to_calc><xsl:copy-of select="$cand_to_calc"/></cand_to_calc>
  819. <poprzedniee><xsl:copy-of select="$poprzednie_odpalam_liczenie_or_nie/poprzednie_odpalam_liczenie_or_nie"/></poprzedniee>
  820. <merged><xsl:copy-of select="$candidates_merged_with_poprzednie"/></merged>
  821. </candidates_merged_with_poprzednie>
  822. <xsl:message>calc_cost_way: calc <xsl:copy-of select="$candidates_merged_with_poprzednie//node()/@ID_Join"/></xsl:message>
  823. </xsl:if>
  824. <xsl:for-each select="$candidates_merged_with_poprzednie/bp:Path_Point"> <!-- bylo cand_to_calc -->
  825. <xsl:sort select="number(@distance)"/>
  826. <!--<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>-->
  827. <xsl:variable name="CurDist" select="@distance"/> <!-- do wykorzystania w zalaeznosciach z jednej drogi do przylaczonej -->
  828. <xsl:choose>
  829. <xsl:when test="@poprzednia_grupa">
  830. <cost>
  831. <xsl:attribute name="Cable_Price" select="0"/>
  832. <xsl:attribute name="PE_Price" select="0"/>
  833. <xsl:attribute name="Price" select="0"/>
  834. <xsl:attribute name="debug" select="'ignore by last DistGroup @poprzednia_grupa'"/>
  835. </cost>
  836. </xsl:when>
  837. <!--<xsl:when test="number(string-length(@bin_pos))=0">
  838. <xsl:message>#768 debug @bin_pos=<xsl:value-of select="@bin_pos"/>; </xsl:message>
  839. </xsl:when>-->
  840. <xsl:when test="@bin_pos='0'"><!-- szukamy gdzie ma najblizej i za ile -->
  841. <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))"/>
  842. <!--<xsl:variable name="ID_Join_up" select="$candidates_merged_with_poprzednie/bp:Path_Point[@id_path =$way_up_id ]/@ID_Join"/>-->
  843. <xsl:variable name="way_up_len" >
  844. <xsl:choose>
  845. <xsl:when test="$way_up_id">
  846. <xsl:value-of select="number( current()/@distance) - number($candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_up_id]/@distance)"/>
  847. </xsl:when>
  848. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  849. </xsl:choose>
  850. </xsl:variable>
  851. <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)) " />
  852. <!--<xsl:variable name="ID_Join_dn" select="$candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join =$way_dn_id ]/@ID_Join"/>-->
  853. <xsl:variable name="way_dn_len">
  854. <xsl:choose>
  855. <xsl:when test="$way_dn_id">
  856. <xsl:value-of select=" number( $candidates_merged_with_poprzednie/bp:Path_Point[@ID_Join=$way_dn_id]/@distance ) - current()/number(@distance)"/>
  857. </xsl:when>
  858. <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
  859. </xsl:choose>
  860. </xsl:variable>
  861. <xsl:choose><!-- czy w gore czy w dol -->
  862. <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') -->
  863. <cost>
  864. <xsl:variable name="Cable_Price_sum">
  865. <xsl:choose>
  866. <xsl:when test="number(@point_count) &gt; 0 ">
  867. <xsl:value-of select="$Cable_Price * $way_dn_len * number(@point_count) "/>
  868. </xsl:when>
  869. <xsl:otherwise>
  870. <xsl:value-of select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
  871. </xsl:otherwise>
  872. </xsl:choose>
  873. </xsl:variable>
  874. <!-- todo @point_count -->
  875. <xsl:if test="$show_cables">
  876. <xsl:attribute name="choosed" select="'down'"/>
  877. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  878. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  879. <xsl:attribute name="way_dn_id" select="$way_dn_id"/>
  880. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  881. <xsl:attribute name="PE_Price" select="0"/>
  882. <xsl:attribute name="Target_ID_Join" select="$way_dn_id"/>
  883. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  884. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/>
  885. </xsl:if>
  886. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  887. </cost>
  888. </xsl:when>
  889. <xsl:otherwise>
  890. <cost>
  891. <xsl:variable name="Cable_Price_sum">
  892. <xsl:choose>
  893. <xsl:when test="number(@point_count) &gt; 0 ">
  894. <xsl:value-of select="$Cable_Price * $way_up_len * number(@point_count) "/>
  895. </xsl:when>
  896. <xsl:otherwise>
  897. <xsl:value-of select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
  898. </xsl:otherwise>
  899. </xsl:choose>
  900. </xsl:variable>
  901. <xsl:if test="$show_cables or $debug">
  902. <xsl:attribute name="Cable_Price" select="$Cable_Price_sum"/> <!-- todo @point_count -->
  903. <xsl:attribute name="PE_Price" select="0"/>
  904. <xsl:attribute name="choosed" select="'up'"/>
  905. <xsl:attribute name="way_up_id" select="$way_up_id"/>
  906. <xsl:attribute name="way_up_len" select="$way_up_len"/>
  907. <xsl:attribute name="way_dn_len" select="$way_dn_len"/>
  908. <xsl:attribute name="Target_ID_Join" select="$way_up_id"/>
  909. <xsl:attribute name="ID_Join" select="@ID_Join"/>
  910. </xsl:if>
  911. <xsl:attribute name="Price" select="$Cable_Price_sum"/>
  912. </cost>
  913. </xsl:otherwise>
  914. </xsl:choose>
  915. </xsl:when>
  916. <xsl:otherwise>
  917. <cost>
  918. <xsl:attribute name="Cable_Price" select="0"/>
  919. <xsl:attribute name="PE_Price" select="$PE_Price"/>
  920. <xsl:attribute name="Price" select="$PE_Price"/>
  921. <xsl:attribute name="mial_bin_pos" select="@bin_pos"/>
  922. </cost>
  923. </xsl:otherwise>
  924. </xsl:choose>
  925. </xsl:for-each>
  926. </xsl:template>
  927. </xsl:stylesheet>