Code covered by the BSD License  

Highlights from
Cops and Robber Software

from Cops and Robber Software by Athanasios Kehagias
Functions to compute optimal schedules for a team of cops chasing a robber on a graph

[F,CT,DCT,mopta,moptd]=CRcod(Ca,Ra,Cd)
function [F,CT,DCT,mopta,moptd]=CRcod(Ca,Ra,Cd)
% function [F,CT,DCT,mopta,moptd]=CRcod(Ca,Ra,Cd)
% computes the cost of drunkenness
%
% Ca:		matrix of cop-optimal capture times, either N-by-N (1 cop) or N-by-N-by-N (2 cops) / ADVERSARIAL robber
% Ra:		matrix of rob-optimal capture times, either N-by-N (1 cop) or N-by-N-by-N (2 cops) / ADVERSARIAL robber
% Cd:		matrix of cop-optimal expected capture times, either N-by-N (1 cop) or N-by-N-by-N (2 cops) / DRUNK       robber
% F:		the cost of drunkennes, ratio of adversarial to drunk optimal capture times 
% mopta:	optimal initial positions, adversarial robber; 1-by-2 (1 cop) or 1-by-3 (2 cops)
% moptd:	optimal initial positions, drunk       robber; 1-by-1 (1 cop) or 1-by-2 (2 cops)

NN=size(Ca);
LL=length(NN);
N=NN(1);
if	LL==2					% one cop  case

	for n=1:N; dct(n)=sum(Cd(n,:)); end
	dct=dct/N;
	[DCT m1]=min(dct);
	moptd=m1;

	for n=1:N;  ct(n)=max(Ca(n,:)); end
	[CT m2]=min(ct);
	[CTr m3]=max(Ca(m2,:));
	mopta=[m2 m3];

else						% two cops case
	dc1=0; dc2=0;
	for n1=1:N
		for n2=1:N
			dct(n1,n2)=sum(Cd(n1,n2,:))/N;
		end
	end
	DCT=min(min(dct));
	for n1=1:N
		for n2=1:N
			if dct(n1,n2)==DCT; dc1=n1; dc2=n2; end
		end
	end	
	moptd=[dc1 dc2];

	ac1=0; ac2=0; ac3=0;
	for n1=1:N
		for n2=1:N
			ct(n1,n2)=0;
			for n3=1:N
				if Ca(n1,n2,n3)>ct(n1,n2); ct(n1,n2)=Ca(n1,n2,n3); end
			end
		end
	end
	CT=min(min(ct));
	for n1=1:N
		for n2=1:N
			if ct(n1,n2)==CT; ac1=n1; ac2=n2; end
		end
	end	
	minCT=max(Ca(ac1,ac2,:));
	for n=1:N
		if Ca(ac1,ac2,n)==minCT; ar=n; end
	end
	mopta=[ac1 ac2 ar];
end
F=CT/DCT;

Contact us