| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
-
-
- exclude-result-prefixes="xs"
- version="2.0">
-
- <xsl:import href="PE_wariant_bit_table.xsl"/>
-
- <xsl:output indent="yes"/>
- <xsl:strip-space elements="*"/>
-
- <xsl:param name="PE_Price" select="1500"/>
- <xsl:param name="Cable_Price" select="10"/>
-
- <xsl:param name="edge_paths_with_PE.xml"/>
-
- <!-- bedziemy od najdluzszej drogi starac sie rozmiescic PE w oparciu o rozmieszczenie klientow oraz odleglosci -->
-
-
-
- <xsl:template match="edge_joins_filled_paths">
-
- <xsl:variable name="edge_joins_filled_paths_len">
- <xsl:for-each select="item">
- <xsl:sort select="number(asText/@len)" order="descending"/>
- <Path>
- <xsl:attribute name="id" select="@id"/>
- <xsl:attribute name="len" select="asText/@len"/>
- <xsl:attribute name="Points_cnt" select="asText/@Points_cnt"/>
- </Path>
- </xsl:for-each>
- </xsl:variable>
- <xsl:variable name="edge_paths_with_PE_controll">
- <edge_paths_with_PE_controll>
- <xsl:apply-templates select="$edge_joins_filled_paths_len" mode="PointMatrixGroup"/>
- </edge_paths_with_PE_controll>
- </xsl:variable>
- <xsl:copy-of select="$edge_paths_with_PE_controll"/>
- <xsl:result-document href="edge_paths_with_PE.xml">
- <xsl:apply-templates select="$edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml"/>
- </xsl:result-document>
- </xsl:template>
-
-
- <xsl:template match="edge_paths_with_PE_controll" mode="edge_paths_with_PE.xml">
- <PE_candidates_dump>
- <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
- </PE_candidates_dump>
- </xsl:template>
-
- <xsl:template match="Path" mode="edge_paths_with_PE.xml">
- <LINESTRING>
- <xsl:attribute name="ID_Way" select="@id"/>
- <xsl:attribute name="Count" select="@Count"/>
- <xsl:attribute name="ID_Point_count" select="@Points_cnt"/>
- <xsl:attribute name="distance"/>
- <xsl:attribute name="dumb_frequency" select="''"/>
- <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
- </LINESTRING>
- </xsl:template>
-
- <xsl:template match="PointMatrixGroupPE" mode="edge_paths_with_PE.xml">
-
- <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
- </xsl:template>
-
- <xsl:template match="PointMatrixGroup" mode="edge_paths_with_PE.xml">
- <!--<test_matrux><xsl:copy-of select="."></xsl:copy-of></test_matrux>-->
- <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
- </xsl:template>
-
- <xsl:template match="odpalam_liczenie" mode="edge_paths_with_PE.xml">
- <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
- </xsl:template>
- <xsl:template match="koniec_wariantow" mode="edge_paths_with_PE.xml">
- <xsl:apply-templates mode="edge_paths_with_PE.xml"/>
- </xsl:template>
-
- <xsl:template match="bp:Path_Point" mode="edge_paths_with_PE.xml">
- <xsl:copy-of select="."/>
- </xsl:template>
-
- <xsl:template match="Path" mode="PointMatrixGroup">
- <Path>
- <xsl:variable name="edge_joins_filled_path" select=" doc(concat('edge_joins_filled_paths/edge_joins_filled_paths.',@id,'.xml'))"/>
- <xsl:attribute name="id" select="@id"/>
- <xsl:attribute name="Points_cnt" select="@Points_cnt"/>
- <xsl:variable name="Points_cnt" select="@Points_cnt"/>
- <xsl:attribute name="len" select="@len"/>
- <xsl:attribute name="Count" select="count($edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString)"/>
- <xsl:variable name="len" select="@len"/>
- <!--<xsl:variable name="edge_joins_filled_paths" select="collection( 'edge_joins_filled_paths?select=*.xml;recurse=yes')"/>-->
-
- <!--<EdgeWayJoinsPair>
- <xsl:copy-of select="$edge_joins_filled_path"></xsl:copy-of>
- </EdgeWayJoinsPair>-->
-
- <!-- liczmy najwieksza roznice odleglosci miedzy punktami -->
-
-
- <!-- rozmieszczamy prawidlowo PE na danej trasie -->
- <xsl:variable name="EconomicDistanceCut">
- <EconomicDistanceCut>
- <xsl:for-each select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString">
- <distance>
- <xsl:attribute name="pos" select="position()"/>
- <xsl:attribute name="not_id" select="@not_id"/>
- <xsl:attribute name="len" select="@len"/>
- <xsl:attribute name="id_path" select="@id_path"/>
- <xsl:attribute name="Points" select="count(Points)"/>
- <xsl:variable name="Points" select="count(Points)"/>
- <xsl:variable name="Ways" select="count(Ways)"/>
- <xsl:choose>
- <xsl:when test="$Ways or $Points">
- <xsl:attribute name="point_count" select="$Points + $Ways"/>
- </xsl:when>
- </xsl:choose>
- </distance>
- </xsl:for-each>
- </EconomicDistanceCut>
- </xsl:variable>
- <!--<xsl:copy-of select="$EconomicDistanceCut"/>-->
- <xsl:variable name="EconomicDistanceCut2">
- <EconomicDistanceCut2>
- <xsl:for-each select="$EconomicDistanceCut/EconomicDistanceCut/distance">
- <distance2>
- <xsl:attribute name="distance" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[number(@pos )< number(current()/@pos )]/@len)"/>
- <!-- suma do poprzedniego pkt tylko dla tych co maja pkt-->
- <xsl:choose>
- <xsl:when test="@point_count>0">
- <xsl:variable name="max_pos_z_pkt" select="max($EconomicDistanceCut/EconomicDistanceCut/distance[
- number(@pos )< number(current()/@pos ) and number(@point_count)>0
- ]/@pos)"/>
- <xsl:attribute name="max_pos_z_pkt" select="$max_pos_z_pkt"/>
- <xsl:variable name="disttopkt" select="sum( $EconomicDistanceCut/EconomicDistanceCut/distance[
- number(@pos )< number(current()/@pos )
- and number(@pos) >= number($max_pos_z_pkt)
- ]/@len)"/>
- <xsl:attribute name="disttopkt" select="$disttopkt" />
- <xsl:variable name="cost_dist" select="$Cable_Price * $disttopkt * @point_count"/>
- <xsl:attribute name="cost_dist" select="$cost_dist"/>
- <xsl:attribute name="point_count" select="@point_count"/>
- <xsl:if test="$cost_dist > $PE_Price">
- <xsl:attribute name="cut_by_pe" select="1"/>
- </xsl:if>
- <xsl:attribute name="not_id" select="@not_id"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:attribute name="point_count" select="0"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:attribute name="id_path" select="@id_path"/>
- <xsl:copy-of select="@point_count"/>
- <xsl:copy-of select="@pos"/>
- <xsl:copy-of select="@len"/>
- </distance2>
- </xsl:for-each>
- </EconomicDistanceCut2>
- </xsl:variable>
-
- <xsl:copy-of select="$EconomicDistanceCut2"/>
-
- <xsl:variable name="elements_cnt" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@point_count > 0])"/><!-- liczba wezlow potencjalnych licbza PE-->
- <xsl:variable name="bit_max" select="round($len div ( $PE_Price div $Cable_Price ) + count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist > $PE_Price]) )"/><!-- max licbza PE-->
-
- <!-- pogrupujemy elementy co 50 metrow -->
- <xsl:variable name="PointMatrixGroup">
- <PointMatrixGroup>
- <xsl:for-each-group select="$EconomicDistanceCut2/EconomicDistanceCut2/distance2" group-by="round( @distance div ( $PE_Price div $Cable_Price + 50 ))">
- <PointMatrixGroupPos>
- <xsl:variable name="elements_cnt_Pos" select="count(current-group()[@point_count > 0])"/>
- <xsl:variable name="bit_max_Pos" select="round(sum( current-group()/@disttopkt ) div ( $PE_Price div 20 ) )"/>
- <xsl:attribute name="distanceGr" select=" current-grouping-key()"/>
- <xsl:attribute name="elements_cnt_Pos" select="$elements_cnt_Pos"/>
- <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/>
- <xsl:attribute name="id_path" select="@id_path"/>
- <xsl:attribute name="point_count_Pos" select="sum(current-group()/@point_count)"/>
- <xsl:attribute name="LineStringCount" select="count( current-group())"/>
- <xsl:attribute name="len_sum" select="sum(current-group()/@len)"/>
- <xsl:attribute name="distanceBeg" select="min(current-group()/number(@distance))"/>
- <xsl:attribute name="distanceEnd" select="max(current-group()/number(@distance))"/>
- <!--<xsl:attribute name="GroupPos" select="position()"/>-->
- <xsl:for-each select="current-group()">
- <distance2>
- <xsl:attribute name="PosMatrGroup" select="position()"/>
- <xsl:copy-of select="@*"></xsl:copy-of>
- </distance2>
- </xsl:for-each>
- </PointMatrixGroupPos>
- </xsl:for-each-group>
- </PointMatrixGroup>
- </xsl:variable>
- <!-- wsadzamy PE w grupach i moze w kilku wariantach - najlepiej tam gdzie jest najwiecej klientow najpierw
- gdzie najwiecej klientow walimy wezly - grupujemy ilosciami klientow dzielac sume drogi na ilosc przewidzianych wezlow
- -->
- <!-- debug -->
- <xsl:copy-of select="$PointMatrixGroup"/>
- <PointMatrixGroupPE>
- <xsl:for-each select="$PointMatrixGroup/PointMatrixGroup">
- <xsl:for-each select="PointMatrixGroupPos">
- <xsl:variable name="bit_max_Pos" select="@bit_max_Pos"/>
- <xsl:variable name="point_count_Pos" select="@point_count_Pos"/>
- <xsl:variable name="distanceGr" select="@distanceGr"/>
- <PointMatrixGroup>
- <xsl:attribute name="bit_max_Pos" select="$bit_max_Pos"/><xsl:attribute name="point_count_Pos" select="$point_count_Pos"/><xsl:attribute name="distanceGr" select="$distanceGr"/>
- <xsl:attribute name="LineStringCount" select="@LineStringCount"/>
- <xsl:attribute name="len_sum" select="@len_sum"/>
- <xsl:attribute name="point_count_Pos" select="@point_count_Pos"/>
- <xsl:attribute name="distanceBeg" select="@distanceBeg"/>
- <xsl:attribute name="distanceEnd" select="@distanceEnd"/>
- <!-- ida kandydaci -->
- <xsl:variable name="candidates">
- <xsl:for-each select="distance2[( position() <= $bit_max_Pos and @point_count >0 ) or ( position()=1 and $point_count_Pos > 0 ) ]"> <!-- jak jest maly wspolczynnik to chociaz jeden punkt jak sa punkty jakies w tej grupie -->
- <xsl:sort select="@cost_dist" order="descending"/>
- <bp:Path_Point>
- <xsl:attribute name="DebugPosPoint" select="position()"/>
- <xsl:attribute name="PosMatrGroup" select="@PosMatrGroup"/>
- <xsl:attribute name="distanceGr" select="$distanceGr"/>
- <xsl:attribute name="pos" select="@pos"/>
- <xsl:attribute name="len" select="@len"/>
- <xsl:attribute name="distance" select="@distance"/>
- <xsl:attribute name="cost_dist" select="@cost_dist"/>
- <xsl:attribute name="id_path" select="@id_path"/>
- <xsl:attribute name="point_count" select="@point_count"/>
-
- <xsl:attribute name="X" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@X"/>
- <xsl:attribute name="Y" select="$edge_joins_filled_path/edge_joins_filled_paths_xml/asText_XMl/LineString[@id_path = current()/@id_path]/@Y"/>
- </bp:Path_Point>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:choose>
- <xsl:when test="count($candidates/bp:Path_Point) < 9 and count($candidates/bp:Path_Point)>1">
- <xsl:variable name="max_bit">
- <xsl:for-each select="1 to count($candidates/bp:Path_Point)"><xsl:value-of select="1"/></xsl:for-each>
- </xsl:variable>
- <odpalam_liczenie>
- <xsl:call-template name="calculate_optimum">
- <xsl:with-param name="candidates" select="$candidates"/>
- <xsl:with-param name="elements_cnt" select="count($candidates/bp:Path_Point)"/>
- <xsl:with-param name="max_bit" select="$max_bit"/>
- </xsl:call-template>
- </odpalam_liczenie>
- </xsl:when>
- <xsl:otherwise>
- <xsl:copy-of select="$candidates"></xsl:copy-of>
- </xsl:otherwise>
- </xsl:choose>
- </PointMatrixGroup>
- </xsl:for-each>
- </xsl:for-each>
- </PointMatrixGroupPE>
-
- <!--<PointMatrix>
- <xsl:attribute name="bit_max" select="$bit_max"/>
- <xsl:attribute name="elements_cnt" select="$elements_cnt"/>
-
- <xsl:attribute name="num_extr" select="count($EconomicDistanceCut2/EconomicDistanceCut2/distance2[@cost_dist > $PE_Price])"/>
- <!-\-<xsl:call-template name="PE_wariant">
- <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
- <xsl:with-param name="bit_max" select="$bit_max"/>
- </xsl:call-template>-\->
-
- </PointMatrix>-->
- </Path>
- </xsl:template>
-
-
-
- <xsl:template name="calculate_optimum">
- <xsl:param name="candidates" required="yes"/>
- <xsl:param name="elements_cnt" required="yes"/>
- <xsl:param name="variant" select="1"/>
- <xsl:param name="max_bit" required="yes"/>
- <xsl:param name="best_cost"/><xsl:param name="best_variant"/>
- <xsl:variable name="bit" select=" string-join(bp:decimalToBitFill($variant,$elements_cnt),'')"/>
- <xsl:variable name="cand_to_calc">
- <xsl:for-each select="$candidates/bp:Path_Point">
- <xsl:sort select="@distance"/>
- <bp:Path_Point>
- <xsl:attribute name="bit" select="$bit"/>
- <xsl:attribute name="bin_pos" select="substring($bit, position(),1)"/>
- <xsl:copy-of select="@*"/>
- <xsl:copy-of select="bp:Path_Point"></xsl:copy-of>
- </bp:Path_Point>
- </xsl:for-each>
- </xsl:variable>
- <!-- debug -->
- <!--<variant><xsl:attribute name="variant" select="$variant"/>
- <xsl:copy-of select="$cand_to_calc"/>
- </variant>-->
- <xsl:variable name="calc_cost_way">
- <xsl:call-template name="calc_cost_way"><xsl:with-param name="cand_to_calc" select="$cand_to_calc"/></xsl:call-template>
- </xsl:variable>
- <!--<xsl:copy-of select="$calc_cost_way"/>-->
- <xsl:variable name="best">
- <xsl:variable name="cur_Price" select="sum($calc_cost_way/cost/number(@Price))"/>
- <xsl:choose>
- <xsl:when test="number($cur_Price) < number($best_cost) or not($best_cost) ">
- <best>
- <xsl:attribute name="best_cost" select="$cur_Price"/>
- <xsl:attribute name="best_variant" select="$bit"/>
- </best>
- </xsl:when>
- <xsl:otherwise>
- <best>
- <xsl:attribute name="best_cost" select="$best_cost"/>
- <xsl:attribute name="best_variant" select="$best_variant"/>
- </best>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <!--<xsl:copy-of select="$best"/>-->
-
- <xsl:choose>
- <xsl:when test="$bit = $max_bit">
- <koniec_wariantow>
- <xsl:attribute name="best_variant" select="$best_variant"/>
- <xsl:for-each select="$candidates/bp:Path_Point">
- <xsl:sort select="@distance"/>
- <xsl:if test="substring($best_variant, position(),1)='1'"><!-- jak wystawiony w wariancie-->
- <bp:Path_Point>
- <xsl:attribute name="bit" select="$best_variant"/>
- <xsl:attribute name="bin_pos" select="substring($best_variant, position(),1)"/>
- <xsl:copy-of select="@*"/>
- <xsl:attribute name="Price" select="$best_cost"/>
- <xsl:copy-of select="bp:Path_Point"/>
- </bp:Path_Point>
- </xsl:if>
- </xsl:for-each>
-
- </koniec_wariantow></xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="calculate_optimum">
- <xsl:with-param name="candidates" select="$candidates"/>
- <xsl:with-param name="max_bit" select="$max_bit"/>
- <xsl:with-param name="variant" select="$variant + 1"/>
- <xsl:with-param name="elements_cnt" select="$elements_cnt"/>
- <xsl:with-param name="best_cost" select="$best/best/@best_cost"/>
- <xsl:with-param name="best_variant" select="$best/best/@best_variant"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-
- </xsl:template>
-
- <xsl:template name="calc_cost_way"><!-- do wyliczenia ile wyjda kable w takiej konfiguracji -->
- <xsl:param name="cand_to_calc" required="yes"/>
- <xsl:for-each select="$cand_to_calc/bp:Path_Point">
- <xsl:choose>
- <xsl:when test="@bin_pos=0"><!-- szukamy gdzie ma najblizej i za ile -->
- <xsl:variable name="way_up_id" select="max($cand_to_calc/bp:Path_Point[@bin_pos=1 and @id_path < current()/@id_path ]/number(@id_path))"/>
- <xsl:variable name="way_up_len" >
- <xsl:choose>
- <xsl:when test="$way_up_id">
- <xsl:value-of select="number( current()/@distance) - number($cand_to_calc/bp:Path_Point[@id_path=$way_up_id]/@distance)"/></xsl:when>
- <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="way_dn_id" select="max($cand_to_calc/bp:Path_Point[@bin_pos=1 and @id_path > current()/@id_path ]/number(@id_path)) " />
- <xsl:variable name="way_dn_len">
- <xsl:choose>
- <xsl:when test="$way_dn_id">
- <xsl:value-of select=" number($cand_to_calc/bp:Path_Point[@id_path=$way_dn_id]/@distance ) - current()/@distance"/>
- </xsl:when>
- <xsl:otherwise><xsl:value-of select="-1"/></xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:choose><!-- czy w gore czy w dol -->
- <xsl:when test=" number($way_up_len) >= number($way_dn_len) and number($way_dn_len) > 0 or $way_up_len=-1"> <!--and not($way_dn_len='NaN') -->
- <cost>
- <xsl:attribute name="Cable_Price" select="$Cable_Price * $way_dn_len "/> <!-- todo @point_count -->
- <xsl:attribute name="PE_Price" select="0"/>
- <xsl:attribute name="Price" select="$Cable_Price"/>
- <xsl:attribute name="choosed" select="'down'"/>
- <xsl:attribute name="way_up_id" select="$way_up_id"/><xsl:attribute name="way_up_len" select="$way_up_len"/>
- <xsl:attribute name="way_dn_id" select="$way_dn_id"/><xsl:attribute name="way_dn_len" select="$way_dn_len"/>
- </cost>
- </xsl:when>
-
- <xsl:otherwise>
- <cost>
- <xsl:attribute name="Cable_Price" select="$Cable_Price * $way_up_len "/> <!-- todo @point_count -->
- <xsl:attribute name="PE_Price" select="0"/>
- <xsl:attribute name="Price" select="$Cable_Price"/>
- <xsl:attribute name="choosed" select="'up'"/>
- <xsl:attribute name="way_up_id" select="$way_up_id"/><xsl:attribute name="way_up_len" select="$way_up_len"/>
- <xsl:attribute name="way_dn_id" select="$way_dn_id"/><xsl:attribute name="way_dn_len" select="$way_dn_len"/>
- </cost>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <cost>
- <xsl:attribute name="Cable_Price" select="0"/>
- <xsl:attribute name="PE_Price" select="$PE_Price"/>
- <xsl:attribute name="Price" select="$PE_Price"/>
- </cost>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
-
- </xsl:template>
-
-
- </xsl:stylesheet>
|