edge_paths_with_PE_controll.xsl 73 KB

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