代做COMP6771 General Directed Weighted Graph代写C/C++程序

COMP6771

General Directed Weighted Graph

2 The Task

In this assignment, you will write a generic directed weighted graph (GDWG) with value-semantics in C++. Both the data stored at a node and the weight stored at an edge will be parameterised types. The types may be different. For example, here is a graph with nodes storing std::string and edges weighted by int :

using graph = gdwg::graph;

Formally, this directed weighted graph G = (N, E) will consist of a set of nodes N and a set of unweighted/weighted edges E.

Explicit assumption for N and E: copyable, comparable (i.e. you can do ==, < etc.), streamable (i.e. you can use operator<< ) and hashable.

All nodes are unique, that is to say, no two nodes will have the same value and shall not compare equal using perator== .

Given a node, an edge directed into it is called an incoming edge and an edge directed out of it is called an outgoing edge. The in-degree of a node is the number of its incoming edges. Similarly, the out-degree of a node is the number of its outgoing edges.

A graph can include both weighted and unweighted edges. This applies to this assignment as well, therefore, you need to differentiate between weighted and unweighted edges in your implementation.

You need to make use of dynamic polymorphism to implement a base edge class, from which unweighted_edge and weighted_edge classes will inherit. The edge class will represent a directed edge from a source node src to a destination node dst . The derived classes will specialise the behaviour of the edge based on whether it is weighted or unweighted.

To summarise, you will need to implement the following classes along with gdwg::graph :

edge: An abstract base class representing an edge in the graph, which can be either weighted or unweighted. It declares pure virtual functions that must be implemented by its derived classes.

weighted_edge: A derived class of edge that represents an edge with an associated weight.

unweighted_edge: A derived class of edge that represents an edge without an associated weight.

Note that edges can be reflexive, meaning the source and destination nodes of an edge could be the same.

G is a multi-edged graph, as there may be two edges from the same source node to the same destination node with two different weights. However, two edges from the same source node to the same destination node cannot have the same weight.

Some words have special meaning in this document. This section precisely defines those words.

Preconditions: the conditions that the function assumes to hold whenever it is called; violation of any preconditions results in undefined behaviours.

Effects: the actions performed by the function.

Postconditions: the conditions (sometimes termed observable results) established by the function.

Returns: a description of the value(s) returned by the function.

Throws: any exceptions thrown by the function, and the conditions that would cause the exception.

Complexity: the time and/or space complexity of the function.

Remarks: additional semantic constraints on the function.

Unspecified: the implementation is allowed to make its own decisions regarding what is unspecified, provided that it still follows the explicitly specified wording.

An Effects element may specify semantics for a function F in code using the term Equivalent to. The semantics for F are interpreted as follows:

All of the above terminology applies to the provided code, whether or not it is explicitly specified.

[Example: If F has a Preconditions element, but the code block doesnʼt explicitly check them, then it is implied that the preconditions have been checked. —end example]

If there is not a Returns element, and F has a non- void return type, all the return statements are in the code block.

Throws, Postconditions, and Complexity elements always have priority over the code block.

Specified complexity requirements are upper bounds, and implementations that provide better complexity guarantees meet the requirements.

The class synopsis is the minimum text your header requires to compile most tests (this doesnʼt mean that it will necessarily link or run as expected).

Blue text in code will link to C++ Reference or to another part of this document.

This section makes use of [stable.names]. A stable name is a short name for a (sub)section, and isnʼt supposed to change. We will use these to reference specific sections of the document.

[Example:

Student: Do we need to define gdwg::graph::operator!= ?

Tutor: [other.notes] mentions that you donʼt need to so you can get used to C++20ʼs generated operators.

—end example]

2.2 Constructors

Itʼs very important your constructors work. If we canʼt validly construct your objects, we canʼt test any of your other functions.

graph();

1. Effects: Value initialises all members.

2. Throws: Nothing.

graph(std::initializer_list il);

3. Effects: Equivalent to: graph(il.begin(), il.end());

template

graph(InputIt first, InputIt last);

4. Preconditions: Type InputIt models Cpp17 Input Iterator and is indirectly readable as type N .

5. Effects: Initialises the graphʼs node collection with the range [first, last) .

graph(graph&& other) noexcept;

6. Postconditions: *this is equal to the value other had before this constructorʼs invocation. other.empty() is true . All iterators pointing to elements owned by *this prior to this constructorʼs invocation are invalidated. All iterators pointing to elements owned by other prior to this constructorʼs invocation remain valid, but now point to the elements owned by *this .

auto perator=(graph&& other) noexcept -> graph&;

7. Effects: All existing nodes and edges are either move-assigned to, or are destroyed.

8. Postconditions:

*this is equal to the value other had before this operatorʼs invocation.

other.empty() is true .

All iterators pointing to elements owned by *this prior to this operatorʼs invocation are invalidated.

All iterators pointing to elements owned by other prior to this operatorʼs invocation remain valid, but now point to the elements owned by *this .

9. Returns: *this .

graph(graph const& other);

10. Postconditions: *this == other is true .

auto perator=(graph const& other) -> graph&;

11. Postconditions:

*this == other is true .

All iterators pointing to elements owned by *this prior to this operatorʼs invocation are invalidated.

Returns: *this .

2.3 Edge Class Hierachy

The edge class is an abstract BASE class that declares PURE virtual functions which must be implemented by its derived classes.

You will note that ONLY the member functions listed below can be specified as public , you are free to create other private virtual functions to help with the implementation of the derived classes and the features required for gdwg::graph .

NOTE: We didn't specify the keywords for functions such as const , virtual , override , or noexcept , this is intentional. You should use them where appropriate.

auto print_edge() -> std::string;

1. Effects: Returns a string representation of the edge.

2. Returns: A string representation of the edge.

3. Remarks: The format of the string representation is src -> dst | W | weight if the edge is weighted, and src -> dst | U if the edge is unweighted.

Note: print_edge will be used in the operator<< overload for the graph class.

auto is_weighted() -> bool;

4. Effects: identify whether the edge is weighted.

5. Returns: true if the edge is weighted, and false otherwise.

auto get_weight() -> std::optional;

7. Effects: Returns the weight of the edge, std::nullopt if the edge is unweighted.

8. Returns: The weight of the edge.

auto get_nodes() -> std::pair;

9. Effects: Returns the source and destination nodes of the edge.

10. Returns: A pair of the source and destination nodes of the edge.

As a polymorphic base class, edge should also have a public virtual destructor.

2.3.2 weighted_edge

The weighted_edge class inherits from edge and represents a weighted edge in the graph.

It MUST implement the edge classʼs pure virtual functions to provide appropriate funtionality for weighted edges.

Additionally, the weighted_edge class should have a constructor that takes the src , dst node, and weight as parameters and initialises the corresponding private member variables.

2.3.3 unweighted_edge

The unweighted_edge class inherits from edge and represents an unweighted edge in the graph.

It MUST implement the edge classʼs pure virtual functions to provide appropriate functionality for unweighted edges.

Similar to the weighted_edge class, the unweighted_edge class should have a constructor that takes the src node and dst node as parameters and initialises the corresponding private member variables.




热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图