Video of previous lectures:
A non-mandatory workshop will be held on 21 December remotely
If you attend remotely: webcam on for the entire duration
You have to organise in groups (you have to choose a name) of 3-4 people (see link to register on Signal)
I will provide online rooms for your internal discussions
The task to address will be presented the day of the workshop
Max. score: 4 (in addition to 32 points you can take with the written examination)
During the last lecture of the course (20 December 2021), you will be asked to fill-up a questionnaire on the organisation of the course and related stuff - it is anonymous, of course
Please, do it carefully and honestly, since it is one of the most important inputs I will have to understand what can be improved in the next year course
The fact that the course of this year is slightly different from the one held during the previous year one is mainly due to the comments I have received through these questionnaires
He was one of the most important men of Science of the whole history
Contributions in Mathematics, Physics, Astronomy, Logic
His works created entirely-new scholarly disciplines and fields
E.g.: graph theory - by demonstrating the problem of the seven bridges of Königsberg
Is it possible to walk around the city and to cross each of the bridges once and only once?
Graph: nodes (circles) connected by edges
An edge is followed every time one enters in a node, and another edge is needed to go out from that node
Each node, except the starting and ending nodes, should have an even number of edges for being satisfactorily traversed one or more times
But all the nodes in the graph have an odd number of edges
Contradiction: the problem of the seven bridges of Königsberg has no solution
Data structure used to describe in abstract terms several well-known situations
Routes between cities
Connections to people you know in social networks
Organisation of links between webpages on the Web
Two different kinds of graphs
undirected graphs, where an edge can be traversed in one way or the other indifferently
directed graphs, where the edge has a clear specification of the node-to-node direction that can be followed
Python package: NetworkX
Constructor: Graph()
Used for creating undirected graphs without any possible multiple edge between two nodes
Constructor: MultiGraph()
Used for creating undirected graphs which permit the specification of multiple edges between the same two nodes
NetworkX package allows us to associate as a node any possible immutable object definable in Python, that can be, thus, connected by means of one or more edges
add a node: <graph>.add_node(<node>)
If a node with that value is already present, the method has no effect on the graph
add an edge: <graph>.add_edge(<node_1>, <node_2>)
Inverting the position of the input nodes does not change the result in an undirected graph
remove a node: <graph>.remove_node(<node>)
removes <node> from the graph as well as all the edges that involve it directly
remove an edge:
<graph>.remove_edge(<node_1>, <node_2>)
removes the particular edge between the two nodes specified
from networkx import Graph
my_graph = Graph()
my_graph.add_node(1)
my_graph.add_node(2)
my_graph.add_node(3)
my_graph.add_node(4)
my_graph.add_edge(1,2)
my_graph.add_edge(1,3)
my_graph.add_edge(1,4)
my_graph.add_edge(2,3)
my_graph.add_edge(3,4)
from networkx import MultiGraph
my_graph = MultiGraph()
my_graph.add_node(1)
my_graph.add_node(2)
my_graph.add_node(3)
my_graph.add_node(4)
my_graph.add_edge(1,2)
my_graph.add_edge(1,2)
my_graph.add_edge(1,3)
my_graph.add_edge(1,4)
my_graph.add_edge(1,4)
my_graph.add_edge(2,3)
my_graph.add_edge(3,4)
Additional information can be specified to nodes and edges by means of Python named parameters
E.g.: my_graph.add_edge(1, 2, weight=4)
<graph>.nodes()
and <graph>.edges()
return particular kind of lists (called NodeView
and EdgeView
respectively) that can be iterated by means of a foreach loop as usual - but no attributes of nodes/edges will be returned
Such attribution is explicit if we call nodes()
and edges()
by specifying the named parameter data
as True, e.g.<graph>.nodes(data=True)
Constructor: DiGraph()
Used for creating directed graphs without any possible multiple edge between two nodes
Constructor: MultiDiGraph()
Used for creating directed graphs which permit the specification of multiple edges between the same two nodes
Same methods presented for the undirected graphs
In this case, the order between <node_1>
and <node_2>
in the methods for adding and removing an edge is meaningful, since an edge specifies now a particular direction: <node_1>
is the source node, while <node_2>
is the target node
from networkx import MultiGraph my_graph = MultiGraph() from networkx import MultiDiGraph my_graph = MultiDiGraph() my_graph.add_node(1) my_graph.add_node(2) my_graph.add_node(3) my_graph.add_node(4) my_graph.add_edge(1,2) my_graph.add_edge(1,2) my_graph.add_edge(1,3) my_graph.add_edge(1,4) my_graph.add_edge(1,4) my_graph.add_edge(2,3) my_graph.add_edge(3,4)