合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

        代做Spatial Networks for Locations

        時間:2024-02-16  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



        Background
        Spatial Networks for Locations
         Locations are connected via roads (we assume traders can travel in both
        directions!)  These locations form a spatial network.  As traders used horses for travelling, they couldn’t travel too far!
        Pottery Trade
        Pottery trade was very active at that times. Each location had its own supply and demandfor pottery. The supply and demand were communicated by traders who also formed their
        own networks. They also potentially communicated the prices, but in these project wewill
        disregard this information.
        Social Networks for Traders
        Traders living in some locations know each other and exchange information about supplyand demand via postal services. These traders for a social network.
        How to Represent Networks
        Each network can be presented as a graph. In this project, we will focus on undirectedgraphs: both social and spatial networks can be represented as graphs:
        1. Spatial networks: nodes correspond to locations, and edges —to roads betweenthem (both directions)
        2. Social networks: nodes correspond to traders, and edges connect those who
        know each other (communicate)
        Networks/graphs can be very different!
        Project Questions
        1. Represent road maps and trader networks as graphs
        2. Find the shortest path between any two locations (return the shortest path andthedistance)
        3. (Static traders) Find the best trading options for a particular trader residing in aparticular location. Core concepts: Itineraries
        Itineraries provide the basis for our spatial network. They are provided as a list of (L1,L2, distance) tuples; listed in any order. L1 and L2 are provided as strings, distance is an integer number (miles).
        In the example:
        >>> itineraries = [('L1', 'L2', 20), ('L2', 'L3', 10), ('L1', 'L4', 15), ('L4','L5',5), ('L4', 'L8', 20), ('L5', 'L8', 22), ('L5', 'L6', 6), ('L6', 'L7', 20)]
        Supply and Demand of Goods (Pottery)
        Each location has its own supply and demand in pottery: supply is provided as a positivenumber, demand — as a negative. Locations with the highest demand should be servedfirst. Assume both numbers are integers. This is provided as a dictionary (in no particular order)
        >>> status = {'L1':50, 'L2':-5, 'L4':-40, 'L3':5, 'L5':5, 'L8':10, 'L6':10, 'L7':-30}Trader Locations
        Traders reside in some but not all locations. Only locations where traders are present cantrade. Each location can have maximum a single trader. Traders are provided as strings.
        Trader locations are provided as a dictionary (in no particular order). In the example:
        >>> trader_locations = {'T1':'L1', 'T2': 'L3', 'T3':'L4', 'T4':'L8', 'T5':'L7','T6':'L5'}
        Social network of Traders
        Traders also form a social network. A trader only trades within their own network
        (considers friends only). Traders also have access to supplies and demands in the
        corresponding locations. Trader friendships are provided as a list of tuples (in no particular order):
        >>> traders = [('T1','T2'), ('T2', 'T5'), ('T3', 'T1'), ('T3', 'T5'), ('T3', 'T6')]Q1
        Write a function create_spatial_network(itineraries) that takes itineraries (a list of
        tuples) and returns for each location its neighbors and distances to them. A location is
        considered to be a neighbour of another location if it can be reached by a single road (oneedge).
        Input:
        **3; itineraries: a list of tuples, where each tuple is of the
        form (location1, location2, distance). location1 and location2 are the stringlabels for these locations and distance is an integer. Your function should return a list of tuples, where each tuple is of the
        form (location, neighbours). neighbours should be of the
        form [(neighbour1, distance1), (neighbour2, distance2), ...] and be sorted by their
        distances (in the increasing order). If two or more neighbors have the same distance tothe location, tie-break by alphanumeric order on their labels. Note that in addition to the neighbors, the overall list has to be sorted. You may assume: **3; Distances are non-negative integer values
        **3; Inputs are correctly formatted data structures and types
        **3; There are no duplicate entries itineraries, and in each neighbor pair only appear
        once (i.e. no [('L1', 'L2', 20), ('L2', 'L1', 20)])
        Here is a diagram of an example network:
        For the network above, this would be a possible itineraries and the function should
        return the following:
        >>> itineraries = [('L1', 'L2', 20), ('L2', 'L3', 10), ('L1', 'L4', 15), ('L4','L5',5), ('L4', 'L8', 20), ('L5', 'L8', 22), ('L5', 'L6', 6), ('L6', 'L7', 20)]
        >>> create_spatial_network(itineraries)
        [('L1', [('L4', 15), ('L2', 20)]), ('L2', [('L3', 10), ('L1', 20)]), ('L3', [('L2',10)]),('L4', [('L5', 5), ('L1', 15), ('L8', 20)]), ('L5', [('L4', 5), ('L6', 6), ('L8', 22)]),('L6', [('L5', 6), ('L7', 20)]), ('L7', [('L6', 20)]), ('L8', [('L4', 20), ('L5', 22)])]A different example (not pictured):
        >>> itineraries = [('L4', 'L1', 2), ('L3', 'L1', 5), ('L1', 'L5', 5), ('L2', 'L5',1)]>>> create_spatial_network(itineraries)
        [('L1', [('L4', 2), ('L3', 5), ('L5', 5)]), ('L2', [('L5', 1)]), ('L3', [('L1',5)]),('L4', [('L1', 2)]), ('L5', [('L2', 1), ('L1', 5)])]
        Q2
        Write a function sort_demand_supply(status) that takes a dictionary of demands andsupplies and returns the information as a list of tuples sorted by the value so that locationswith greatest demands (the most negative number) are provided first.
        Input: **3; status: a dictionary of demands and supplies. The keys are the location labels
        (strings) and the values are integers, where a positive value represents supply
        and a negative value represents demand. Your function should return a list of tuples, where each tuple is of the
        form (location, demand_supply), and the list should be sorted in ascending order by
        their demand_supply (i.e. greatest demand to greatest supply). If two or more locationshave the same demand or supply, tie-break by alphanumeric order on their labels. You may assume: **3; Inputs are correctly formatted data structures and types
        >>> status = {'L1':50, 'L2':-5, 'L4':-40, 'L3':5, 'L5':5, 'L8':10, 'L6':10, 'L7':-30}>>> sort_demand_supply(status)
        [('L4', -40), ('L7', -30), ('L2', -5), ('L3', 5), ('L5', 5), ('L6', 10), ('L8',10),('L1', 50)]
        Another example:
        >>> status = {'L1':30, 'L2':-20, 'L4':100, 'L3':-50, 'L5':-60}
        >>> sort_demand_supply(status)
        [('L5', -60), ('L3', -50), ('L2', -20), ('L1', 30), ('L4', 100)]
        Q3
        Write a function create_social_network(traders) that takes traders, a list of tuples
        specifing trader connections (edges in the trader social network) and returns a list
        containing (trader, direct_connections) for each trader in traders.
        Input: **3; traders: a list of tuples specifing trader connections (edges in the trader social
        network). Each tuple is of the
        form (trader1, trader2) where trader1 and trader2 are string names of
        each trader.
        Your function should return list of tuples in alphanumeric order of trader name, where
        each tuple is of the form (trader, direct_connections), and direct_connections is analphanumerically sorted list of that trader's direct connections (i.e. there exists an edgebetween them in the trader social network). You may assume: **3; Inputs are correctly formatted data structures and types. Just like Q1a, you don't
        need to guard against something like [('T1', 'T2'), ('T2', 'T1')] or duplicate
        entries.
        The pictured example:
        >>> traders = [('T1','T2'), ('T2', 'T5'), ('T3', 'T1'), ('T3', 'T5'), ('T3', 'T6')]>>> create_social_network(traders)
        [('T1', ['T2', 'T3']), ('T2', ['T1', 'T5']), ('T3', ['T1', 'T5', 'T6']), ('T5', ['T2','T3']),('T6', ['T3'])]
        Another example (not pictured):
        >>> traders = [('T1', 'T5'), ('T2', 'T6'), ('T3', 'T7'), ('T4', 'T8'), ('T1', 'T6'),('T2', 'T7'), ('T3', 'T8'), ('T4', 'T5'), ('T1', 'T7'), ('T2', 'T8'), ('T3', 'T5'),('T4','T6')]
        >>> create_social_network(traders)
        [('T1', ['T5', 'T6', 'T7']), ('T2', ['T6', 'T7', 'T8']), ('T3', ['T5', 'T7', 'T8']),('T4', ['T5', 'T6', 'T8']), ('T5', ['T1', 'T3', 'T4']), ('T6', ['T1', 'T2', 'T4']),('T7',['T1', 'T2', 'T3']), ('T8', ['T2', 'T3', 'T4'])]
        Q4
        Write a function shortest_path(spatial_network, source, target, max_bound) that
        takes a spatial network, initial (source) location, target location and the maximumdistance(that a trader located in the initial location can travel) as its input and returns a tuple withashortest path and its total distance.
        Input:  spatial_network: a list of tuples, where each tuple is of the
        form (location, neighbours) and neighbours is of the
        form [(neighbour1, distance1), (neighbour2, distance2), ...]. This
        corresponds with the output of the function you wrote for Q1a.  source: the location label (string) of the initial location. **3; target: the location label (string) of the target location. **3; max_bound: an integer (or None) that specifies the maximum total distance that
        your trader can travel. If max_bound is None then always return the path withminimum distance. Your function should return a tuple (path, total_distance), where path is a string of
        each location label in the path separated by a - hyphen character, and total_distanceisthe total of the distances along the path.
        If there's two paths with the same minimum total distance, choose the path with morelocations on it. If there's two paths with the same minimum total distance and they havethe same number of locations on the path then choose alphanumerically smaller pathstring.
        If there is no path with a total distance within the max_bound then your function shouldreturn (None, None). You may assume:
         Inputs are correctly formatted data structures and types. **3; Distances are non-negative integer values. **3; The network is connected, so a path always exists, although it may not have atotal distance within the maximum bound.
        >>> spatial_network = [('L1', [('L4', 15), ('L2', 20)]), ('L2', [('L3', 10), ('L1',20)]),('L3', [('L2', 10)]), ('L4', [('L5', 5), ('L1', 15), ('L8', 20)]), ('L5', [('L4',5),('L6', 6), ('L8', 22)]), ('L6', [('L5', 6), ('L7', 20)]), ('L7', [('L6', 20)]), ('L8',[('L4', 20), ('L5', 22)])]
        >>> shortest_path(spatial_network, 'L1', 'L3', 50)
        ('L**L2-L3', 30)
        >>> shortest_path(spatial_network, 'L1', 'L3', 0)
        (None, None)
        >>> shortest_path(spatial_network, 'L1', 'L3', 10)
        (None, None)
        >>> shortest_path(spatial_network, 'L1', 'L3', None)
        ('L**L2-L3', 30)
        Q5
        In this question you will be writing a
        function trade(spatial_network, status_sorted, trader_locations, trader_network, max_dist_per_unit=3) that makes a single trade.
        Input:
        **3; spatial_network: a list of tuples, where each tuple is of the
        form (location, neighbours) and neighbours is of the
        form [(neighbour1, distance1), (neighbour2, distance2), ...]. This
        corresponds with the output of the function you wrote for Q1a. **3; status_sorted: a list of tuples, where each tuple is of the
        form (location, demand_supply), and the list is sorted in ascending order by
        their demand_supply (i.e. greatest demand to greatest supply) with ties brokenalphanumerically on location label. This corresponds with the output of the
        function you wrote for Q1b. **3; trader_locations: a dictionary of trader locations. The structure of this
        is trader_name: trader_location, where
        both trader_name and trader_location are strings. **3; trader_network: a list of tuples in alphanumeric order of trader name, whereeach tuple is of the form (trader, direct_connections), and direct_connections is an alphanumerically sorted list of that trader's direct
        connections (i.e. there exists an edge between them in the trader social network). This corresponds with the output of the function you wrote for Q1c. **3; max_dist_per_unit: a float or integer value that represents the maximumthetrader is willing to travel per unit. This parameter should have a default of 3in your
        function. Your function should return a single trade as a
        tuple (supplier_location, consumer_location, amount) where supplier_locationand consumer_location are location labels (strings) and amount is a positive integer. If notrade is possible return (None, None, None).
        Traders from the locations with highest demand contact their social network asking for
        help. Then they choose the contacts worth travelling to, based on distance and the
        amount of supply there. The trade shoud be determined as follows:
        1. Find the location with the highest demand, this will be the consumer location. 2. Find the trader at the consumer location (skip this location and go back to step1if
        there are no traders at this location) and consider the trader's connections. 3. A supplier location can only supply to the consumer location if their status is
        positive (i.e. they have items to supply) and can supply an amount up to this value(i.e. they can't supply so much that they result in having a demand for the itemthey are supplying). 4. If a supplier location is directly neighbouring by a single road (adjacent) to theconsumer location then the distance used is the direct distance between the twolocations, even if there exists a shorter route via other locations. If the supplier andconsumer are not adjacent then the shortest_path function should be used todetermine the distance. 5. The trader will trade with the connection that has the highest amount of units tosupply, subject to meeting the max_dist_per_unit of the distance/units ratio. 6. Then if no trade is possible in this location, consider the next location. Return (None, None, None) if all locations have been considered. You may assume: **3; Inputs are correctly formatted data structures and types. **3; Distances are non-negative integer values. **3; There will be at most one trader at any particular location.
        Consider the spatial and trader network in the image above. With a
        default max_dist_per_unit of 3, the trader will only consider travelling maximum3 milesfor each unit (one direction), i.e. they will agree to travel 6 miles for get 2 pottery units but
        not a single one.
        In the example, we have 'L4' as the location with the highest demand of 40 units
        (demand_supply=-40) and the trader 'T3' who resides there. 'T3''s direct connectionsare ['T1', 'T5', 'T6']. We can't trade with 'T5' because at their location ('L7') there is
        also demand for the items. We compare the units able to be supplied and the distance-units ratio for each potential
        supplier: **3; T1:
        o location: L1
        o supply max: 50
        o distance: 15
        o so they could supply all 40 units that are demanded at L4
        o distance/units = 15/40 = 0.375
        **3; T6:
        o location: L5
        o supply max: 5
        o distance: 5
        o so they could supply 5 of the units that are demanded at L4
        o distance/units = 5/5 = 1.0
        Since T1 has the largest amount of units able to be supplied, and the distance/units ratiois below the maximum (3), this trade goes ahead and the function would
        return ('L1', 'L4', 40). >>> spatial_network = [('L1', [('L4', 15), ('L2', 20)]), ('L2', [('L3', 10), ('L1',20)]),('L3', [('L2', 10)]), ('L4', [('L5', 5), ('L1', 15), ('L8', 20)]), ('L5', [('L4',5),('L6', 6), ('L8', 22)]), ('L6', [('L5', 6), ('L7', 20)]), ('L7', [('L6', 20)]), ('L8',[('L4', 20), ('L5', 22)])]
        >>> status_sorted = [('L4', -40), ('L7', -30), ('L2', -5), ('L3', 5), ('L5', 5), ('L6',10), ('L8', 10), ('L1', 50)]
        >>> trader_locations = {'T1':'L1', 'T2': 'L3', 'T3':'L4', 'T4':'L8', 'T5':'L7','T6':'L5'}
        >>> trader_network = [('T1', ['T2', 'T3']), ('T2', ['T1', 'T5']), ('T3', ['T1','T5','T6']), ('T5', ['T2', 'T3']),('T6', ['T3'])]
        >>> trade(spatial_network, status_sorted, trader_locations, trader_network)
        ('L1', 'L4', 40)
        More examples:
        >>> spatial_network = [('L1', [('L4', 2), ('L3', 5), ('L5', 5)]), ('L2', [('L5',1)]),('L3', [('L1', 5)]), ('L4', [('L1', 2)]), ('L5', [('L2', 1), ('L1', 5)])]
        >>> status = {'L1':30, 'L2':-20, 'L4':100, 'L3':-50, 'L5':-60}
        >>> status_sorted = [('L5', -60), ('L3', -50), ('L2', -20), ('L1', 30), ('L4',100)]>>> trader_locations = {'T1': 'L1', 'T2': 'L2'}
        >>> trader_network = [('T1', ['T2']), ('T2', ['T1'])]
        >>> trade(spatial_network, status_sorted, trader_locations, trader_network)
        ('L1', 'L2', 20)
        >>> trade(spatial_network, status_sorted, trader_locations, trader_network,
        max_dist_per_unit=0.001)
        (None, None, None)
        Q6
        In this part you'll be using the trade() function from part 3a iteratively to determine thestatus after several trades. Write a
        function trade_iteratively(num_iter, spatial_network, status, trader_locations, trader_network, max_dist_per_unit=3) that takes the number of iterations to perform,
        the spatial network, status dictionary, trader locations dictionary, trader network, and
        maximum distance per unit and returns a tuple containing the sorted status list
        after num_iter trades along with a list of trades performed.
        Input: **3; num_iter: the number of iterations to perform as an integer or None if the
        iteration should continue until no further trades can be made. **3; spatial_network: a list of tuples, where each tuple is of the
        form (location, neighbours) and neighbours is of the
        form [(neighbour1, distance1), (neighbour2, distance2), ...]. This
        corresponds with the output of the function you wrote for Q1a. **3; status: a dictionary of demands and supplies. The keys are the location labels
        (strings) and the values are integers, where a positive value represents supply
        and a negative value represents demand. **3; trader_locations: a dictionary of trader locations. The structure of this
        is trader_name: trader_location, where
        both trader_name and trader_location are strings. **3; trader_network: a list of tuples in alphanumeric order of trader name, whereeach tuple is of the form (trader, direct_connections), and direct_connections is an alphanumerically sorted list of that trader's direct
        connections (i.e. there exists an edge between them in the trader social network). This corresponds with the output of the function you wrote for Q1c.
        **3; max_dist_per_unit: a float or integer value that represents the maximumthetrader is willing to travel per unit. This parameter should have a default of 3in your
        function. At each iteration, the next trade to be performed is determined by the process in part 3a. We strongly suggest using the provided trade() function to find this trade. Your functionshould update the status dictionary at each iteration. Your function should return a tuple (final_supply_sorted, trades) containing the sorteddemand-supply status after num_iter trades along with a list of trades performed. The final_supply_sorted should be a list of tuples, where each tuple is of the
        form (location, demand_supply), and the list should be sorted in ascending order by
        their demand_supply (i.e. greatest demand to greatest supply). If two or more locationshave the same demand or supply, tie-break by alphanumeric order on their
        labels. trades should be a list of each trade performed, where a trade is of the
        form (supplier_location, consumer_location, amount) where supplier_locationandconsumer_location are location labels (strings) and amount is a positive integer. You may assume: Inputs are correctly formatted data structures and types. **3; Distances are non-negative integer values.  There will be at most one trader at any particular location.
        In the example pictured, only one trade can occur:
        >>> spatial_network = [('L1', [('L4', 15), ('L2', 20)]), ('L2', [('L3', 10), ('L1',20)]),('L3', [('L2', 10)]), ('L4', [('L5', 5), ('L1', 15), ('L8', 20)]), ('L5', [('L4',5),('L6', 6), ('L8', 22)]), ('L6', [('L5', 6), ('L7', 20)]), ('L7', [('L6', 20)]), ('L8',[('L4', 20), ('L5', 22)])]
        >>> status = {'L1': 50, 'L2': -5, 'L4': -40, 'L3': 5, 'L5': 5, 'L8': 10, 'L6': 10,'L7':-30}
        >>> trader_locations = {'T1': 'L1', 'T2': 'L3', 'T3': 'L4', 'T4': 'L8', 'T5': 'L7','T6':'L5'}
        >>> trader_network = [('T1', ['T2', 'T3']), ('T2', ['T1', 'T5']), ('T3', ['T1','T5','T6']), ('T5', ['T2', 'T3']),('T6', ['T3'])]
        >>> trade_iteratively(1, spatial_network, status, trader_locations, trader_network)([('L7', -30), ('L2', -5), ('L4', 0), ('L3', 5), ('L5', 5), ('L1', 10), ('L6', 10),('L8',10)], [('L1', 'L4', 40)])
        >>> trade_iteratively(None, spatial_network, status, trader_locations, trader_network)([('L7', -30), ('L2', -5), ('L4', 0), ('L3', 5), ('L5', 5), ('L1', 10), ('L6', 10),('L8',10)], [('L1', 'L4', 40)])

        請加QQ:99515681  郵箱:99515681@q.com   WX:codehelp 

        掃一掃在手機打開當前頁
      1. 上一篇:代寫ECE438、代做C/C++編程語言
      2. 下一篇: cs400編程代寫、A03.FirstGit程序語言代做
      3. 無相關信息
        合肥生活資訊

        合肥圖文信息
        出評 開團工具
        出評 開團工具
        挖掘機濾芯提升發動機性能
        挖掘機濾芯提升發動機性能
        戴納斯帝壁掛爐全國售后服務電話24小時官網400(全國服務熱線)
        戴納斯帝壁掛爐全國售后服務電話24小時官網
        菲斯曼壁掛爐全國統一400售后維修服務電話24小時服務熱線
        菲斯曼壁掛爐全國統一400售后維修服務電話2
        美的熱水器售后服務技術咨詢電話全國24小時客服熱線
        美的熱水器售后服務技術咨詢電話全國24小時
        海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
        海信羅馬假日洗衣機亮相AWE 復古美學與現代
        合肥機場巴士4號線
        合肥機場巴士4號線
        合肥機場巴士3號線
        合肥機場巴士3號線
      4. 上海廠房出租 短信驗證碼 酒店vi設計

        主站蜘蛛池模板: 国产无吗一区二区三区在线欢| 亚洲国产精品一区二区成人片国内| 国产精品一区二区无线| 精品国产AⅤ一区二区三区4区 | 国产美女露脸口爆吞精一区二区| 91视频国产一区| 日韩av无码一区二区三区| 高清一区二区三区| 最新中文字幕一区| 多人伦精品一区二区三区视频| 无码精品一区二区三区免费视频| 午夜精品一区二区三区在线观看| 国产精品香蕉一区二区三区| 一区二区三区福利视频免费观看| 国产精品无码一区二区在线观一| 欧洲精品免费一区二区三区| 国产精品福利一区二区久久| 日韩精品中文字幕无码一区| 免费一区二区三区| 最美女人体内射精一区二区| 狠狠综合久久AV一区二区三区 | 天堂Av无码Av一区二区三区| 99久久人妻精品免费一区| 亚州日本乱码一区二区三区| 国产一区二区三区不卡观| 久久精品免费一区二区三区 | 亚洲熟妇无码一区二区三区导航| 国产精品成人一区二区三区| 国模一区二区三区| 波多野结衣一区在线观看| 午夜在线视频一区二区三区| 性盈盈影院免费视频观看在线一区| 无码播放一区二区三区| 亚洲精品日韩一区二区小说| 无码人妻精品一区二区三区久久久 | 久久精品免费一区二区| 国产主播在线一区| 国产成人久久一区二区三区 | 日本一区二区在线播放| 亚洲丰满熟女一区二区v| 黑巨人与欧美精品一区|