An Introduction to Sage and Some Other Graph Theory Software

Transcription

An Introduction to Sage and Some Other Graph Theory Software
An Introduction to Sage and Some
Other Graph Theory Software
Meysam Madani
Sharif University of Technology
http://mehr.sharif.ir/~madani
Outline
A survey on Apps for graph theory
How to Implement a Graph Algorithm?




Programming in Fortran, Java, C++, …
Matlab and Mathematica
GraphTheory Package In Maple
iGraph in R, C and …
Sage
 Which is the best?
A SURVEY ON APPS
FOR GRAPH THEORY
newGRAPH
www.mi.sanu.ac.rs/newgraph
Java Based
Drawing, Adjacent Matrices, Some invariants
for any graphs, … Educational
Plantri
http://cs.anu.edu.au/~bdm/plantri/
C based
Generate planar graphs, planar cubic graphs,
Options for further restrictions, …
Groups & Graphs
http://www.combinatorialmath.ca/g&g/
A software package for graphs, digraphs, graph
embeddings, projective configurations,
polyhedra, convex hulls, combinatorial designs,
automorphism groups, and fractals, Hamilton
Cycle.
Grinvin
http://www.grinvin.org/en/
Grinvin is a software package for studying
graphs, their properties (invariants) and the
relations between these properties.
Graphlab
http://graphlab.org
C++ Based
Graphlab has a large selection of machine
learning methods already implemented
The latest GraphLab open source release is
GraphLab PowerGraph version 2.2,
GraphChi can run very large graph
computations on just a single machine, by using
a novel algorithm for processing the graph from
disk
Graphviz (Graph Visualization Software)
• open source
• Representing structural information as diagrams
of abstract graphs and networks.
• Many Layouts,
graph-tool
 Statistical analysis of graphs
 Implemented in C++,
 Creation and manipulation
 Convenient and powerful graph drawing based
on cairo or Graphviz.
 Support for typical statistical measurements
 Support for several graph-theoretical
algorithms
 Generation of random graphs,
 Support for well-established network models
GraphLab or GraphTea
http://graphtheorysoftware.com/
free and opensource(GPL) software framework
 draw a graph
 graphs and social networks.
 get reports about it
 run algorithms on it
 visualize it
Sharif University of Technology (Dr Daneshgar)
Flexivert
 http://flexivert.annahid.com/
 Under Microsoft .NET Framework
 Provides a comprehensive environment for implementing,
visualizing and testing graph algorithms.
 One of the special features of Flexivert is its scriptable context.
Flexivert's shell allows users and developers to run quick scripts
and see the results.
 Scripts can also be added as extensions to the program, in order to
add a basic functionality.
Sharif University of Technology (Dr E. Mahmoodian)
Graph Transformation Tools








AGG (Attributed Graph Grammar System)
GROOVE (Graphs for Object-Oriented Verification)
GReAT (Graph Rewriting and Transformation)
TREEBAG
Augur
Grammatika (Graph Transformation with Mathematica)
HOPS (The Higher Object Programming System)
PROGRES (PROgrammed Graph REwrite Systems)
Networks
Cytoscape,
• Open source software platform for visualizing
molecular interaction networks and biological pathways
and integrating these networks with annotations, gene
expression profiles and other state data. Now it is a
general platform for complex network analysis
and visualization
NodeXL
• A free, open-source template for Microsoft Excel that
makes it easy to explore network graphs, you can enter a
network edge list in a worksheet, click a button and see
your graph, all in the familiar environment of the Excel
window.
Gephi
• Networks, visualizing, analysis, good databases
SNAP (Stanford Network Analysis Project)
• General purpose network analysis and graph mining
library
• C++ and easily scales to massive networks with
hundreds of millions of nodes, and billions of edges.
• Manipulates large graphs, calculates structural
properties, generates regular and random graphs,
and supports attributes on nodes and edges.
• SNAP is also available through the NodeXL
HOW TO IMPLEMENT A
GRAPH ALGORITHM?





