Commit d3cbeb17 authored by Taddeüs Kroes's avatar Taddeüs Kroes

- Emptied Makefile.

Merge branch 'master' of ssh://vo20.nl/home/git/repos/uva

Conflicts:
	os/ass4/Makefile
parents 53506716 1715f304
*.log
*.aux
*.swp
*.toc
compilerbouw/
[submodule "compilerbouw"]
path = compilerbouw
url = ssh://sander@vo20.nl/git/compilerbouw.git
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumerate}
\usepackage{listings}
\usepackage{url}
\usepackage{float}
\title{Algoritme en complexiteit: opgaves deel 3}
\author{Sander van Veen \& Richard Torenvliet \\ Tadde\"us Kroes \& Jayke Meijer}
% dot graphs
\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\definecolor{darkgray}{rgb}{0.95,0.95,0.95}
\maketitle
\tableofcontents
\pagebreak
\section{}
\section{}
\section{Chemische stof}
Na elke veredeling stijgt de waarde van de stof (er geldt dus
$\phi_{r+1}(x) > \phi_{r}(x)$, als $x$ niet verandert). De hoeveelheid $x$ van
de stof neemt af bij elke veredeling ($x_{i+1} = x_i * a$ met $a < 1$). De
maximale winst van de chemische stof wordt behaald als $\phi_r(x)$ maximaal is.
Stel: $x_0$ = 6 en $\phi_0(x) = \frac{1}{2} x$. In dit voorbeeld nemen we aan dat
$\phi_{r+1}(x) = \phi_r(x) * c$ met $c = 1.4$. Tot slot geldt in dit voorbeeld
dat $a = 0.8$. Dat levert de volgende tabel op:
\begin{table}[H]
\begin{tabular}{|r|l|l|l|l|l|l|l|l|l|l|}
\hline
& $x_0$ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ & $x_6$ & $x_7$ & $x_8$ & $x_9$ \\
\hline
$\phi_0(x)$ & 3.00 & 2.40 & 1.92 & 1.54 & 1.23 & 0.98 & 0.79 & 0.63 & 0.50 & 0.40 \\
\hline
$\phi_1(x)$ & 4.20 & 3.36 & 2.69 & 2.15 & 1.72 & 1.38 & 1.10 & 0.88 & 0.70 & 0.56 \\
\hline
$\phi_2(x)$ & 5.88 & 4.70 & 3.76 & 3.01 & 2.41 & 1.93 & 1.54 & 1.23 & 0.99 & 0.79 \\
\hline
$\phi_3(x)$ & 8.23 & 6.59 & 5.27 & 4.21 & 3.37 & 2.70 & 2.16 & 1.73 & 1.38 & 1.10 \\
\hline
$\phi_4(x)$ & 11.52 & 9.22 & 7.38 & 5.90 & 4.72 & 3.78 & 3.02 & 2.42 & 1.93 & 1.55 \\
\hline
$\phi_5(x)$ & 16.13 & 12.91 & 10.33 & 8.26 & 6.61 & 5.29 & 4.23 & 3.38 & 2.71 & 2.17 \\
\hline
$\phi_6(x)$ & 22.59 & 18.07 & 14.46 & 11.57 & 9.25 & 7.40 & 5.92 & 4.74 & 3.79 & 3.03 \\
\hline
$\phi_7(x)$ & 31.62 & 25.30 & 20.24 & 16.19 & 12.95 & 10.36 & 8.29 & 6.63 & 5.31 & 4.24 \\
\hline
$\phi_8(x)$ & 44.27 & 35.42 & 28.34 & 22.67 & 18.13 & 14.51 & 11.61 & 9.28 & 7.43 & 5.94 \\
\hline
$\phi_9(x)$ & 61.98 & 49.59 & 39.67 & 31.74 & 25.39 & 20.31 & 16.25 & 13.00 & 10.40 & 8.32 \\
\hline
\end{tabular}
\end{table}
\noindent Uit de tabel valt op te maken dat de cel $\phi_9(x_9)$ het meest voordelig is.
Daardoor is het volgende algoritme bedacht:
\begin{lstlisting}[language=python,backgroundcolor=\color{darkgray}]
def phi(i, x):
if i == 0:
return 0.5 * x
else:
return phi(i-1, x * 1.4)
def x_i(i, x):
if i == 0:
return x
else:
return x_i(i-1, x * 0.8)
max = phi(n, x_i(x, x0))
\end{lstlisting}
\noindent De worse-case tijdcomplexiteit van dit algoritme is van de orde
$\mathcal{O}(n)$, omdat het zichzelf recursief aanroept (n keer).
\section{}
\section{}
\end{document}
def phi(i, x):
if i == 0:
return 0.5 * x
else:
return phi(i-1, x*1.4)
def x_i(i, x):
if i == 0:
return x
else:
return x_i(i-1, x * 0.8)
x0 = 6
max_j = max_i = 10
lookup = []
print r'\hline'
print ' &', ' & '.join(map(lambda x: "$x_%d$" % x, range(0, max_i))), r'\\'
print r'\hline'
for i in range(0,max_i):
r = []
for j in range(0,max_j):
r.append("%.2f" % phi(i, x_i(j, x0)))
print '$\phi_%d(x)$ & ' % i, ' & '.join(r), r'\\'
print r'\hline'
lookup.append(r)
r = []
print " === calculations ==="
n = 10
x_step = float(x0) / n
s = []
left = float(x0)
for i in range(0, n):
left -= x_step
s.append(phi(i, x_i(i, x_step)))
print left, s, len(s), sum(s)
print "x_n = x0 / n = %.3f =>" % x_step, sum([phi(i, x_i(i, x_step)) for i in range(0, n)])
for f in range(2, 10, 1):
x = float(x0)
left = x
for d in range(0, n):
x /= f
s = []
for i in range(0, n-1):
print x
x *= f
left -= x
s.append(phi(i, x_i(i, x)))
s.append(phi(n, x_i(n, left)))
print left, s, len(s)
print "x_n = x * %d =>" % f, sum(s)
print "all x in phi():", phi(n, x_i(n, float(x0)))
compilerbouw @ 4911d79e
Subproject commit 4911d79e41b41212a4b120bb69ee4a6a492d29e8
function [onb] = norma( v )
onb = v ./ sqrt(dot(v,v));
end
function [Q,R] = obn(V)
[m,n] = size(V)
A = V
Q = zeros(n,n)
for j = 1:n
% take column j of V
%v = V(:,j)
for i = 1:j-1
%a = V(:,i)
%b = v'
%c = a * b
%v = v - dot(v, V(:,i))*v
% v = v - dot(V(:,i), v)*V(:,i)
% v = v - V(:,i)*v' % proj (V(:,i), V(:,j))
% \mathbf{v}_j \leftarrow \mathbf{v}_j - \mathrm{proj}_{\mathbf{v}_{i}}
% \, (\mathbf{v}_j) (remove component in direction vi)
m = (V(:, j)'*V(:, i)) / (V(:, i)'*V(:, i));
V(:, j) = V(:, j) - m * V(:, i);
end
Q(:, j) = V(:, j) / norm(V(:, j));
%v = norma(v)
%V(:,j) = v
end
R = Q' * A
end
%obn([1,1,1;
% 0,1,1;
% 0,0,1])
%function [span, printv2, printw1] = onb2(w1, v2)
% w1 = norma(w1);
% v2 = norma(v2);
% printv2 = v2;
% printw1 = w1;
%
% v2 = cross(w1, v2);
%
% span(:, 1) = w1;
% span(:, 2) = v2;
%end
function span = onb2(w1, v2)
span = [w1, norma(v2 - dot(w1,v2)*w1)];
end
function [onb] = norma( v )
onb = v ./ sqrt(dot(v,v));
end
function [Q,R] = obn(V)
[m,n] = size(V)
A = V
Q = zeros(n,n)
for j = 1:n
% take column j of V
%v = V(:,j)
for i = 1:j-1
%a = V(:,i)
%b = v'
%c = a * b
%v = v - dot(v, V(:,i))*v
% v = v - dot(V(:,i), v)*V(:,i)
% v = v - V(:,i)*v' % proj (V(:,i), V(:,j))
% \mathbf{v}_j \leftarrow \mathbf{v}_j - \mathrm{proj}_{\mathbf{v}_{i}}
% \, (\mathbf{v}_j) (remove component in direction vi)
m = (V(:, j)'*V(:, i)) / (V(:, i)'*V(:, i));
V(:, j) = V(:, j) - m * V(:, i);
end
Q(:, j) = V(:, j) / norm(V(:, j));
%v = norma(v)
%V(:,j) = v
end
R = Q' * A
end
%obn([1,1,1;
% 0,1,1;
% 0,0,1])
%function [span, printv2, printw1] = onb2(w1, v2)
% w1 = norma(w1);
% v2 = norma(v2);
% printv2 = v2;
% printw1 = w1;
%
% v2 = cross(w1, v2);
%
% span(:, 1) = w1;
% span(:, 2) = v2;
%end
function span = onb2(w1, v2)
span = [w1, norma(v2 - dot(w1,v2)*w1)];
end
ass*/ass*
*.o
PROG = philosophers
CC = gcc
CFLAGS = -ansi -Wall -Wextra -O3 -pthread
OFILES = host.o
RM = rm -f
$(PROG): $(OFILES)
$(CC) -o $(PROG) $(OFILES) $(CFLAGS)
%.o: %.c
$(CC) -c $< $(CFLAGS)
clean:
$(RM) *.o $(PROG)
This diff is collapsed.
/*
* Assignment 4 of Operating Systems: PThread simulation.
*
* Sander van Veen (6167969) and Taddeus Kroes (6054129).
* <sandervv@gmail.com> and <taddeuskroes@hotmail.com>.
*
* Submission date: 21 november 2010.
*/
typedef struct diner_stats {
unsigned int meals;
unsigned int forks;
unsigned int id;
unsigned int locked;
} diner_stats;
/*
* Duration of the diner party (in seconds). When this time limit is reached,
* all philosophers are requested to pay their bill and leave the party.
*/
#define TIME_LIMIT 10.f
int philo_left(diner_stats *stats, int id);
int philo_right(diner_stats *stats, int id);
int philo_optimistic(diner_stats *stats, int id);
int philo_shy(diner_stats *stats, int id);
int philo_random(diner_stats *stats, int id);
typedef int(*philo_t)(diner_stats *, int);
TT\documentclass[twocolumn]{article}
\documentclass[twocolumn]{article}
\usepackage{url}
\title{Web-based digital examination for specific learning areas}
......
......@@ -22,7 +22,7 @@ if version > 580
endif
let g:colors_name="darkspectrum"
hi Normal guifg=#efefef guibg=#2A2A2A
hi Normal guifg=#efefef guibg=#171717
" highlight groups
hi Cursor guibg=#ffffff guifg=#000000
......@@ -123,8 +123,8 @@ hi link schemeFunc Statement
"hi link bashSpecialVariables Constant
" tabs (non gui)
hi TabLine guifg=#A3A3A3 guibg=#202020 gui=none
hi TabLineFill guifg=#535353 guibg=#202020 gui=none
hi TabLine guifg=#A3A3A3 guibg=#171717 gui=none
hi TabLineFill guifg=#535353 guibg=#171717 gui=none
hi TabLineSel guifg=#FFFFFF gui=bold
"hi TabLineSel guifg=#FFFFFF guibg=#000000 gui=bold
" vim: sw=4 ts=4
......@@ -31,6 +31,34 @@ augroup vimrc_autocmds
autocmd BufEnter * match OverLength /\%81v.*/
augroup END
" configure tags - add additional tags here or comment out not-used ones
" cd /usr/include
" ctags -R --sort=yes --fields=+iaS -f ~/.vim/tags/stdc stdio.h stdlib.h \
" pthread.h math.h assert.h errno.h malloc.h strings.h fcntl.h unistd.h
" ctags -R --sort=yes --fields=+iaS -f ~/.vim/tags/gl GL/
set tags+=~/.vim/tags/stdc
set tags+=~/.vim/tags/gl
" build tags of your own project with CTRL+F12
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"noremap <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
"inoremap <F12> <Esc>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
"set completeopt=menuone,menu,longest,preview
set completeopt=menuone,menu " ,longest,preview
set nocp
filetype plugin on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment