igraph网络分析库(C语言接口)
展开阅读
展开阅读
git clone https://github.com/igraph/igraph
cd igraph
./bootstrap.sh
./configure --prefix=$MY_LOCAL
make
make install
export CPATH="$MY_LOCAL/include:$CPATH"
export LD_LIBRARY_PATH="$MY_LOCAL/lib:$LD_LIBRARY_PATH"
以下代码创建了一个6个节点的空图,添加了8条边,又添加了2个节点和4条边
%:include <igraph/igraph.h>
int main(void)
{
igraph_t graph;
igraph_vector_t edges;
igraph_real_t data[] = {0,1,0,2,0,5,1,2,1,4,2,4,1,3,3,5};
igraph_vector_view(&edges, data, sizeof(data)/sizeof(double));
igraph_empty(&graph, 6, IGRAPH_UNDIRECTED);
igraph_add_edges(&graph, &edges, 0);
igraph_add_vertices(&graph, 2, 0);
igraph_add_edge(&graph, 6,4);
igraph_add_edge(&graph, 6,5);
igraph_add_edge(&graph, 7,5);
igraph_add_edge(&graph, 7,3);
printf("vertices: %d, edges: %d\n", (int)igraph_vcount(&graph), (int)igraph_ecount(&graph));
igraph_destroy(&graph);
return 0;
}
使用如下命令编译
gcc test.c -ligraph
展开阅读
batch_size
与learning_rate
成正比
展开阅读
; (cs) ~ code (ds) ~ data (ss) ~ stack
assume cs:code, ds:data, ss:stack
; 编译完后:
; ds:0 ~ ds+10h:0存放程序段前缀(PSP)
; cs:ip初始化为地址标号main
; data段从ds+10h:0开始,注意此时ds不指向data段
data segment ; data是一个地址标号
; db: define byte dw: define word dd: define double word
str db 'Hello World$' ; str是一个数据标号
; ((cs)<<4 + 0) ~ ((cs)<<4 + 11) = 'Hello World$'
arr dw 0123h, 0234h, 0345h, 0456h
; ((cs)<<4 + 12) = 0123h
; ((cs)<<4 + 14) = 0234h
; ((cs)<<4 + 16) = 0345h
; ((cs)<<4 + 18) = 0456h
; 数据的直接定址表
addr dd str, arr
; offset操作符取标号的偏移地址,seg操作符取标号的段地址
; 等价于addr dw offset str, seg a, offset b, seg b
table dw main, sub ; 子程序的直接定址表
data ends
stack segment
; 初始值为0的容量为256个字单元的栈段,初始栈顶(sp)=100h
dw 256 dup (0)
stack ends
code segment
main:
;;; 初始化栈段
mov ax, stack
mov ss, ax
mov sp, 100h
; 栈操作
push ax ; (sp)=(sp)-2 ((ss)<<4 + (sp)) = (ax)
pop bx ; (ax) = ((ss)<<4 + (sp)) (sp)=(sp)+2
pushf ; push flags
popf ; pop flags 可以用于修改标志寄存器
;;; 初始化数据段
mov ax, data
mov ds, ax
mov bx, 0
;;; 使用assume和以上初始化代码设置好数据段后可以使用数据标号访问数据,不能使用地址标号访问另一个段的数据
mov al, str[si] ; mov al, ds:[si]
add arr, ax ; add ds:[12], ax 代表单元arr可指示单元大小
;;; 常见运算
add ax, 1 ; (ax) += 1
add al, bl
adc ah, bh ; 带进位加法,这两条指令等价于add ax,bx
sub ax, 1 ; (ax) -= 1
sub al, bl
sbb ah, bh ; 带借位减法,这两条指令等价于sub ax,bx
and ax, 011b ; (ax) &= 011b
or ax, 011b ; (ax) |= 011b
inc ax ; (ax) = (ax) + 1
dec ax ; (ax) = (ax) - 1
div byte ptr [bx] ; (al) = (ax)//((ds)<<4 + (bx)) (ah) = (ax)%((ds)<<4 + (bx))
div word ptr [bx] ; (ax) = ((dx)*10000h + (ax))//((ds)<<4 + (bx)) (ax) = ((dx)*10000h + (ax))%((ds)<<4 + (bx))
mul byte ptr [bx] ; (ax) *= ((ds)<<4 + (bx))
mul word ptr [bx] ; (dx)*10000h + (ax) = (ax) * ((ds)<<4 + (bx))
; 逻辑移位
mov al,01010001b
mov cl,3 ; 必须用cl设置移位位数
shr al,cl ; 右移,左移是shl
;;; 内存访问使用ds和bx
mov ax, [0ffffh] ; 警告:含义不明(ax) = ffffh 首位为f时必须加0
mov al, ds:[0] ; (al) = ((ds)<<4 + 0) 直接寻址
mov al, [bx] ; 同上
mov al, ds:[bx] ; 同上
mov al, [bp] ; (al) = ((ss)<<4 + (bp)) 栈段寻址用bp
mov [bx], al ; ((ds)<<4 + (bx)) = (al) 寄存器间接寻址
mov [bx], ax ; ((ds)<<4 + (bx)) = (al) ((ds)<<4 + (bx) + 1) = (ah) 小心高位覆盖
mov ax, [2+bx] ; (ax) = ((ds)<<4 + (bx) + 2) 寄存器相对寻址(结构体[bx].idata,数组idata[si])
mov ax, 2[bx] ; 同上
mov ax, [bx].2 ; 同上
mov ax, [bx+si] ; (ax) = ((ds)<<4 + (bx) + (si)) 基址变址寻址(二维数组[bx][si])
mov ax, [bx][si] ; 同上
mov ax, [bx+si+2] ; (ax) = ((ds)<<4 + (bx) + (si) + 2) 相对基址变址寻址(表格中的数组[bx].idata[si],二维数组idata[bx][si]
mov ax, 2[bx][si] ; 同上
mov ax, [bx].2[si] ; 同上
mov ax, [bx][si].2 ; 同上
;;; 标号偏移地址可进行立即数运算
mov ax, offset main - offset data ; main, data都是地址标号
;;; 串传送指令
cld ; (df) = 0 向右传送, clear direction
std ; (df) = 1 向左传送, set direction
mov cx, 8 ; 根据(df)从(ds)段复制8个字节到(es)段,(df)=0时(si),(di)++,(df)=1时--
rep movsb ; s:movsb, loop s
mov cx, 8 ; 根据(df)从(ds)段复制8个字到(es)段,(df)=0时(si),(di)++,(df)=1时--
rep movsw ; s:movsw, loop s
;;; 循环
mov cx, 10 ; 使用cx设定循环次数
s: ; 循环体
inc ax
loop s ; (cx) -= 1 if (cx) == 0: then (cs) = seg s (ip) = offset s
;;; 无条件跳转jmp, 有条件跳转jcxz(jmp if cx is zero)
jmp short main ; 8位转移 (ip) += main - (ip_next)
jmp near main ; 16位段内转移
jmp far main ; 段间转移,指令机器码包含段地址和偏移地址 (cs)=seg main (ip)=offset main
jmp ax ; (ip) = (ax)
jmp word ptr [bx] ; (ip) = ((ds)<<4 + (bx))
jmp dword ptr [bx] ; (ip) = ((ds)<<4 + (bx)) (cs) = ((ds)<<4 + (bx) + 2)
jcxz main ; if (cx)==0: then jmp short main
cmp ax, bx ; 计算(ax)-(bx),比较结果用(zf)和(cf)表示
; 以下跳转指令检测无符号数cmp指令比较结果
je main ; (ax)==(bx)
jne main ; (ax)!=(bx)
jb main ; (ax)<(bx)
jnb main ; (ax)>=(bx)
ja main ; (ax)>(bx)
jna main ; (ax)<=(bx)
;;; 调用子程序call
call sub ; push IP, jmp near ptr sub
; call far ptr sub ; push CS, push IP, jmp far ptr sub
call ax ; push IP, jmp ax
call word ptr [bx] ; push IP, jmp word ptr [bx]
call dword ptr [bx] ; push CS, push IP, jmp dword [bx]
;;; 设置中断向量
mov ax, 0 ; 中断向量表的段为0
mov es, ax
; 字单元 0:n*4 保存n号中断向量偏移地址
mov word ptr es:[0*4], offset sub
; 字单元 0:n*4 + 2 保存n号中断向量段地址
mov word ptr es:[0*4+2], seg sub
;;; 可屏蔽外中断
sti ; (if)=1
cli ; (if)=0
;;; 从CMOS RAM时钟信息中读取当前分钟
mov al, 2 ; 选中2号CMOS RAM
out 70h, al ; 在CMOS端口写入2
in al, 71h ; 从CMOS端口读出数据(BCD码),0号对应秒,2号对应分,4号对应时,7号对应日,8号对应月,9号对应年
;;; 打印字符串
mov ax,data
mov ds,ax ; 设置数据段
mov dx,0 ; 设置打印起始位置偏移地址
mov ah,9 ; 参数9对应打印的中断子程序
int 21h ; 触发中断,打印到'$'为止
mov ah, 4ch ; 参数4ch对应程序返回的中断子程序
mov al, 0 ; 返回值
int 21h ; 引发21h号中断,返回dos
; 子程序保存恢复现场, 返回ret ref
sub:
push cx ; 保存寄存器,入栈
nop ; 1B的指令,什么也不干
pop cx ; 恢复寄存器,出栈
ret ; pop IP
; retf ; pop IP, pop CS
; iret ; 中断程序返回pop IP, pop CS, popf
code ends ; end segment
end main ; end main表示程序入口为main段
打开dosbox,输入以下命令
mount c E:\learn_asm
c:
masm filename;
link filename;
debug filename.exe
? ; 显示帮助信息
r ; 显示寄存器内容
r ax ; 修改寄存器ax内容
d ds:0 8 ; 从((ds)<<4+0)开始打印内存内容,打印到8
e ds:0 12 23 ; 从((ds)<<4+0)开始修改内存内容,输入12 23(16进制)
t ; 运行一步
p ; 运行一步(不进入)
g cs:0 8 ; 从代码段((cs)<<4+0)开始运行,运行到8
h ax bx ; 输出16进制加减((ax)+(bx))和((ax)-(bx))
u cs:0 8 ; 反编译,从((cs)<<4+0)到8
a cs:0 ; 从((cs)<<4 + 0) 开始输入汇编指令,并写入内存
q ; 退出
; 标志寄存器表示
of(OV, NV)
sf(NG, PL)
zf(ZR, NZ)
pf(PE, PO)
cf(CY, NC)
df(DN, UP)
寄存器(reg):ax,bx,cx,dx,ah,al,bh,hl,ch,cl,dh,dl,sp,bp,si,di
段寄存器(sreg):ds,ss,cs,es
标志寄存器(flags):zf(zero flag), pf(parity flag), sf(sign flag), cf(carry flag无符号数), of(overflow flag有符号数), df(direction flag), 单步中断(类型码为1)标志tf(trap flag), 可屏蔽外中断使能标志if(interrupt enable flag)
ds:数据段寄存器; ss:栈段寄存器;es,ds和ss只能用通用寄存器赋值; cs:代码段寄存器,只能用jmp修改; ip:代码偏移地址寄存器,不能赋值,只能用loop修改; sp:栈顶偏移地址寄存器,可以用立即数赋值; cx:loop指令的计数器; bx,si,di:数据段偏移地址; bp:栈段偏移地址; si,di:偏移地址增量
新建文件upper_lower.asm
,内容如下
include \masm32\include\masm32rt.inc
assume cs:codesg,ds:datasg
datasg segment
a db 'BaSiC',10,0
b db 'iNfOrMaTiOn',10,0
datasg ends
codesg segment
start:
mov ebx, offset a ; first string
mov ecx,5
s:
mov al,[ebx]
and al,11011111b ; lower to upper
mov [ebx],al
inc ebx
loop s
mov ebx, offset b ; second string
mov ecx,11
s0:
mov al,[ebx]
or al,00100000b ; upper to lower
mov [ebx],al
inc ebx
loop s0
call main
exit
main proc
cls
print offset a
print offset b
ret
main endp
codesg ends
end start
在www.masm32.com上下载编译器并安装,新建文件makeit.bat
,内容如下:
@echo off
if exist "upper_lower.obj" del "upper_lower.obj"
if exist "upper_lower.exe" del "upper_lower.exe"
\masm32\bin\ml /c /coff "upper_lower.asm"
if errorlevel 1 goto errasm
\masm32\bin\PoLink /SUBSYSTEM:CONSOLE "upper_lower.obj"
if errorlevel 1 goto errlink
dir "upper_lower.*"
goto TheEnd
:errlink
echo _
echo Link error
goto TheEnd
:errasm
echo _
echo Assembly Error
goto TheEnd
:TheEnd
pause
双击文件即可编译,在工作目录下Ctrl+L,输入cmd,输入upper_lower回车即可看到运行结果
gcc -Wa,-adhln -g source_code.c > assembly_list.lst
参数说明:
-g: 生成debug信息
-Wa,option: 把`option`作为参数传给汇编器
-adhln:
a: 生成列表
d: 忽略debug指令
n: 忽略列表处理
h: 包含高级语言代码include high-level source
l: 包含汇编代码
展开阅读
图 $S$ 和图 $G$ 的子图有哪些同构的问题可以看成一个约束满足问题(CSP) $\mathcal{\langle X,D,C\rangle}$ ,CSP的详细定义见:约束规划,约束传播和CSP问题
简单地说,图 $S$ 在 $G$ 中的嵌入(embedding) $f:V(S)\to V(G)$ 满足
(1) $\nexists v_1,v_2\in V(S), v_1\neq v_2,f(v_1)=f(v_2)$ ,
(2) $\forall e=(v_1,v_2)\in E(S), f(e)=(f(v_1),f(v_2))\in E(G)$ ,
(3) $\forall e\notin E(S), f(e)\notin E(G)$ ,
是 $S$ 和 $G$ 的某个子图的同构
$S$ 的每个结点 $v\in V(S)$ 都对应一个变量 $X(v)$ ,因此可以定义双射 $X:V(S)\to \mathcal X$ ,变量集 $\mathcal X=X(V(S))$
每个结点 $v\in V(S)$ 的嵌入一定是 $G$ 中的结点 $u\in V(G)$ ,因此变量$X(v)$ 对应的域为 $D(X(v))=V(G)$ ,域集 $\mathcal D=D(\mathcal X)$
由条件(1)知,有约束条件 $\mathtt{Alldifferent}(X(V(S))$
由条件(2)知,对 $\forall (v_1,v_2)\in E(S)$ ,有约束条件 $\mathtt{AllowedAssignments}((X(v_1),X(v_2)), E(G))$
由条件(3)知,对 $\forall (v_1,v_2)\notin E(S)$ ,有约束条件 $\mathtt{ForbiddenAssignments}((X(v_1),X(v_2)), E(G))$
综合以上3种约束,有约束集 $\mathcal C=\{\mathtt{Alldifferent}(X(V(S))\}\cup \\ \{ \mathtt{AllowedAssignments}((X(v_1),X(v_2)), E(G)): \forall (v_1,v_2)\in E(S)\}\cup \\ \{\mathtt{ForbiddenAssignments}((X(v_1),X(v_2)), E(G)):\forall (v_1,v_2)\notin E(S)\}$
我们已经把子图同构对应的CSP问题$\mathcal{\langle X,D,C\rangle}$表示成了标准形式,因此可以使用求解器进行求解
OR-tools是谷歌开源的运筹学求解器库,详细介绍见:使用谷歌的OR-Tools求解鸡兔同笼
networkx是python的一个图算法库,详细介绍见:python常用代码的第12和13节
以下代码使用OR-tools和networkx求解子图同构问题:
import networkx as nx
from ortools.sat.python import cp_model
from itertools import combinations
def var_from_domain(model, name, domain):
"initialize a variable with integer domain defined by domain"
domain = cp_model.Domain.FromIntervals([[i] for i in domain])
val = model.NewIntVarFromDomain(domain, name)
return val
# 五角星
G=nx.Graph([(1,3),(1,4),(2,4),(2,5),(3,5)])
# 五边形
S=nx.Graph([(1,2),(2,3),(3,4),(4,5),(5,1)])
model = cp_model.CpModel()
D = list(G.nodes)
X = {i:var_from_domain(model, "X("+str(i)+")", D) for i in S.nodes}
# 约束:嵌入 S -> subgraph of G
model.AddAllDifferent([X[i] for i in S.nodes])
E_G = list(G.edges) + [e[::-1] for e in G.edges]
for v1, v2 in combinations(S.nodes,2):
if (v1,v2) in S.edges:
model.AddAllowedAssignments((X[v1],X[v2]), E_G)
else:
model.AddForbiddenAssignments((X[v1],X[v2]), E_G)
solver = cp_model.CpSolver()
status = solver.Solve(model)
if status == cp_model.FEASIBLE:
print("有嵌入:")
for v, x in X.items():
print('f(%s)=%i' % (v, solver.Value(x)))
else:
print("不存在子图同构")
展开阅读
申请gpu分区的5G内存资源并打开bash
srun --partition=gpu --mem=5G --pty bash
编写任务脚本submit.sh
#!/bin/bash
#
#SBATCH --job-name=eit
#SBATCH --output=log.txt
#
#SBATCH --ntasks=1
#SBATCH --time=30:00
#SBATCH --partition=gpu
#SBATCH --mem=15G
#SBATCH --mem-per-gpu=10G
#SBATCH --gres=gpu:1
module load gcc/8.1.0
module load cmake/3.13.4
module load python/3.7.1
export C_INCLUDE_PATH=/usr/local/cuda-10.0/include
export CPLUS_INCLUDE_PATH=/usr/local/cuda-10.0/include
export LIBRARY_PATH=/usr/local/cuda-10.0/lib64
cd EIT/EIT_train/
srun python train.py
提交任务
sbatch submit.sh
查看我的任务
squeue --user=$MY_NAME
取消我的任务
scancel -v $JOB_ID
查看任务详细信息
scontrol show job $JOB_ID
为了防止任务的标准输出流长期不刷新,可以使用以下命令
stdbuf -o0 -e0 command
print("hello",flush=True)
展开阅读
(适用于Sharp牌计算器,型号EL-W516TB-SL或EL-W991TL)
注意:如果设置角度模式为DEG,则所有三角函数的积分微分等都会受到影响
2ndF : second function 特殊计算(非10进制,组合,角度相关)
alpha: 变量常量,统计模式,积分求和
M-CLR: memory clear
CA: clear all
BS: backspace
arc hyp: arc(弧长) hyperbolic
hyp: hyperbolic
D° M'S: Degree Minute Second,复数模式下的虚单位
DRG>:角度转弧度
∠:复数模式下分隔模$r$和辐角$theta$
ABCDEFMXY: 寄存器,HEX模式下用于输入16进制数
, : 统计模式下一次输入两个数,积分输入步数n,求和输入步长,用于后续$\to r\theta$转换
D1 D2 D3:函数存储器,只能保存两次按键的函数
RCL: recall
STO: store
MDF: modify 修改真实值为显示值
M+: M+=?
M-: M-=?
INS-D: insert down
change/DATA: 显示统计模式下所有数据
MATH: 当前模式下所有常用的函数
MEMORY: 查看寄存器的值
x',y': 统计模式下要预测的变量
nCr, nPr, n!:组合数,排列数,全排列
CONV: 进制转换
Exp: 10^n
SIG: significant digits
TAB: decimal places
FSE: Fixed, Scientific, Engineering
SD: Single Dimension
ref: Row Echelon Form
rref: Reduced Row Echelon Form
2-VLE: 2 variable linear equation
K: 上次计算的值
常数:
1.光速
2.牛顿常数
3.重力加速度
4.电子质量
5.质子量
6.中子质量
7.μ介子质量
8.原子质量单位-千克关系
9.基本电荷
10.普朗克常数(h)
11.玻尔兹曼常数
12.磁常数
13.电常数
14.经典电子半径
15.精细结构常数
16.玻尔半径
17.里德伯常数
18.磁通量子
19.玻尔磁
20.电子磁矩
21.核磁
22.质子磁矩
23.中子磁矩
24.μ介子磁矩
25.康普顿波长
26.质子康普顿波长
27.斯蒂芬-玻尔兹曼常数
28.阿伏加德罗常数
29.理想气体摩尔体积
30.摩尔气体常数
31.法拉第常数
32.冯 克利青常数
33.电荷与质量商
34.循环量
35.质子旋磁比
36.约瑟夫森常数
37.电子伏特
38.摄氏温度
39.天文单位
40.秒差距
41.碳-12的摩尔质量
42.普朗克常数(h/(2pi))
43.哈特里能量
44.电导量子
45.反向精细结构常数
46.质子-电子质量比
47.摩尔质量常数
48.中子康普顿波长
49.第一辐射常数
50.第二辐射常数
51.真空的特性阻抗
52.标准大气压
单位:
in: inch
ft: foot
yd: yard
mi: mile
n mi: nautical mile
oz: ounce(avoirdupois)
lb: pound(avoirdupois)
gal:gallon
L: liter
fl oz: fluid ounce
cal_th: calorie
hp: horsepower
ps: horsepower(metric)
atm: atmosphere
展开阅读
A4纸长边对折,放入中性笔笔芯,将笔芯尾部与折痕处对齐,去掉头部多余的纸
将笔芯放入对折后的A4纸中,卷出一个笔杆,如果太厚可以去掉多余的纸
如果有胶水或胶带还可以把卷好的纸进一步固定
展开阅读
首先登录ent.uca.fr
然后点击SERVICES ANNEXES -> Impression,进入print.dsi.uca.fr网页
点击网络打印,上传文件(此时可以上传彩色文件,计费按彩色计费,因此会高于实际收费)
看到“已在打印队列中”时,上传成功,这里能看到计费
在大厅一楼打印机终端登录ENT账号,点击文件右侧的">",选择右下角的"recto/verso -> recto-verso"(双面打印),和"couleur -> niveaux de gris"(灰度打印),这里的计费才是最终的计费,正常灰度双面打印价格为0.023欧每面
设置完成后点击右下角的Imprimer打印文件
展开阅读
设置A4纸,字体大小为12pt,report格式(分章节,换页留白)
\documentclass[a4paper, 12pt]{report}
使用DeclareMathOperator, newtheorem, proof
\usepackage{amsmath, amsthm}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[chapter]
常用字体:花体mathscr, 加粗字体bm, 空心字体mathbb, 半空心字体mathbbm, 向量正粗字体mathbf,纽约时报体mathfrak,计科函数体mathtt,正圆体mathsf
\usepackage{mathrsfs, bm, amsfonts, amssymb, bbm}
常用package
\usepackage{color, xcolor} % 使用颜色
\usepackage[utf8]{inputenc} % 使用utf8编码
\usepackage{hyperref} % 使用\href, \url
\usepackage{enumitem} % 使用\enumerate
\usepackage{float} % 使用[H]标签,让图片和文字一起浮动
\usepackage{caption} % 使用\caption*
\usepackage[createtips]{fancytooltips} %在hyperref上悬浮显示预览内容
使用beamer
\documentclass[10pt,aspectratio=43,mathserif,handout]{beamer} % handout会去掉所有动态展示
\usepackage{multimedia, animate, algpseudocode} % beamer内置定理块
\usetheme{Berlin}
\title{Title}
\subtitle{\fontsize{9pt}{14pt}\textbf{subtitle}}
\author{Shitong CHAI}
\institute{ISIMA}
\date{\today}
\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{\textbf{table of contents}}
\tableofcontents[currentsection]
\end{frame}
}
\beamerdefaultoverlayspecification{<+->}
\begin{document}
\frame{\titlepage}
%\section{Table of contents}
%\begin{frame}{table of contents}
%\tableofcontents
%\end{frame}
\section{a section}
\begin{frame}[fragile,allowframebreaks]{incGM+} % 如果有lstlisting则必须添加fragile
\begin{algorithmic}[1]
\end{algorithmic}
\begin{lstlisting}[language=python, frame=single]
\end{lstlisting}
\end{frame}
\bibliography{bibtex}{}
\bibliographystyle{plain}
\end{document}
使用tikz
\usepackage{tikz}
\begin{document}
\begin{equation}
\begin{tikzpicture}
\node[shape=circle,draw=black] (A) at (0,0) {};
\node[shape=circle,draw=black] (B) at (0,1) {};
\node[shape=circle,draw=black] (C) at (1,0) {};
\node[shape=circle,draw=black] (D) at (1,1) {};
\path [-] (A) edge node {} (B);
\path [-] (B) edge node {} (C);
\path [-] (A) edge node {} (C);
\path [-] (B) edge node {} (D);
\end{tikzpicture}
\tag{$G$}
\end{equation}
\end{document}
使用lstlisting, lstset
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
breaklines=true,
}
% SPARQL:
% \lstset{language=SQL,morekeywords={PREFIX,java,rdf,rdfs,url}}
\begin{docuement}
\begin{lstlisting}[language=python, frame=single]
\end{lstlisting}
\end{document}
使用newtcblisting
\usepackage[most]{tcolorbox}
\newtcblisting{commandshell}{colback=white,colupper=black,colframe=black!75!black,
listing only,listing options={language=sh, breaklines=true,aboveskip=0pt, belowskip=0pt},
every listing line={\small\ttfamily\bfseries{[root@shchai]\$} }}
\newtcblisting{sqlshell}{colback=white,colupper=black,colframe=black!75!black,
listing only,listing options={language=SQL, breaklines=true, aboveskip=0pt, belowskip=0pt},
every listing line={\small\ttfamily\bfseries{SQL> }}}
\newtcblisting{messageshell}{colback=white,colupper=black,colframe=black!75!black,
listing only,listing options={language={}, basicstyle=\small\ttfamily, breaklines=true,aboveskip=0pt, belowskip=0pt},
every listing line={}}
\begin{docuement}
\begin{commandshell}
\end{commandshell}
\end{document}
使用algorithm, algorithmic
\usepackage[chapter]{algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{document}
\begin{algorithm}
\caption{DBSCAN}\label{euclid}
\begin{algorithmic}[1]
\Require Given parameter $\varepsilon,\mathcal{M}$ and $N_\varepsilon(i),i=1,2,\cdots,N$.
\Ensure $M=\{m_i\}_{i=1}^N$
\State $k=1;m_i=0,i=1,2,\cdots,N;$
\State $I=\{1,2,\cdots,N\}$;
\While{$I\neq \emptyset$}
\State Get an element $i$ from $I$, and let $I:=I\setminus\{i\}$;
\If{$m_i=0$}\Comment{If point i has not been visited.}
\State Initialize $T:=N_\varepsilon(i)$;
\If{$|T|<\mathcal{M}$}
\State $m_i=-1$;\Comment{Label point i as noise point}
\Else\Comment{If point i is a core point}
\State $m_i=k$;\Comment{Indicate point i belonging to $C_k$}
\While{$T\neq \emptyset$}
\State Get any element $j$ from $T$, let $T:=T\setminus\{j\}$;
\If{$m_j=0$ or $m_j=-1$}
\State $m_j=k$;
\EndIf
\If{$|N_\varepsilon(j)|\geq\mathcal{M}$}
\State{$T:=T\cup N_\varepsilon(j)$;}
\EndIf
\EndWhile
\State $k=k+1$;
\EndIf
\EndIf
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}
添加页眉和页脚
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{姓名}
\fancyhead[R]{\leftmark}
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
调节页边距
\usepackage{geometry}
\geometry{left=3cm, right=2.5cm, top=2.5cm, bottom=2.5cm}
添加图片
\usepackage{graphicx}
\graphicspath{{img/}}
\begin{document}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth,height=50mm]{}
\caption{Test Test Test}
\end{figure}
\end{document}
文档框架
\title{Report}
\date{}
\author{Shitong CHAI}
\begin{document}
\maketitle
\tableofcontents
\chapter {Something about report\cite{cortes1995support}}
\bibliography{bibtex}{}
\bibliographystyle{plain}
\end{document}
使用ifthen宏(whiledo, ifthenelse, value, setcounter, stepcounter),在宏中使用intcalcMod
\usepackage{ifthen}
\usepackage{intcalc, calc}
\newcounter{i}
\begin{document}
\begin{figure}[H]
% 以下代码把图片目录下的0.png-36.png以每行四张的格式平铺成一张图
\centering
\begin{tabular}{c p{3cm}p{3cm}clc}
\setcounter{i}{0}
\whiledo{\value{i} < 37} {
\includegraphics[width=0.13\textwidth]{\thei}
\ifthenelse{\intcalcMod{\value{i}}{4} = 3}{\\}{&}
\stepcounter{i}
}
\end{tabular}
\caption{Frequent patterns generated ($\tau=7$)}
\end{figure}
\end{document}
更改页码样式
% 正文中
\setcounter{page}{2}
\renewcommand{\thepage}{第\arabic{page}页(共6页)}
bibtex.bib
@article{cortes1995support,
title={Support-vector networks},
author={Cortes, Corinna and Vapnik, Vladimir},
journal={Machine learning},
volume={20},
number={3},
pages={273--297},
year={1995},
publisher={Springer}
}
编译
xelatex report
bibtex report
xelatex report
xelatex report
展开阅读
当你发现一个你喜欢的乐队,一首你喜欢的歌时,你可能会很想找到同类型的乐队和音乐家。
但是如何知道一首歌或一个乐队是哪个风格的呢?疯狂谷歌维基?这样太费时间了
基于语义网SPARQL语言可以帮助你完成自动在维基上搜索的过程
以下代码寻找所有风格为爵士的乐队的音乐家:
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX dbp:<http://dbpedia.org/resource/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dct: <http://purl.org/dc/terms/>
select distinct ?memberName {
?member foaf:name ?memberName .
?band dbo:bandMember ?member .
?band dbo:genre ?genre .
?genre dct:subject dbp:Category:Jazz_genres .
}
使用在线dbpedia工具,在Query Text栏输入以上代码,点击Run Query即可得到你要找的音乐家,是不是比手动深度优先遍历维基快多了?(狗头