Programming in Fortran, Java, C++, …
Matlab and Mathematica
GraphTheory Package In Maple
iGraph in R, C and …
Sage
‫آﺷﻨﺎﻳﻲ ﺑﺎ ‪Sage‬‬
‫• ‪Sage‬ﻳﻚ ﻧﺮم اﻓﺰار راﻳﮕﺎن و ﻣﺘﻦ ﺑﺎز اﺳﺖ‪.‬‬
‫‪System for Algebra and Geometry Experimentation‬‬
‫• ﺟﺎﻣﻌﻪ ﻫﺪف ﻣﻮرد ﻧﻈﺮ اﻳﻦ ﻧﺮم اﻓﺰار‪ ،‬ﺟﺎﻣﻌﻪ رﻳﺎﺿﻴﺎت اﺳﺖ‪.‬‬
‫• از ﺷﺎﺧﻪ ﻫﺎي ﺟﺒﺮ‪ ،‬ﻫﻨﺪﺳﻪ‪ ،‬ﻧﻈﺮﻳﻪ اﻋﺪاد‪ ،‬رﻣﺰﻧﮕﺎري‪ ،‬ﻣﺤﺎﺳﺒﺎت ﻋﺪدي و ﺷﺎﺧﻪ ﻫﺎي‬
‫ﻣﺮﺗﺒﻂ ﭘﺸﺘﻴﺒﺎﻧﻲ ﻣﻲ ﻛﻨﺪ‪.‬‬
‫• ﻫﺪف ﻧﻬﺎﻳﻲ ﺳﻴﺞ‪ ،‬اﻳﺠﺎد ﻳﻚ ﻧﺮم اﻓﺰار راﻳﮕﺎن و ﻣﺘﻦ ﺑﺎز ﺑﺎ ﻗﺎﺑﻠﻴﺖ ﻫﺎي ﻧﺮم اﻓﺰارﻫﺎﻳﻲ‬
‫ﭼﻮن‬
‫‪ Maple, Mathematica, Magma‬و‪Matlab‬‬
‫اﺳﺖ‪.‬‬
‫• ﺑﺮاي اﻳﻦ ﻧﺮم اﻓﺰار راﻫﻨﻤﺎﻫﺎي ﺑﺴﻴﺎري وﺟﻮد دارد‬
‫)!‪1- Sage for beginners (free only for iranians‬‬
‫)‪2- Sage Tutorial (free for all‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﺗﺎرﻳﺨﭽﻪ‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫اوﻟﻴﻦ ﻧﺴﺨﻪ ﺳﻴﺞ ﺳﺎل ‪ 2005‬ﺗﻮﻟﻴﺪ ﺷﺪ‪.‬‬
‫ﻣﺪﻳﺮﻳﺖ ﭘﺮوژه ﺑﻪ ﻋﻬﺪه ‪ William Stein‬ﻳﻚ رﻳﺎﺿﻲ دان از داﻧﺸﮕﺎه‬
‫واﺷﻨﮕﺘﻮن ﺑﻮد‪.‬‬
‫او درﻳﺎﻓﺘﻪ ﺑﻮد ﻛﻪ ﻧﺮم اﻓﺰارﻫﺎي زﻳﺎدي رﻳﺎﺿﻲ زﻳﺎدي وﺟﻮد دارﻧﺪ ﻛﻪ در‬
‫زﺑﺎﻧﻬﺎي ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﻲ ﻣﺨﺘﻠﻔﻲ ﻧﻮﺷﺘﻪ ﺷﺪه اﻧﺪ‪.‬‬
‫اﻣﺎزﻣﺎﻧﻲ ﻛﻪ ﻣﻲ ﺧﻮاﻫﻴﺪ ﻛﺎرﻫﺎي ﻣﺨﺘﻠﻒ را اﻧﺠﺎم دﻫﻴﺪ ﺑﺎﻳﺴﺘﻲ ﺑﺎ ﺗﻚ ﺗﻚ‬
‫اﻳﻦ زﺑﺎﻧﻬﺎ آﺷﻨﺎ ﺑﺎﺷﻴﺪ‪.‬‬
‫در ﺻﻮرﺗﻲ ﻛﻪ در ﺳﻴﺞ ﺷﻤﺎ ﺣﺘﻲ ﻟﺰوﻣﻲ ﻧﺪارد ﺑﺮ ‪ python‬ﻣﺴﻠﻂ ﺑﺎﺷﻴﺪ!‬
‫ﻛﺎﻓﻴﺴﺖ ﻛﻤﻲ ﺑﺮ زﺑﺎن اﻧﮕﻠﻴﺴﻲ ﺗﺴﻠﻂ داﺷﺘﻪ ﺑﺎﺷﻴﺪ!!!‬
‫‪ Sage‬ﻣﺠﻤﻮﻋﻪ ﺑﻴﺶ از ‪ 100‬ﻧﺮم اﻓﺰار اﺳﺖ ﻛﻪ ﺗﻤﺎﻣﻲ اﻳﻦ ﻧﺮم اﻓﺰارﻫﺎ در‬
‫‪http://www.sagemath.org/links-omponents.html.‬‬
‫ﻗﺎﺑﻞ روﻳﺖ ﻫﺴﺘﻨﺪ‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫اﻫﺪاف ﺑﻠﻨﺪ ﻣﺪت ﺳﻴﺞ‪:‬‬
‫‪ -1‬ﻛﺎرﺑﺮدي‪ :‬ﻛﺎرﺑﺮان اﺻﻠﻲ ﺳﻴﺞ را داﻧﺸﺠﻮﻳﺎن‪ ،‬ﻣﺪرﺳﺎن و ﻣﺤﻘﻘﺎن رﻳﺎﺿﻴﺎت ﺗﺸﻜﻴﻞ ﻣﻲ‬
‫دﻫﻨﺪ‪ .‬ﻫﺪف ﺗﻮﻟﻴﺪ ﻧﺮم اﻓﺰاري اﺳﺖ ﻛﻪ ﺑﺘﻮاﻧﺪ در ﺟﺴﺘﺠﻮ و ﺗﺠﺮﺑﻪ ﺳﺎﺧﺘﺎرﻫﺎي رﻳﺎﺿﻴﺎت در‬
‫ﺗﺮﻛﻴﺒﻴﺎت‪ ،‬ﺟﺒﺮ‪ ،‬ﻫﻨﺪﺳﻪ‪ ،‬ﻧﻈﺮﻳﻪ اﻋﺪاد‪ ،‬رﻣﺰﻧﮕﺎري‪ ،‬ﻣﺤﺎﺳﺒﺎت ﻋﺪدي و ﺷﺎﺧﻪ ﻫﺎي ﻣﺮﺗﺒﻂ‬
‫اﺳﺖ‪ .‬ﺳﻴﺞ ﻛﺎر ﺑﺎ اﺷﻴﺎء و ﺳﺎﺧﺘﺎرﻫﺎي رﻳﺎﺿﻲ را ﺳﺎده ﺗﺮ ﻣﻲ ﻛﻨﺪ‪.‬‬
‫‪ -2‬ﻛﺎراﻳﻲ‪ :‬ﺳﺮﻳﻊ ﺑﻮدن‪ .‬ﺳﻴﺞ از ﻧﺮم اﻓﺰارﻫﺎي ﺑﺴﻴﺎر ﺑﻬﻴﻨﻪ ﺷﺪه ﻣﺎﻧﻨﺪ‪ PARI، GMP‬و‬
‫‪ NTL‬اﺳﺘﻔﺎده ﻣﻲ ﻛﻨﺪ و در ﻋﻤﻠﻴﺎت اﺻﻠﻲ ﺑﺴﻴﺎر ﺳﺮﻳﻊ اﺳﺖ‪.‬‬
‫‪ -3‬راﻳﮕﺎن و ﻣﺘﻦ ﺑﺎز ﺑﻮدن‪ :‬ﻛﺪ ﻣﻨﺒﻊ ﺑﻪ ﻃﻮر ﻛﺎﻣﻼ ﻣﻨﺎﺳﺒﻲ در دﺳﺘﺮس و ﺧﻮاﻧﺎ اﺳﺖ‪.‬‬
‫ﻛﺎرﺑﺮان ﻣﻲ ﺗﻮاﻧﻨﺪ اﻳﻨﻜﻪ ﺳﻴﺴﺘﻢ در ﻫﻨﮕﺎم اﺟﺮا واﻗﻌﺎ ﭼﻪ ﻛﺎري را اﻧﺠﺎم ﻣﻲ دﻫﺪ را درك‬
‫ﻛﻨﻨﺪ‬
‫‪ -4‬ﺳﺎدﮔﻲ اﺟﺮا‪ :‬ﺳﻴﺞ ﻣﻲ ﺗﻮاﻧﺪ ﺑﻪ ﺳﺎدﮔﻲ در ﺳﻴﺴﺘﻢ ﻋﺎﻣﻠﻬﺎي ﻟﻴﻨﻮﻛﺲ‪ ،‬ﻣﻚ و وﻳﻨﺪوز‬
‫اﺟﺮا ﺷﻮد‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫اﻫﺪاف ﺑﻠﻨﺪ ﻣﺪت ﺳﻴﺞ‪:‬‬
‫•‬
‫•‬
‫•‬
‫•‬
‫‪ -5‬ﻣﺸﺎرﻛﺖ‪ :‬اﻳﻦ ﻧﺮم اﻓﺰار از ﻧﻈﺮ ﻇﺎﻫﺮ اﺟﺮا ﺷﺒﺎﻫﺖ زﻳﺎدي ﺑﺎ اﻛﺜﺮ ﻧﺮم اﻓﺰارﻫﺎي‬
‫رﻳﺎﺿﻴﺎت ﻣﻮﺟﻮد دارد‪.‬‬
‫‪ -6‬ﭘﺸﺘﻴﺒﺎﻧﻲ ﻣﻨﺎﺳﺐ‪ :‬آﻣﻮزش ﻫﺎي ﻣﻨﺎﺳﺒﻲ ﺑﺮاي اﻳﻦ ﻧﺮم اﻓﺰار در ﻛﺘﺎب ﻫﺎ و ﺳﺎﻳﺖ‬
‫ﻫﺎي ﻣﺨﺘﻠﻒ ﻗﺎﺑﻞ دﺳﺘﺮس ﻫﺴﺘﻨﺪ‪.‬‬
‫‪ -7‬ﻗﺎﺑﻞ ﺗﻮﺳﻌﻪ‪ :‬ﻣﻲ ﺗﻮان ﻧﻮع ﻫﺎي ﺟﺪﻳﺪ ﺗﻌﺮﻳﻒ ﻛﺮد و از ﻛﺪﻫﺎي ﻧﻮﺷﺘﻪ ﺷﺪه‬
‫اﺳﺘﻔﺎده ﻛﺮد‪.‬‬
‫‪ -8‬ﻣﺤﻴﻂ ﻛﺎرﺑﺮي ﻣﻨﺎﺳﺐ‪ :‬ﻣﻲ ﺗﻮان ﺑﺎ ﻣﺸﺎﻫﺪه ﻣﺘﻦ ﻛﺪ ﻋﻤﻠﻜﺮد را ﺗﺤﻠﻴﻞ ﻛﺮد‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﻧﻴﺎزي ﻧﻴﺴﺖ ﭼﺮخ را دوﺑﺎره اﺧﺘﺮاع ﻛﺮد!‬
‫ﺑﺮاي رﺳﻴﺪن ﺑﻪ اﻳﻦ اﻫﺪاف ﺑﻪ ﻣﻮارد زﻳﺮ ﻧﻴﺎز دارﻳﻢ‬
‫•‬
‫•‬
‫•‬
‫•‬
‫ﻳﻚ زﺑﺎن ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﻲ ﺷﻲ ﮔﺮا‪ ،‬ﺳﺎده و ﻗﻮي‪ ،‬راﻳﮕﺎن )‪(Python‬‬
‫ﻳﻚ ﺳﺮي ﻛﻼس ﺗﻌﺮﻳﻒ ﺷﺪه ﺑﺮاي ﺗﻮاﺑﻊ رﻳﺎﺿﻲ )ﻛﻼس ﻫﺎي ﺳﻴﺞ(‬
‫ﻳﻚ ﺟﺎﻣﻌﻪ ﻣﻨﺎﺳﺐ ﺑﺮاي رﻓﻊ ﻧﻴﺎزﻫﺎي ﻣﺮﺗﺒﻂ )‪(www.sagemath.org‬‬
‫راﻫﻨﻤﺎ و ﻛﺘﺎب ﻫﺎي ﻻزم )ﺗﻴﻢ ﺳﻴﺞ ﭼﻨﺪ وﻗﺖ ﻳﻚ ﺑﺎر ﻳﻚ راﻫﻨﻤﺎي ﺟﺪﻳﺪ‬
‫و ﻣﻨﺎﺳﺐ اراﺋﻪ ﻣﻲ ﻛﻨﺪ(‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
(‫ ﺑﺎ ﭼﻨﺪ ﻧﺮم اﻓﺰار رﻳﺎﺿﻲ)ﻛﻠﻴﺎت‬Sage ‫ﻣﻘﺎﻳﺴﻪ‬
Open
source
No
Yes
Yes
Proprietary
GPL
GPL or LGPL
No
Proprietary
No
Proprietary
Free
Yes
GPL
2005
Free
No
Proprietary
2005
Free
Yes
GPL
Free
Yes
GPL
Development First public
started
release
System
Creator
Algebrator
GAP
Java Algebra System
Neven Jurkovic
GAP Group
Heinz Kredel
1986
1986
2000
1999
1986
2005
Maple
Symbolic Computation
Group,
University of
Waterloo
1980
1984
Mathematica
Wolfram Research
1986
1988
Maxima
MIT Project MAC and
Bill Schelter
et al.
1967
1998
Microsoft Mathematics
Microsoft
Sage
William A. Stein
SINGULAR
MATLAB
Wolfram Alpha
?
2005
Cost (USD)
$58.99
Free
Free
$2,275 (Commercial), $2,155
(Government),
$1245(Academic), $239
(Personal Edition), $99
(Student), $79 (Student, 12Month term)[2]
$2,495 (Professional), $1095
(Education), $140 (Student),
$69.95 (Student annual license)
[4] $295 (Personal)[5]
License
University of
Kaiserslauter
n
1984
1997
MathWorks
1989
2008
$2900 including required MATLAB
No
Proprietary
2009
Pro version: $4.99 / month, Pro version
for students: $2.99 / month,
Regular version free.
No
Proprietary
Wolfram Research
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‬
(‫ ﺑﺎ ﭼﻨﺪ ﻧﺮم اﻓﺰار رﻳﺎﺿﻲ)ﺗﻮاﻧﺎﻳﻲ‬Sage ‫ﻣﻘﺎﻳﺴﻪ‬
Formula editor
Arbitrary
precision
Integration
Integral
transforms
Equations
Inequalities
Diophantine
equations
Differential
equations
Recurrence
relations
Graph theory
Number theory
Quantifier
elimination
Boolean algebra
Tensors
Probability
Control Theory
Algebrator
Yes
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
?
?
Magma
No
Yes
No
No
Yes
No
Yes
No
No
Yes
Yes
No
No
No
?
?
Maple
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Mathematica Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
MATLAB
No
Yes
Yes
Yes
Yes
No
No
Yes
?
No
?
No
No
?
?
?
Maxima
No
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
Yes
?
?
Microsoft
Yes
Mathematics
No
Yes
No
Yes
Yes
No
No
No
No
No
No
Yes
No
?
?
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Pro version Yes
only
Yes
Yes
Yes
Yes
?
Yes
Yes
Yes
Yes
Yes
Yes
No
?
?
Sage
Wolfram
Alpha
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‬
‫روش ﻫﺎي اﺟﺮاي ‪sage‬‬
‫‪ -1‬ﻧﺼﺐ آن ﺑﻪ ﺻﻮرت ﻧﺮم اﻓﺰار‬
‫‪ -2‬اﺟﺮاي ﻣﺴﺘﻘﻴﻢ در ﺳﺎﻳﺖ ‪ . www.sagemath.org‬اﻟﺒﺘﻪ ﺑﺮﺧﻲ‬
‫اﻣﻜﺎﻧﺎت را ﻧﺨﻮاﻫﻴﺪ داﺷﺖ‪.‬‬
‫‪ -3‬از ﻃﺮﻳﻖ ﻧﺼﺐ روي ﺳﺮور و دﺳﺘﺮﺳﻲ اﻓﺮاد از ﻃﺮﻳﻖ ﺳﺮور‬
‫‪ -4‬اﺳﺘﻔﺎده در ﻣﺤﻴﻂ ﭘﺎﻳﺘﻮن‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﭼﻬﺎر روش ﻛﺎر ﺑﺎ ﻧﺮم اﻓﺰار‬
‫• ﺣﺎﻟﺖ ﮔﺮاﻓﻴﻜﻲ ﻧﻮت ﺑﻮك‪:‬‬
‫در اﻳﻦ ﺣﺎﻟﺖ ﺳﻴﺞ را در ﻳﻚ ﻣﺮورﮔﺮ وب ﺧﻮاﻫﻴﺪ دﻳﺪ و اﺟﺮا ﺧﻮاﻫﻴﺪ ﻛﺮد‪ .‬اﻳﻦ ﻣﺮورﮔﺮ‬
‫ﻣﻲ ﺗﻮاﻧﺪ ﻫﺮ ﻛﺪام از ﻣﺮورﮔﺮﻫﺎي ﻣﺸﻬﻮري ﻛﻪ اﺳﺘﻔﺎده ﻣﻲﻛﻨﻴﺪ ﺑﺎﺷﺪ‪.‬‬
‫ﺑﺮاي اﻳﻨﻜﺎر ﻳﻚ ﻣﺮورﮔﺮ وب ﺑﺎز ﻛﻨﻴﺪ و آدرس‬
‫‪http://localhost:8000‬‬
‫را ﻣﺮور ﻛﻨﻴﺪ‪.‬‬
‫• ﭘﻮﺳﺘﻪ ﭘﻮﻳﺎ‪:‬‬
‫ﻛﻪ در واﻗﻊ در ﻳﻚ ﺗﺮﻣﻴﻨﺎل آن را اﺟﺮا ﻣﻲ ﻛﻨﻴﺪ و در وﻳﻨﺪوز در ﻣﺤﻴﻂ‪dos‬‬
‫• ﺗﻮﺳﻂ ﺑﺮﻧﺎﻣﻪﻫﺎي ﻣﺨﺘﻠﻒ‪:‬‬
‫ﺑﺎ ﻧﻮﺷﺘﻦ و اﺟﺮاي ﻳﻚ ﺑﺮﻧﺎﻣﻪ در ﺳﻴﺞ‬
‫• اﺳﻜﺮﻳﭙﺖ‪:‬‬
‫ﺑﺎ ﻧﻮﺷﺘﻦ ﻳﻚ اﺳﻜﺮﻳﭙﺖ ﭘﺎﻳﺘﻮن ﻛﻪ از ﻛﺘﺎﺑﺨﺎﻧﻪ ﺳﻴﺞ اﺳﺘﻔﺎده ﻣﻲ ﻛﻨﺪ‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﻧﺼﺐ ‪ sage‬در وﻳﻨﺪوز‬
‫‪http://www.sagemath.org/download- -1‬‬
‫‪source.html‬‬
‫‪ -2‬آﺧﺮﻳﻦ ﻧﺴﺨﻪ را ﺑﺮاي وﻳﻨﺪوز داﻧﻠﻮد ﻛﻨﻴﺪ‪ 2 .‬ﮔﻴﮓ و آن را درﺟﺎﻳﻲ‬
‫ﻣﻄﻤﺌﻦ ﻧﮕﻪ دارﻳﺪ‬
‫‪ -3‬ﻧﺮم اﻓﺰار ‪ VirtualBox‬ﻧﺴﺨﻪ ﭼﻬﺎر ﺑﻪ ﺑﺎﻻ را داﻧﻠﻮد و ﻧﺼﺐ ﻛﻨﻴﺪ‪.‬‬
‫‪-4‬از ﻣﻨﻮي‬
‫‪File >Import Appliance> choose‬‬
‫ﻓﺎﻳﻞ داﻧﻠﻮد ﺷﺪه از ﺳﺎﻳﺖ را اﻧﺘﺨﺎب ﻛﻨﻴﺪ‪ .‬ﻛﻤﻲ ‪ next‬ﺑﺰﻧﻴﺪ‪.‬‬
‫‪ -5‬ﺑﺮاي اﺟﺮاي ‪ sage‬ﻫﺮ ﺑﺎر ﻛﺎﻓﻴﺴﺖ ‪ VirtualBox‬را اﺟﺮا ﻛﺮده‬
‫و ‪ sage‬را در آن اﺟﺮا ﻛﻨﻴﺪ‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﻧﺼﺐ ‪ sage‬در ﻟﻴﻨﻮﻛﺲ‬
‫‪http://www.sagemath.org/download- -1‬‬
‫‪source.html‬‬
‫‪ -2‬آﺧﺮﻳﻦ ﻧﺴﺨﻪ را ﺑﺮاي ﻟﻴﻨﻮﻛﺲ داﻧﻠﻮد ﻛﻨﻴﺪ‪ .‬ﺣﺪود‪ 400‬ﻣﮕﺎﺑﺎﻳﺖ‬
‫‪-2‬ﻓﺎﻳﻞ داﻧﻠﻮد ﺷﺪه را ‪ extract‬ﻛﻨﻴﺪ‪.‬‬
‫‪ -3‬ﻓﺎﻳﻞ ‪ sage.sh‬را اﺟﺮا ﻛﻨﻴﺪ‪.‬‬
‫ﺑﺎﻳﺴﺘﻲ ﺑﺴﺘﻪ ‪ gfortran‬ﻧﻴﺰ ﻧﺼﺐ ﺷﻮد‪ .‬از دﺳﺘﻮر‬
‫‪sudo apt-get install build-essential gfortran‬‬
‫اﺳﺘﻔﺎده ﻛﻨﻴﺪ‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
(‫ﺑﺮﺧﻲ ﺗﻮاﻧﺎﻳﻲ ﻫﺎ )ﺣﻞ ﻣﻌﺎدﻻت‬
x = var('x')
solve(x^2 + 3*x + 2, x)
[x == -2, x == -1]
---------------------var('x y p q')
eq1 = p+q==9
eq2 = q*y+p*x==-6
eq3 = q*y^2+p*x^2==24
solve([eq1,eq2,eq3,p==1],p,q,x,y)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‬
(‫ﺑﺮﺧﻲ ﺗﻮاﻧﺎﻳﻲ ﻫﺎ )ﻣﺤﺎﺳﺒﻪ اﻧﺘﮕﺮال و ﻣﺸﺘﻖ ﻧﺎﻣﻌﻴﻦ‬
diff(sin(x^2), x, 4)
---------------------x, y = var('x,y')
f = x^2 + 17*y^2
f.diff(x)
f.diff(y)
-------integral(x*sin(x^2), x)
integral(x/(x^2+1), x, 0, 1)
--------s = var("s")
t = var("t")
f = t^2*exp(t) - sin(t)
f.laplace(t,s)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‬
(‫ﺑﺮﺧﻲ ﺗﻮاﻧﺎﻳﻲ ﻫﺎ )ﺗﻮﻟﻴﺪ راﺑﻂ ﻛﺎرﺑﺮي‬
var('x')
x0 = 0
f = sin(x)*e^(-x)
p = plot(f,-1,5, thickness=2)
dot = point((x0,f(x=x0)),pointsize=80,rgbcolor=(1,0,0))
@interact
def _(order=(1..12)):
ft = f.taylor(x,x0,order)
pt = plot(ft,-1, 5, color='green', thickness=2)
html('$f(x)\;=\;%s$'%latex(f))
html('$\hat{f}(x;%s)\;=\;%s+\mathcal{O}(x^{%s})$'%(x0,la
tex(ft),order+1))
show(dot + p + pt, ymin = -.5, ymax = 1)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‬
‫ﺑﺮﺧﻲ ﻛﻠﻴﺪﻫﺎي ﻣﻴﺎﻧﺒﺮ‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫)‪help(exp‬‬
‫‪ = Shift+enter‬ﻣﺤﺎﺳﺒﻪ ﺣﺠﺮه‬
‫اﻳﺠﺎد ﻳﻚ ﺣﺠﺮه ﺟﺪﻳﺪ‬
‫;‪= ctrl+‬‬
‫‪ = ctrl+ backspace‬ﻳﻜﻲ ﻛﺮدن ﺑﺎ ﺣﺠﺮه ﻗﺒﻞ‬
‫‪ = Tab‬ﻣﺸﺎﻫﺪه اﻣﻜﺎﻧﺎت ﻗﺎﺑﻞ اﺟﺮا)ﻛﺎﻣﻞ ﻛﺮدن ﺧﻮدﻛﺎر(‬
‫‪ = Ctrl+0‬ﺑﺴﺘﻦ اﺗﻮﻣﺎﺗﻴﻚ ﭘﺮاﻧﺘﺰﻫﺎ‬
‫‪ = Ctrl+,‬ﮔﺬاﺷﺘﻦ ﻣﺘﻦ ﻧﻈﺮات)اﺟﺮا ﻧﻤﻲ ﺷﻮﻧﺪ(‬
‫‪ = Ctrl+.‬ﺗﺒﺪﻳﻞ ﻧﻈﺮات ﺑﻪ ﻣﺘﻦ ﺑﺮﻧﺎﻣﻪ‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﺑﺮﺧﻲ ﻋﻤﻠﮕﺮﻫﺎي ﻣﺤﺎﺳﺒﺎﺗﻲ‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫‪‬‬
‫=‬
‫‪+‬‬
‫‬‫*‬
‫‪/‬‬
‫**ﻳﺎ ^‬
‫‪%‬‬
‫‪//‬‬
‫‪ == ‬ﺗﺴﺎوي‬
‫‪<‬‬
‫‪>= ‬‬
‫ﺗﻮان‬
‫ﻣﺎﻧﺪه‬
‫ﺧﺎرج ﻗﺴﻤﺖ‬
‫‪<‬‬
‫‪<= ‬‬
‫‪ != ‬ﻣﺴﺎوي ﻧﻴﺴﺖ ﺑﺎ‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس اول – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫"‪print"hi‬‬
‫”ﺳﻼم“ ‪print‬‬
‫ﻗﺪر ﻣﻄﻖ )‪abs(number‬‬
‫ﻣﺤﺎﺳﺒﻪ رﻳﺸﻪ دوم ﺣﺘﻲ ﺑﺮاي اﻋﺪاد ﻣﻨﻔﻲ )‪cmath.sqrt(number‬‬
‫ﻳﻚ رﺷﺘﻪ ﻳﺎ ﻋﺪد را ﺑﻪ ﻳﻚ ﻋﺪد اﻋﺸﺎري ﺗﺒﺪﻳﻞ ﻣﻲ ﻛﻨﺪ )‪float(object‬‬
‫ﻛﻤﻚ )(‪help‬‬
‫ﮔﺮﻓﺘﻦ ورودي از ﻛﺎرﺑﺮ )‪input(prompt‬‬
‫ﺗﺒﺪﻳﻞ ﻳﻚ رﺷﺘﻪ ﻳﺎ ﻋﺪد ﺑﻪ ﻳﻚ ﻋﺪد ﺻﺤﻴﺢ )‪int(object‬‬
‫ﺗﺒﺪﻳﻞ ﻳﻚ رﺷﺘﻪ ﻳﺎ ﻋﺪد ﺑﻪ ﻳﻚ ﻋﺪد ﺻﺤﻴﺢ ﻃﻮﻻﻧﻲ )‪long(object‬‬
‫ﻛﻮﭼﻜﺘﺮﻳﻦ ﻋﺪد ﺻﺤﻴﺢ ﺑﺰرﮔﺘﺮ ﻣﺴﺎوي ﻳﻚ ﻋﺪد ﺻﺤﻴﺢ )‪math.ceil(number‬‬
‫ﺟﺰء ﺻﺤﻴﺢ )‪math.floor(number‬‬
‫رﻳﺸﻪ دوم ﺑﺪون در ﻧﻈﺮ ﮔﺮﻓﺘﻦ اﻋﺪاد ﻣﻨﻔﻲ )‪math.sqrt(number‬‬
‫‪x^y‬ﺑﻪ ﭘﻴﻤﺎﻧﻪ ‪pow(x, y[, z]) z‬‬
‫ﮔﺮﻓﺘﻦ ورودي ﺑﻪ ﻋﻨﻮان ﻳﻚ رﺷﺘﻪ )‪raw_input(prompt‬‬
‫ﺑﺮﮔﺮداﻧﺪن ﻧﻤﺎﻳﺶ رﺷﺘﻪ اي ﻳﻚ ﺷﻲ )‪repr(object‬‬
‫رﻧﺪ ﻳﻚ ﻋﺪد ﺑﺎ دﻗﺖ دﻟﺨﻮاه )]‪round(number[, ndigits‬‬
‫تبديل يک مقدار به يک رشته )‪str(object‬‬
‫ﻛﻤﻲ ﭘﺎﻳﺘﻮن‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫ﻟﻴﺴﺘﻬﺎ‬
‫]‪c=[1,’hello’,3,4,5,6‬‬
‫]‪c[0], c[1], c[2], c[3],c[-1‬‬
‫‪1, ’hello’,3,4,6‬‬
‫]‪c[0:2‬‬
‫’‪1, ’hello‬‬
‫]‪c[2:‬‬
‫]‪[3,4,5,6‬‬
‫]‪c[:2‬‬
‫اﻧﺪﻳﺲ ﮔﺬاري ﭘﺎﻳﺘﻮن از ﺻﻔﺮ ﺷﺮوع ﻣﻲ ﺷﻮد‬
‫ﻟﻴﺴﺘﻬﺎ‬
c=[n^3 for n in range (1,6)]
[1, 8, 27, 64, 125]
cd=[n**3/2 for n in range (1,6)]
[0, 4, 13, 32, 62]
7 in cd
False
‫ﺣﻠﻘﻪ ﻫﺎ‬
x=1
while x<100:
print x, '\t',x**2
x=x+3
for letter in 'Python':
fruits = ['banana', 'apple', 'mango']
for fruit in fruits:
Print ‘1’
while ‫• ﺣﻠﻘﻪ‬
‫؟‬while ‫• اﺗﻤﺎم‬
‫ﺣﻠﻘﻪ ﻫﺎ‬
for num in range(10,20):
for i in range(2,num):
if num%i == 0:
j=num/i
print '%d equals %d * %d' (num,i,j)
break
else:
print(‘prime number’)
‫ﮔﺮاف‬
‫)}]‪G=Graph({0:[1,2,3], 2:[4‬‬
‫)}}"‪G=Graph({0:{1:"x",2:"z",3:"a"}, 2:{5:"out‬‬
‫ﺗﻌﺮﻳﻒ دو ﮔﺮاف ﻳﻜﻲ ﺑﻪ ﺻﻮرت ﺳﺎده و دﻳﮕﺮي ﻟﻴﺒﻞ دار‬
‫‪x,z,a,out‬‬
‫)])‪G = Graph([(1,3,"Label"),(3,8,"Or"),(5,2‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪ‬
‫ﮔﺮاف ﻣﺎﺗﺮﻳﺲ ﻫﺎ‬
‫ﻣﺎﺗﺮﻳﺲ ﻣﺠﺎورت )ﻣﺎﺗﺮﻳﺲ ﺑﺎﻳﺪ ﻣﺠﺎورت ﺑﺎﺷﺪ!(‬
‫)]]‪M=Matrix([[0,1,1,0],[1,0,1,1],[1,1,0,1],[0,1,1,0‬‬
‫)‪G = Graph(M‬‬
‫)(‪G.show‬‬
‫ﻣﺎﺗﺮﻳﺲ وﻗﻮع‬
‫)]]‪N=Matrix([[-1,-1,0,0,0],[1,0,-1,-1,0],[0,1,1,0,-1], [0,0,0,1,1‬‬
‫)'‪H=Graph(N, format='incidence_matrix‬‬
‫)(‪H.show‬‬
‫)(‪I = G.incidence_matrix‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫اﺧﺘﻴﺎرات در ﮔﺮاﻓﻬﺎ‬
•
•
•
•
•
•
•
•
•
G.show(edge_labels=True)
Graph(M,(multiedges = True))
G= copy(H)
g.plot(graph_border=True).save('graph.pdf')
g.edges()
g.vertices()
g.plot(layout='circular')
g.plot(layout='tree')
g.plot3d()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫اﺳﺘﻔﺎده از ﮔﺮاﻓﻬﺎي ﭘﻴﺶ ﻓﺮض‬
‫ﺧﻮد ‪ sage‬ﮔﺮاﻓﻬﺎي ﺑﺴﻴﺎري را ﺑﻪ ﺻﻮرت از ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪه در ﺑﺮ دارد‪.‬‬
‫ﺑﺮاي اﻳﻨﻜﺎر ﻛﺎﻓﻴﺴﺖ از دﺳﺘﻮري ﻣﺜﻞ‬
‫)(‪graphs.PetersenGraph‬‬
‫اﺳﺘﻔﺎده ﻛﻨﻴﻢ‪ .‬ﻛﻪ اﻟﺒﺘﻪ ﻣﻲ ﺗﻮاﻧﻴﺪ ﺑﻪ ﺟﺎي ‪ PetersenGraph‬اﺳﻢ ﮔﺮاف‬
‫ﻣﻮرد ﻧﻈﺮ را ﺑﻴﺎورﻳﺪ‪.‬‬
‫اﮔﺮ اﺳﻤﺶ را ﻧﻤﻲ داﻧﻴﺪ ﻛﺎﻓﻴﺴﺖ ﺑﻌﺪ از ‪ graphs.‬ﻳﻚ ‪ Tab‬ﺑﺰﻧﻴﺪ‪ .‬از‬
‫ﻟﻴﺴﺖ ﻳﻜﻲ را اﻧﺘﺨﺎب ﻛﻨﻴﺪ‪.‬‬
‫)ﻣﻌﻤﻮﻻ ﻛﻠﻴﺪﻫﺎي ﻣﻴﺎﻧﺒﺮ در ‪ internet explorer‬ﻛﺎر ﻧﻤﻲ ﻛﻨﻨﺪ(‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﺗﺒﺪﻳﻼت‬
G.to_directed()
G.to_undirected()
G.sparse6_string()
G.graph6_string()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫ﺿﺮب ﻫﺎ‬
• G.strong_product(H)
• G.tensor_product(H)
• G.categorical_product(H)
• G.disjunctive_product(H)
• G.lexicographic_product(H)
• G.cartesian_product(H)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
• G.is_tree()
‫ﺳﻮاﻻت ﺑﻠﻪ ﺧﻴﺮ‬
• G.is_forest()
• G.is_gallai_tree()
• G.is_interval()
• G.is_regular()
• G.is_chordal()
• G.is_eulerian()
• G.is_hamiltonian()
• G.is_interval()
• G.is_independent_set([vertices])
• G.is_overfull()
‫•ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫ﻣﺪرس‬
– ‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم‬
G.is_regular(k)
‫ﻧﺎورداﻫﺎي راﻳﺞ‬
• G.diameter()
• G.average_distance()
• G.edge_disjoint_spanning_trees(k)
• G.girth()
• G.size()
• G.order()
• G.radius()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫رﻧﮓ آﻣﻴﺰي ﮔﺮاﻓﻬﺎ‬
• G.chromatic_polynomial()
• G.chromatic_number(algorithm="DLX")
You can change DLX (dancing links) to CP (chromatic polynomial
coecients) or MILP (mixed integer linear program)
• G.coloring(algorithm="DLX")
You can change DLX to MILP
• G.is_perfect(certificate=False)’
• G.tutte_polynomial()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
•
•
•
•
•
‫ﻣﺴﻄﺢ ﺑﻮدن‬
G.is_planar()
G.is_circular_planar()
G.is_drawn_free_of_edge_crossings()
G.layout_planar(test=True, set_embedding=True)
G.set_planar_positions()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫ﺟﺴﺘﺠﻮﻫﺎ و ﻛﻮﺗﺎﻫﺘﺮﻳﻦ ﻣﺴﻴﺮ‬
• list(G.depth_first_search([vertices], distance=4)
• list(G.breadth_first_search([vertices])
• pred = graph.shortest_path_all_pairs(by_weight)
Choice of algorithms: BFS or Floyd-Warshall-Python
• G.shortest_path_length(v_1,v_2, by_weight=True)
• G.shortest_path_lengths(v_1)
• G.shortest_path(v_1,v_2)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
•
•
•
•
‫درﺧﺖ ﻓﺮاﮔﻴﺮ‬
G.steiner_tree(g.vertices()[:10])
G.spanning_trees_count()
G.edge_disjoint_spanning_trees(2, root vertex)
G.min_spanning_tree(weight_function=somefunctio
n, algorithm='Kruskal',starting_vertex=3)
Kruskal can be change to Prim fringe, Prim edge, or NetworkX
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
•
•
•
•
•
•
Matrices
G.kirchhoff_matrix()
G.laplacian_matrix()
G.weighted_adjacency_matrix()
G.adjacency_matrix()
G.incidence_matrix()
•
•
•
•
•
G.characteristic_polynomial()
G.cycle_basis()
G.spectrum()
G.eigenspaces(laplacian=True)
G.eigenvectors(laplacian=True)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫ﺟﺒﺮ ﮔﺮاﻓﻬﺎ‬
‫اﺗﻮﻣﻮرﻓﻴﺴﻢ ﻫﺎ و اﻳﺰوﻣﻮرﻓﻴﺴﻢ ﻫﺎ‬
•
•
•
•
•
G.automorphism_group()
G.is_isomorphic(H)
G.is_vertex_transitive()
G.canonical_label()
G.minor(graph of minor to find)
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫ﺗﺤﻠﻴﻞ ﻛﻠﻴﻚ ﻫﺎ‬
• G.is_clique([vertices])
• G.cliques_vertex_clique_number(vertices=[(0, 1), (1,
2)],algorithm="networkx")
networkx can be replaced with cliquer.
•
•
•
•
•
•
G.cliques_number_of()
G.cliques_maximum()
G.cliques_maximal()
G.cliques_get_max_clique_graph()
G.cliques_get_clique_bipartite()
G.cliques_containing_vertex()
• G.clique_number(algorithm="cliquer")
cliquer can be replaced with networkx.
• G.clique_maximum()
• G.clique_complex()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫ﻫﻤﺒﻨﺪي در ﮔﺮاﻓﻬﺎ‬
•
•
•
•
•
•
•
•
•
G.is_connected()
G.connected_component_containing_vertex(vertex)
G.connected_components_number()
G.connected_components_subgraphs()
G.strong_orientation()
G.strongly_connected_components()
G.strongly_connected_components_digraph()
G.strongly_connected_components_subgraphs()
G.strongly_connected_component_containing_vertex(v
ertex)
• G.is_strongly_connected()
‫ ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
‫ﻣﺴﺎﺋﻞ ‪NP‬‬
‫)'‪• G.vertex_cover(algorithm='Cliquer‬‬
‫ﭘﻮﺷﺶ رأﺳﻲ‬
‫ﺗﻮﺟﻪ داﺷﺘﻪ ﺑﺎﺷﻴﺪ ﻛﻪ ﻣﻲ ﺗﻮاﻧﻴﺪ از اﻟﮕﻮرﻳﺘﻢ )‪MILP(mixed integer linear program‬‬
‫ﻧﻴﺰ اﺳﺘﻔﺎده ﻛﻨﻴﺪ )ﺑﺎﻳﺴﺘﻲ ﺑﺴﺘﻪ ‪ GLPK‬ﻳﺎ ‪ CBC‬را ﻓﺮاﺧﻮاﻧﻲ ﻛﻨﻴﺪ(‬
‫)(‪• G.hamiltonian_cycle‬‬
‫ﻳﺎﻓﺘﻦ دور ﻫﻤﻴﻠﺘﻮﻧﻲ‬
‫)(‪• G.traveling_salesman_problem‬‬
‫ﻣﺴﺄﻟﻪ ﻓﺮوﺷﻨﺪه دوره ﮔﺮد‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﺗﻐﻴﻴﺮات ﺑﻪ ﺻﻮرت ﮔﺮاﻓﻴﻜﻲ در ﮔﺮاف‬
‫=‪g‬‬
‫)}]‪Graph({0:[1,2,3],1:[0],2:[0,4,4],3:[0,4],4:[2,2,3,6],5:[6],6:[4,8,5],7:[],8:[6‬‬
‫‪g.set_pos({0:[79,139],1:[45,44.4],2:[183.85,296.907],3:[284.3617‬‬
‫[‪,145.2],4:[226,193],5:[256.015,301],6:[242,239],7:[273,221],8:‬‬
‫)}]‪293,303‬‬
‫اﮔﺮ ﻫﻢ اﻳﻦ ﻫﻤﻪ دﺳﺘﻮر را ﻧﻤﻲ ﺧﻮاﻫﻴﺪ وارد ﻛﻨﻴﺪ )(‪g.get_pos‬‬
‫)‪graph_editor(g‬‬
‫• اوﻟﻴﻦ دﺳﺘﻮر ﮔﺮاف را ﺗﻌﺮﻳﻒ ﻣﻲ ﻛﻨﺪ‪.‬‬
‫• دوﻣﻴﻦ دﺳﺘﻮر ﻣﻮﻗﻌﻴﺖ ﻫﺮ رأس را ﻣﺸﺨﺺ ﻣﻲ ﻧﻤﺎﻳﺪ‪.‬‬
‫• ﺳﻮﻣﻴﻦ دﺳﺘﻮر وﻳﺮاﻳﺸﮕﺮ را ﻓﺮاﺧﻮاﻧﻲ ﻣﻲ ﻛﻨﺪ‪.‬‬
‫ﺗﻮﺟﻪ ﻛﻨﻴﺪ ﻣﻲ ﺗﻮاﻧﻴﺪ ﺑﺎ ﻳﻚ ﮔﺮاف ﺳﺎده ﺷﺮوع ﻛﻨﻴﺪ و ﮔﺮاف ﻣﻮرد ﻧﻈﺮ ﺧﻮد را ﻣﺮﺣﻠﻪ ﺑﻪ ﻣﺮﺣﻠﻪ‬
‫ﺑﺴﺎزﻳﺪ‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﺗﻐﻴﻴﺮات ﺑﻪ ﺻﻮرت ﮔﺮاﻓﻴﻜﻲ در ﮔﺮاف‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫•‬
‫ﺑﺎ د‪‬ﺑِﻞ ﻛﻠﻴﻚ روي ﻳﻚ ﻓﻀﺎي ﺧﺎﻟﻲ ﻣﻲ ﺗﻮاﻧﻴﺪ ﻳﻚ رأس ﺟﺪﻳﺪ اﺿﺎﻓﻪ ﻛﻨﻴﺪ‪.‬‬
‫رأﺳﻬﺎ را ﻣﻲ ﺗﻮاﻧﻴﺪ ﺑﺎ ﻣﺎوس ﺣﺮﻛﺖ دﻫﻴﺪ‬
‫ﺑﺎ اﻧﺘﺨﺎب ﻳﻚ رأس و ﺳﭙﺲ رأس دﻳﮕﺮ ﻣﻲ ﺗﻮاﻧﻴﺪ ﻳﺎل ﻣﻮرد ﻧﻈﺮ ﺧﻮد را ﺑﻜﺸﻴﺪ‪.‬‬
‫ﺑﺎ اﻧﺠﺎم ﻣﺮﺣﻠﻪ ﻗﺒﻞ روي ﻳﻚ ﻳﺎل از ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪه ﻳﺎل ﻣﻮرد ﻧﻈﺮ ﺣﺬف ﻣﻲ ﺷﻮد‪.‬‬
‫اﮔﺮ ﻳﻚ رأس ﺗﻨﻬﺎ ﭘﺲ از ﺣﺬف ﻳﺎﻟﺶ ﺣﺬف ﻣﻲ ﺷﻮد‪ ،‬ﺑﺎ ﻧﮕﻬﺪاﺷﺘﻦ ﻛﻠﻴﺪ ‪shift‬‬
‫از اﻳﻨﻜﺎر ﺟﻠﻮﮔﻴﺮي ﻛﻨﻴﺪ )اﻟﺒﺘﻪ اﮔﺮ ﺧﻮاﺳﺘﻴﺪ!(‬
‫ﺑﺎ دوﺑﺎر ﻛﻠﻴﻚ ﻛﺮدن روي ﻳﻚ رأس‪ ،‬آن را ﺣﺬف ﻛﺮده اﻳﺪ‪.‬‬
‫ﺑﺎ زدن دﻛﻤﻪ ‪ save‬ﮔﺮاف ﻣﻮرد ﻧﻈﺮ ﺷﻤﺎ داﺧﻞ ﺳﻠﻮﻟﻲ ﻛﻪ در اﺑﺘﺪا ﮔﺮاف را در آن‬
‫ﺗﻌﺮﻳﻒ ﻛﺮده ﺑﻮدﻳﺪ ﻗﺎﺑﻞ ﻣﺸﺎﻫﺪه اﺳﺖ‪.‬‬
‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‪ :‬ﻣﻴﺜﻢ ﻣﺪﻧﻲ‬
‫ﺗﻬﻴﻪ ﺟﺪول‬
.‫ راس در اﻳﻦ ﺟﺪوﻟﻬﺎ ﻗﺎﺑﻞ ﺑﺎزﺧﻮاﻧﻲ ﻫﺴﺘﻨﺪ‬7 ‫ﺗﻤﺎم ﮔﺮاف ﻫﺎي ﺑﺎ ﺣﺪاﻛﺜﺮ‬
gdb = GraphDatabase()
graph_db_info(tablename='graph_data')
['complement_graph6', 'eulerian', 'graph6', 'lovasz_number',
'num_cycles', 'num_edges', 'num_hamiltonian_cycles', 'num_vertices',
'perfect', 'planar']
‫ ﻣﺮﺗﺐ ﺑﺮ اﺳﺎس درﺟﻪ‬1 ‫ﺗﻬﻴﻪ ﺟﺪوﻟﻲ از ﮔﺮاف ﻫﺎ ﺑﺎ ﻛﻤﺘﺮ ﻣﺴﺎوي ﻳﺎل و ﺣﺪاﻗﻞ درﺟﻪ‬
Q =GraphQuery(display_cols=['graph6','num_vertices','degree_sequence'],
num_edges=['<=',5],min_degree=1)
Q.show(with_picture=True)
Q.number_of()
‫ ﻣﻴﺜﻢ ﻣﺪ‬:‫آزﻣﺎﻳﺸﮕﺎه رﻳﺎﺿﻲ – درس ﭼﻬﺎرم – ﻣﺪرس‬
WHICH IS THE BEST?





Fortran, Java, C++, …
Matlab and Mathematica
GraphTheory Package In Maple
iGraph in R, C and …
Sage
Thank You