<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eurion.net</title>
	<atom:link href="http://bloc.eurion.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://bloc.eurion.net</link>
	<description>Siegfried Gevatter (RainCT)</description>
	<lastBuildDate>Sat, 29 Dec 2012 12:42:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Best Chrome extensions</title>
		<link>http://bloc.eurion.net/archives/2012/best-chrome-extensions/</link>
		<comments>http://bloc.eurion.net/archives/2012/best-chrome-extensions/#comments</comments>
		<pubDate>Sat, 29 Dec 2012 12:40:45 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[recommendations]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=2064</guid>
		<description><![CDATA[Since I haven&#8217;t been blogging for a while, here is a list of some Chrome extensions you can&#8217;t miss. Sanity AdBlock Plus &#8211; I&#8217;m not sure how anyone can use a web browser without AdBlock. It&#8217;ll make sure you don&#8217;t see ads, anywhere. Productivity Pocket &#8211; If you have a tablet, this is the extension [...]]]></description>
				<content:encoded><![CDATA[<p>Since I haven&#8217;t been blogging for a while, here is a list of some Chrome extensions you can&#8217;t miss.</p>
<p><strong>Sanity</strong></p>
<ul>
<li><strong><a href="https://adblockplus.org/">AdBlock Plus</a></strong> &#8211; I&#8217;m not sure how anyone can use a web browser without AdBlock. It&#8217;ll make sure you don&#8217;t see ads, anywhere.</li>
</ul>
<p><strong>Productivity</strong></p>
<ul>
<li><strong><a href="http://getpocket.com/">Pocket</a></strong> &#8211; If you have a tablet, this is the extension you need. Save interesting reads so you can access them later from your computer, smartphone or tablet. It also nicely extracts the text from the page, leaving it free of clutter.</li>
<li><strong><a href="https://chrome.google.com/webstore/detail/google-tasks-by-google/dmglolhoplikcoamfgjgammjbgchgjdd">Google Tasks</a></strong> &#8211; Who doesn&#8217;t want to be able to save TODO items just by typing &#8220;<strong>t</strong> whatever&#8221; into the <abbr title="Chrome's combined URL and search box" style="font-weight: normal;">omnibox</abbr>? I haven&#8217;t tried it, but some may prefer <a href="https://chrome.google.com/webstore/detail/better-google-tasks/nbhddnkmimnokfjdlogacnfjfclgcdme">Better Google Tasks</a>.</li>
</ul>
<p><strong>Privacy</strong></p>
<ul>
<li><strong><a href="https://chrome.google.com/webstore/detail/https-everywhere/gcbommkclmclpchllfjekcdonpmejbdp">HTTPS Everywhere</a></strong> &#8211; Protect your privacy when using insecure networks. This extension forces many popular sites to always encrypt communications.</li>
<li><strong><a href="https://chrome.google.com/webstore/detail/donottrackme/epanfjkfahimkgomnigadpkobaefekcd">DoNotTrackMe</a></strong> &#8211; If you&#8217;re using AdBlock you won&#8217;t see ads, so what does it matter whether they are customized to your interests? Use this extension to stop ad networks from tracking you.</li>
<li>Extra: <a href="https://userscripts.org/scripts/show/87718">Facebook Link Rewriter</a>, <a href="https://chrome.google.com/webstore/detail/unsocial-reader-for-faceb/lbdpfpcjdacpjajeiinhbbgdahbdgdbh">Unsocial Reader for Facebook</a>.</li>
</ul>
<p><strong>Social</strong></p>
<ul>
<li><strong><a href="http://rapportive.com/">Rapportive</a></strong> &#8211; For GMail users, this extension adds a sidebar with information about who you&#8217;re talking to (LinkedIn profile, etc).</li>
<li><strong><a href="https://chrome.google.com/webstore/detail/jgoepmocgafhnchmokaimcmlojpnlkhp">Google +1 Button</a></strong> &#8211; Add a &#8220;+1&#8243; button to Chrome.</li>
</ul>
<p>What extensions do <strong>you</strong> use? Let me know about your favorite one.</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2012/best-chrome-extensions/#comments">3 comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2012. |
<a href="http://bloc.eurion.net/archives/2012/best-chrome-extensions/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/chrome/" rel="tag">chrome</a>, <a href="http://bloc.eurion.net/archives/tag/recommendations/" rel="tag">recommendations</a><br/>
</small></p><div class='yarpp-related-rss yarpp-related-none'>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2012/best-chrome-extensions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A gentle introduction to Zeitgeist&#8217;s Python API</title>
		<link>http://bloc.eurion.net/archives/2012/zeitgeist-python-api-tutorial/</link>
		<comments>http://bloc.eurion.net/archives/2012/zeitgeist-python-api-tutorial/#comments</comments>
		<pubDate>Sat, 21 Jul 2012 13:17:26 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet Debian]]></category>
		<category><![CDATA[Planet GNOME]]></category>
		<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[zeitgeist]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=2005</guid>
		<description><![CDATA[In this post I&#8217;ll make a quick introduction by example on how to use Zeitgeist&#8217;s Python API for good and profit. If you&#8217;re interested in using Zeitgeist from C instead, see the libzeitgeist examples; to use it with C++/Qt, Trever&#8217;s «a web browser in 4 steps» may be of interest. First things first In case [...]]]></description>
				<content:encoded><![CDATA[<p>In this post I&#8217;ll make a quick introduction by example on how to use Zeitgeist&#8217;s Python API for good and profit.</p>
<p>If you&#8217;re interested in using Zeitgeist from C instead, see the <a href="https://bazaar.launchpad.net/~libzeitgeist-developers/libzeitgeist/trunk/files/head:/examples/">libzeitgeist examples</a>; to use it with C++/Qt, Trever&#8217;s «<a href="http://wm161.net/2012/03/30/zeitgeist-webrowser-in-four-steps/">a web browser in 4 steps</a>» may be of interest.</p>
<h3>First things first</h3>
<p>In case you&#8217;re not familiar with <a href="http://zeitgeist-project.com/">Zeitgeist</a>, it may prove helpful to first read Mikkel&#8217;s <a href="http://www.grillbar.org/wordpress/?p=426">introduction to Zeitgeist</a> post.</p>
<p>If that&#8217;s too much to read, just should know that Zeitgeist is an event log. Like the history in your browser, it keeps track of what websites you open at which point in time. It also keeps track of when you close them, and of what browser you used, since it&#8217;s a system-wide service. Furthermore, it does the same for files, conversations, e-mails, and anything else you want to insert into it.</p>
<p>So Zeitgeist is a database of events, and an <strong>event</strong> can be pretty much anything. But what does it look like? It&#8217;s main attributes are the following:</p>
<ul>
<li>timestamp &#8211; when did the event happen (milliseconds since Unix epoch)</li>
<li>interpretation &#8211; what sort of event is it (eg. opened, closed)</li>
<li>manifestation &#8211; why did it happen (user activity, notification&#8230;)</li>
<li>actor &#8211; which is the primary application involved</li>
<li>origin &#8211; where did it come from (eg. website where you clicked the link that opened this page)</li>
</ul>
<p>Additionally, each event has one or more <strong>subjects</strong>, which have the following attributes:</p>
<ul>
<li>uri</li>
<li>current_uri &#8211; updated URI if it changed since the event</li>
<li>interpretation &#8211; abstract type (document, image, video&#8230;)</li>
<li>manifestation &#8211; how it is stored (file, remote object, website)</li>
<li>origin &#8211; parent folder for files, domain name for websites</li>
<li>mimetype</li>
<li>text &#8211; a title for the event (eg. filename, website title&#8230;)</li>
<li>storage &#8211; identifier for the storage medium of the subject (eg. local, online, pendrive X)</li>
</ul>
<h3>Retrieving recent data</h3>
<p>Okay, so let&#8217;s say you want to know the last song you&#8217;ve listened to (if you have a Zeitgeist-enabled music player). It&#8217;s a simple as:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_events_received<span style="color: black;">&#40;</span>events<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> events:
        song <span style="color: #66cc66;">=</span> events<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Last song: %s&quot;</span> % song.<span style="color: black;">subjects</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">uri</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;You haven't listened to any songs.&quot;</span>
&nbsp;
template <span style="color: #66cc66;">=</span> Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">AUDIO</span><span style="color: black;">&#41;</span>
zeitgeist.<span style="color: black;">find_events_for_template</span><span style="color: black;">&#40;</span>template<span style="color: #66cc66;">,</span> on_events_received<span style="color: #66cc66;">,</span> num_events<span style="color: #66cc66;">=</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop - note: the Qt mainloop also works</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>This may need some explaining. We start by importing the <a href="http://eurion.net/zeitgeist/docs/0.8.2/client.html#zeitgeistclient">Zeitgeist client</a> and some associated <a href="http://eurion.net/zeitgeist/docs/0.8.2/datamodel.html">data structures</a> (such as <em>Event</em> and <em>Interpretation</em>), and create an instance of the client. The <em>ZeitgeistClient</em> class is a wrapper around <a href="http://eurion.net/zeitgeist/docs/0.8.2/dbus_api.html">Zeitgeist&#8217;s D-Bus API</a> which not only makes it much nicer to use, but also makes it easy to install monitors (as we will see later) and provides convenient functionality such as automatic reconnection if the connection to the engine is lost.</p>
<p>To query for the most recent song, we just need to create a template with the restrictions we want to impose and submit it to Zeitgeist using the <em>find_events_for_template</em> call. If you haven&#8217;t read <a href="http://www.grillbar.org/wordpress/?p=426">Mikkel&#8217;s post</a> yet, please do so, as it introduces the structure of events and subjects (in short: an event has a timestamp, some other properties, and one or more subjects representing the resources -files, websites, people&#8230;- involved in the event).</p>
<p>The Python API is inherently asynchronous (if for some reason you need a synchronous API, you may still use the lower level ZeitgeistDBusInterface class), so we need to define a callback function to handle the results we receive from the Zeitgeist engine. </p>
<p>Finally, we need to create a main loop so the asynchronous functions can run.</p>
<hr /></p>
<p>Now this was a pretty simple example. Let&#8217;s make it more interesting. One song isn&#8217;t much, so let&#8217;s get the 5 most recent songs. Also, now we want both songs and videos.</p>
<p>The first part is pretty easy, we just need to change the <em>num_events</em> parameter. For the second extension, we have to change the event template. In fact, now we need two different event templates and the <em>find_events_for_template<strong>s</strong></em> function, which takes an arbitrary number of event templates and ORs them. The result is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_events_received<span style="color: black;">&#40;</span>events<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> event <span style="color: #ff7700;font-weight:bold;">in</span> events:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;- %s&quot;</span> % event.<span style="color: black;">subjects</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">uri</span>
&nbsp;
tmpl1 <span style="color: #66cc66;">=</span> Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">AUDIO</span><span style="color: black;">&#41;</span>
tmpl2 <span style="color: #66cc66;">=</span> Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">VIDEO</span><span style="color: black;">&#41;</span>
zeitgeist.<span style="color: black;">find_events_for_templates</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>tmpl1<span style="color: #66cc66;">,</span> tmpl2<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span>
                                    on_events_received<span style="color: #66cc66;">,</span> num_events<span style="color: #66cc66;">=</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>This will work, but unless you&#8217;re lucky you&#8217;re likely to get some duplicate line. Why is this? Well, other than that you may have used the same file twice, don&#8217;t forget that what you are requesting are actually events. If you&#8217;ve started playing a given song, you probably also stopped playing it, so that&#8217;s actually two of them (an <em>AccessEvent</em> and a <em>LeaveEvent</em>). Since this isn&#8217;t what we want, we&#8217;ll change the query a bit:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;">zeitgeist.<span style="color: black;">find_events_for_templates</span><span style="color: black;">&#40;</span>
    <span style="color: black;">&#91;</span>tmpl1<span style="color: #66cc66;">,</span> tmpl2<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span>
    on_events_received<span style="color: #66cc66;">,</span>
    num_events<span style="color: #66cc66;">=</span><span style="color: #ff4500;">5</span><span style="color: #66cc66;">,</span>
    result_type<span style="color: #66cc66;">=</span>ResultType.<span style="color: black;">MostRecentSubjects</span><span style="color: #66cc66;">,</span>
    storage_state<span style="color: #66cc66;">=</span>StorageState.<span style="color: black;">Available</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>By requesting the most recent <em>subjects</em>, vs. the most recent <em>events</em>, we can filter out events with duplicate URI. See the <a href="http://eurion.net/zeitgeist/docs/0.8.2/datamodel.html#resulttype">ResultType documentation</a> for other modes you can use. Note particularly the <strong>MostPopularSubjects</strong> result type.</p>
<p>I also used the chance to introduce the <em>storage_state</em> parameter. This one will filter out events for files Zeitgeist knows aren&#8217;t available (this mostly means online resources won&#8217;t be shown if you don&#8217;t have a network connnection; there&#8217;s also support for handling external storage media, but because of problems with GIO this is currently disabled).</p>
<p>Last but not least, the <em>find_events_for_*</em> methods also accept a <em>timerange</em> parameter. It defaults to <em>TimeRange.until_now()</em>, but you may change it to <em>TimeRange.always()</em> (if for some reason you&#8217;re working with events in the future) or to any other time range of your choice. Here it&#8217;s important to note that Zeitgeist&#8217;s timestamps use millisecond precision.</p>
<hr /></p>
<p>For more advanced queries, you can use more complex combinations of events and subject templates. The rule to keep in mind here is that events are OR&#8217;d and subjects are ANDed.</p>
<p>Additionally, some field (actor, origin, mimetype, uri and current_uri) may be prefixed with an exclamation mark (&#8220;!&#8221;) for NOT, or you may append an asterisc (&#8220;*&#8221;) to them for prefix search. You can even combine the two operators together. Here&#8217;s an example of a template you could build:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;">subj1 <span style="color: #66cc66;">=</span> Subject.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">SOURCE_CODE</span><span style="color: #66cc66;">,</span>
                               uri<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;file:///home/rainct/Development/*&quot;</span><span style="color: black;">&#41;</span>
subj2 <span style="color: #66cc66;">=</span> Subject.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>uri<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;!file:///home/rainct/Development/zeitgeist/*&quot;</span><span style="color: black;">&#41;</span>
tmpl1 <span style="color: #66cc66;">=</span> Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">MODIFY_EVENT</span><span style="color: #66cc66;">,</span>
                             subjects<span style="color: #66cc66;">=</span><span style="color: black;">&#91;</span>subj1<span style="color: #66cc66;">,</span> subj2<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
templates <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>tmpl1<span style="color: black;">&#93;</span></pre></td></tr></table></div>

<p>In my case, this template would fetch a list of the source code files I modified most recently but excluding those related to the Zeitgeist project.</p>
<h3>Working with big sets of data</h3>
<p>In case you&#8217;re trying to do something crazy, you may end up with a Zeitgeist query complaining that it exceeded the memory limit. You&#8217;re not supposed to do that. Instead, we provide some methods for working with large collections of events.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_events_received<span style="color: black;">&#40;</span>events<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> event <span style="color: #ff7700;font-weight:bold;">in</span> events:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'- %s'</span> % event.<span style="color: black;">subjects</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">uri</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_ids_received<span style="color: black;">&#40;</span>event_ids<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'A total of %d source code files were found.'</span> % <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>event_ids<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Fetching the first 100...'</span>
    zeitgeist.<span style="color: black;">get_events</span><span style="color: black;">&#40;</span>event_ids<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">100</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> on_events_received<span style="color: black;">&#41;</span>
&nbsp;
tmpl <span style="color: #66cc66;">=</span> Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">SOURCE_CODE</span><span style="color: black;">&#41;</span>
zeitgeist.<span style="color: black;">find_event_ids_for_templates</span><span style="color: black;">&#40;</span>
    <span style="color: black;">&#91;</span>tmpl<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span>
    on_ids_received<span style="color: #66cc66;">,</span>
    num_events<span style="color: #66cc66;">=</span><span style="color: #ff4500;">10000</span><span style="color: #66cc66;">,</span> <span style="color: #808080; font-style: italic;"># you can use 0 for &quot;all events&quot;, but do you really need to?</span>
    timerange<span style="color: #66cc66;">=</span>TimeRange.<span style="color: black;">from_seconds_ago</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3600</span>*<span style="color: #ff4500;">24</span>*<span style="color: #ff4500;">30</span>*<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span>
    result_type<span style="color: #66cc66;">=</span>ResultType.<span style="color: black;">MostPopularSubjects</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>And there you have the source code files you worked with during the last 3 months, ordered from most to least popular (<small>popularity is measured counting the number of events; for more precision, maybe you could limit the results to events with interpretation AccessEvent</small>).</p>
<p>Why do we provide this mechanism instead of querying with a simple offset? Well, this avoids problems when the log changes (events are inserted or deleted). Have you ever been exploring the latest posts in some website, and as you change to the next page some of the results from the previous page show up again (because new posts have been added in the meantime)? With Zeitgeist this won&#8217;t happen.</p>
<h3>Receiving information in real time</h3>
<p>At this point you&#8217;re an expert at requesting all sorts of data from Zeitgeist, but now you want to show a list of the last kitten images you&#8217;ve viewed, updated in real time. Don&#8217;t worry, Zeitgeist can provide for this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_insert<span style="color: black;">&#40;</span>time_range<span style="color: #66cc66;">,</span> events<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># do awesome stuff with the events here</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> events
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_delete<span style="color: black;">&#40;</span>time_range<span style="color: #66cc66;">,</span> event_ids<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># a previously inserted event was deleted</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> event_ids
&nbsp;
templates <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>subject_uri<span style="color: #66cc66;">=</span><span style="color: #483d8b;">'file:///home/user/kittens/*'</span><span style="color: #66cc66;">,</span>
                                  subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">IMAGE</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
zeitgeist.<span style="color: black;">install_monitor</span><span style="color: black;">&#40;</span>TimeRange.<span style="color: black;">always</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> templates<span style="color: #66cc66;">,</span> on_insert<span style="color: #66cc66;">,</span> on_delete<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>It&#8217;s important to note that <em>on_delete</em> won&#8217;t be called when an image is deleted (that&#8217;d be a newly inserted event with <em>interpretation=DELETE_EVENT</em>); rather, it&#8217;s called when a previously inserted event is deleted (for example, using the &#8220;forget recent history» option in <a href="https://launchpad.net/activity-log-manager/">Activity Log Manager</a>).</p>
<p>In case you&#8217;re curious: for best performance, this doesn&#8217;t actually use D-Bus signals. Instead, this little call will setup a D-Bus object behind the scenes and register it with the Zeitgeist engine, so it can notify said object when (and only when) an event of its interest is registered.</p>
<p>To stop receiving notifications for a template, you&#8217;ll need the save the object returned by the <em>install_monitor</em> call:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;">m <span style="color: #66cc66;">=</span> zeitgeist.<span style="color: black;">install_monitor</span><span style="color: black;">&#40;</span>TimeRange.<span style="color: black;">always</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> templates<span style="color: #66cc66;">,</span> on_insert<span style="color: #66cc66;">,</span> on_delete<span style="color: black;">&#41;</span>
zeitgeist.<span style="color: black;">remove_monitor</span><span style="color: black;">&#40;</span>m<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Pro Tip:</strong> You can use the <a href="https://launchpad.net/zeitgeist-explorer">Zeitgeist Explorer</a> GUI to quickly try out different queries (<small>note: it&#8217;s still work in progress, so much funcionality is missing, but it does work somewhat</small>).</p>
<h3>Contextual awesomeness: finding related events</h3>
<p>By now you&#8217;re familiar with retrieving events and keeping them up to date. Now it&#8217;s time for a little secret:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_related_received<span style="color: black;">&#40;</span>uris<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Related URIs:'</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> uri <span style="color: #ff7700;font-weight:bold;">in</span> uris:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">' - %s'</span> % uri
&nbsp;
query_templates <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>
    subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">SOURCE_CODE</span><span style="color: #66cc66;">,</span>
    subject_uri<span style="color: #66cc66;">=</span><span style="color: #483d8b;">'file:///home/rainct/Development/zeitgeist/*'</span><span style="color: #66cc66;">,</span>
    subject_mimetype<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;text/x-vala&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
result_templates <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>
    subject_interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">WEBSITE</span><span style="color: #66cc66;">,</span>
    subject_manifestation<span style="color: #66cc66;">=</span>Manifestation.<span style="color: black;">WEB_DATA_OBJECT</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
now <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>*<span style="color: #ff4500;">1000</span>
zeitgeist.<span style="color: black;">find_related_uris_for_events</span><span style="color: black;">&#40;</span>
    query_templates<span style="color: #66cc66;">,</span>
    on_related_received<span style="color: #66cc66;">,</span>
    time_range<span style="color: #66cc66;">=</span>TimeRange<span style="color: black;">&#40;</span>now - <span style="color: #ff4500;">1000</span>*<span style="color: #ff4500;">3600</span>*<span style="color: #ff4500;">24</span>*<span style="color: #ff4500;">30</span>*<span style="color: #ff4500;">6</span><span style="color: #66cc66;">,</span> now<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span>
    result_event_templates<span style="color: #66cc66;">=</span>result_templates<span style="color: #66cc66;">,</span>
    num_events<span style="color: #66cc66;">=</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>This little query example will return up to 10 websites I used at the same time as the Vala files inside my Zeitgeist directory, considering only data from the last 6 months. Nice, huh?</p>
<p>This is an experimental feature, and it doesn&#8217;t work well when operating on big inputs, so it&#8217;s usually better to use the <em>find_related_uris_for_uris</em> variant (which replaces the first <em>query_templates</em> parameter with a list of URIs).</p>
<h3>Advanced searching: the FTS extension</h3>
<p>Some people think prefix searches aren&#8217;t good enough for them, and this is why the Zeitgeist engine ships by default with a FTS (<em>Full Text Search</em>) extension.</p>
<p>Using the methods provided by this extension you can perform more advanced queries against subjects&#8217; <em>current_uri</em> and <em>text</em> properties (unlike the name may suggest, the FTS extension doesn&#8217;t index the content of the files, but just the information in the event).</p>
<p>This is exposed as <a href="http://developer.ubuntu.com/api/ubuntu-12.04/c/zeitgeist/ZeitgeistIndex.html">zeitgeist_index_search</a> in libzeitgeist (the C library), but unfortunately isn&#8217;t currently available in the Python API. If you still need it, you&#8217;ll have to fallback to pretty much using the D-Bus interface (you still get reconnection support, though). Here&#8217;s an example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
index <span style="color: #66cc66;">=</span> zeitgeist._iface.<span style="color: black;">get_extension</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Index'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'index/activity'</span><span style="color: black;">&#41;</span>
&nbsp;
query            <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'hello'</span> <span style="color: #808080; font-style: italic;"># search query</span>
time_range       <span style="color: #66cc66;">=</span> TimeRange.<span style="color: black;">always</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
event_templates  <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
offset           <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0</span>
num_events       <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">10</span>
result_type      <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">100</span> <span style="color: #808080; font-style: italic;"># magic number for &quot;relevancy&quot; (ResultType.* also work)</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_reply<span style="color: black;">&#40;</span>events<span style="color: #66cc66;">,</span> num_estimated_matches<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Got %d out of ~%d results.'</span> % <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>events<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> num_estimated_matches<span style="color: black;">&#41;</span>
    events <span style="color: #66cc66;">=</span> <span style="color: #008000;">map</span><span style="color: black;">&#40;</span>Event<span style="color: #66cc66;">,</span> events<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> event <span style="color: #ff7700;font-weight:bold;">in</span> events:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">' - %s'</span> % event.<span style="color: black;">subjects</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">uri</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_error<span style="color: black;">&#40;</span>exception<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Error from FTS:'</span><span style="color: #66cc66;">,</span> exception
&nbsp;
index.<span style="color: black;">Search</span><span style="color: black;">&#40;</span>query<span style="color: #66cc66;">,</span> time_range<span style="color: #66cc66;">,</span> event_templates<span style="color: #66cc66;">,</span>
             offset<span style="color: #66cc66;">,</span> num_events<span style="color: #66cc66;">,</span> result_type<span style="color: #66cc66;">,</span>
             reply_handler<span style="color: #66cc66;">=</span>on_reply<span style="color: #66cc66;">,</span> error_handler<span style="color: #66cc66;">=</span>on_error<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>The most interesting thing here is the <em>query</em> parameter. Quoting from the C documentation:</p>
<pre>
The default boolean operator is AND. Thus the query foo bar will
be interpreted as foo AND bar. To exclude a term from the result
set prepend it with a minus sign - eg foo -bar. Phrase queries
can be done by double quoting the string "foo is a bar". You can
truncate terms by appending a *.

There are a few keys you can prefix to a term or phrase to search
within a specific set of metadata. They are used like key:value.
The keys name and title search strictly within the text field of
the event subjects. The key app searches within the application
name or description that is found in the actor attribute of the
events. Lastly you can use the site key to search within the
domain name of the subject URIs.

You can also control the results with the boolean operators AND
and OR and you may use brackets, ( and ), to control the operator
precedence.
</pre>
<h3>Modifying the log</h3>
<p>So far we&#8217;ve only queried Zeitgeist for information, let&#8217;s get a bit more active.</p>
<p>You can delete events from Zeitgeist with the following query:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_deleted<span style="color: black;">&#40;</span>timerange<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Deleted events going from %s to %s'</span> % <span style="color: black;">&#40;</span>timerange<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> timerange<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
event_ids <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: #ff4500;">50</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;"># put the IDs of the events you want to delete here</span>
&nbsp;
zeitgeist.<span style="color: black;">delete_events</span><span style="color: black;">&#40;</span>event_ids<span style="color: #66cc66;">,</span> on_deleted<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a mainloop</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>The confirmation callback will receive a timerange going from the first to the last event. If no events were deleted (because they didn&#8217;t exist), you&#8217;ll get <em>(-1, -1)</em>.</p>
<hr /></p>
<p>And now for the interesting part. If your application involves resources (files, websites, contacts, etc.) of any sort, you&#8217;ll probably want to let Zeitgeist know that you&#8217;re using them. It&#8217;s time that you write a data-source!</p>
<p>We start by registering the data-source. Here we go:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">from</span> gi.<span style="color: black;">repository</span> <span style="color: #ff7700;font-weight:bold;">import</span> GLib
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> ZeitgeistClient
<span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: black;">datamodel</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
zeitgeist <span style="color: #66cc66;">=</span> ZeitgeistClient<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> on_status_changed_callback<span style="color: black;">&#40;</span>enabled<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; This method will be called whenever someone enables or disables
        the data-source. &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> enabled:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Data-source enabled and ready to send events!'</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Data-source disabled; don<span style="color: #000099; font-weight: bold;">\'</span>t send event, they<span style="color: #000099; font-weight: bold;">\'</span>ll be ignored.'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> register<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># Always use the same unique_id. Name and description can change</span>
    <span style="color: #808080; font-style: italic;"># freely.</span>
    unique_id <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'com.example.your.data.source'</span>
    name <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'user visible name (may be translated)'</span>
    description <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'user visible description (may be translated)'</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Describe what sort of events will be inserted (optional)</span>
    subject_template <span style="color: #66cc66;">=</span> Subject<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    subject_template.<span style="color: black;">interpretation</span> <span style="color: #66cc66;">=</span> Interpretation.<span style="color: black;">PLAIN_TEXT_DOCUMENT</span>
    subject_template.<span style="color: black;">manifestation</span> <span style="color: #66cc66;">=</span> Manifestation.<span style="color: black;">FILE_DATA_OBJECT</span>
    templates <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> interp <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#40;</span>Interpretation.<span style="color: black;">ACCESS_EVENT</span><span style="color: #66cc66;">,</span> Interpretation.<span style="color: black;">LEAVE_EVENT</span><span style="color: black;">&#41;</span>:
        event_template <span style="color: #66cc66;">=</span> Event<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        event_template.<span style="color: black;">interpretation</span> <span style="color: #66cc66;">=</span> interp
        event_template.<span style="color: black;">manifestation</span> <span style="color: #66cc66;">=</span> Manifestation.<span style="color: black;">USER_ACTIVITY</span>
        event_template.<span style="color: black;">append_subject</span><span style="color: black;">&#40;</span>subject_template<span style="color: black;">&#41;</span>
        templates.<span style="color: black;">append</span><span style="color: black;">&#40;</span>event_template<span style="color: black;">&#41;</span>
&nbsp;
    zeitgeist.<span style="color: black;">register_data_source</span><span style="color: black;">&#40;</span>unique_id<span style="color: #66cc66;">,</span> name<span style="color: #66cc66;">,</span> description<span style="color: #66cc66;">,</span> templates<span style="color: #66cc66;">,</span>
                                   on_status_changed_callback<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Once that&#8217;s done (and if it is enabled), we are free to send our events:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> log<span style="color: black;">&#40;</span>title<span style="color: #66cc66;">,</span> uri<span style="color: #66cc66;">,</span> opened<span style="color: black;">&#41;</span>:
    subject <span style="color: #66cc66;">=</span> Subject.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>
        uri<span style="color: #66cc66;">=</span>uri<span style="color: #66cc66;">,</span>
        interpretation<span style="color: #66cc66;">=</span>Interpretation.<span style="color: black;">PLAIN_TEXT_DOCUMENT</span><span style="color: #66cc66;">,</span>
        manifestation<span style="color: #66cc66;">=</span>Manifestation.<span style="color: black;">FILE_DATA_OBJECT</span><span style="color: #66cc66;">,</span>
        origin<span style="color: #66cc66;">=</span>GLib.<span style="color: black;">path_get_dirname</span><span style="color: black;">&#40;</span>uri<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span>
        mimetype<span style="color: #66cc66;">=</span><span style="color: #483d8b;">'text/plain'</span><span style="color: #66cc66;">,</span>
        text<span style="color: #66cc66;">=</span>title<span style="color: black;">&#41;</span>
    event <span style="color: #66cc66;">=</span> Event.<span style="color: black;">new_for_values</span><span style="color: black;">&#40;</span>
        timestamp<span style="color: #66cc66;">=</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>*<span style="color: #ff4500;">1000</span><span style="color: #66cc66;">,</span>
        manifestation<span style="color: #66cc66;">=</span>Manifestation.<span style="color: black;">USER_ACTIVITY</span><span style="color: #66cc66;">,</span>
        actor<span style="color: #66cc66;">=</span><span style="color: #483d8b;">'application://your_application_name.desktop'</span><span style="color: #66cc66;">,</span>
        subjects<span style="color: #66cc66;">=</span><span style="color: black;">&#91;</span>subject<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> opened:
        event.<span style="color: black;">interpretation</span> <span style="color: #66cc66;">=</span> Interpretation.<span style="color: black;">ACCESS_EVENT</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        event.<span style="color: black;">interpretation</span> <span style="color: #66cc66;">=</span> Interpretation.<span style="color: black;">LEAVE_EVENT</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> on_id_received<span style="color: black;">&#40;</span>event_ids<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Logged %s (%d) with event id %d.'</span> % <span style="color: black;">&#40;</span>title<span style="color: #66cc66;">,</span> opened<span style="color: #66cc66;">,</span> event_ids<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
    zeitgeist.<span style="color: black;">insert_events</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>event<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> on_id_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'__main__'</span>:
    register<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    log<span style="color: black;">&#40;</span><span style="color: #483d8b;">'test.txt'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'file:///tmp/test.txt'</span><span style="color: #66cc66;">,</span> opened<span style="color: #66cc66;">=</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    log<span style="color: black;">&#40;</span><span style="color: #483d8b;">'another_file.txt'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'file:///tmp/another_file.txt'</span><span style="color: #66cc66;">,</span> opened<span style="color: #66cc66;">=</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    log<span style="color: black;">&#40;</span><span style="color: #483d8b;">'another_file.txt'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'file:///tmp/another_file.txt'</span><span style="color: #66cc66;">,</span> opened<span style="color: #66cc66;">=</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    log<span style="color: black;">&#40;</span><span style="color: #483d8b;">'test.txt'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'file:///tmp/test.txt'</span><span style="color: #66cc66;">,</span> opened<span style="color: #66cc66;">=</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Start a mainloop</span>
    GLib.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>If you don&#8217;t know what interpretation and manifestation your subject should have, you can use the following utility methods:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> zeitgeist.<span style="color: #dc143c;">mimetypes</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> get_interpretation_for_mimetype<span style="color: black;">&#40;</span><span style="color: #483d8b;">'text/plain'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> get_manifestation_for_uri<span style="color: black;">&#40;</span><span style="color: #483d8b;">'file:///tmp/test.txt'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Event better, with Zeitgeist 0.9 you can just leave the subject (but <strong>not</strong> event!) interpretation and manifestation fields empty, and they&#8217;ll be guessed the same way as if you used those utility methods.</p>
<p><strong>Pro Tip:</strong> You can examine all registered data-sources and toggle whether they are enabled or not using the <a href="http://cgit.freedesktop.org/zeitgeist/zeitgeist/tree/tools/gtk/zeitgeist-data-sources-gtk.py">zeitgeist-data-sources-gtk.py</a> tool.</p>
<h3>Conclusion</h3>
<p>Wow, I&#8217;m impressed if you&#8217;ve got this far. By now you should have quite a good idea on how to use the Zeitgeist API, and I&#8217;m looking forward to seeing what you do with it in your next awesome project.</p>
<p>If you have any problem with Zeitgeist, feel free to visit us on IRC (<strong>#zeitgeist</strong> on <strong>irc.freenode.net</strong>), or join our <a href="http://lists.zeitgeist-project.com/cgi-bin/mailman/listinfo/dev">mailing list</a>. We&#8217;ll also be at <a href="http://guadec.org/">GUADEC</a> next week, so if you&#8217;re there make sure to say hi!</p>
<p>In case you missed them, here are some useful links:</p>
<ul>
<li><a href="http://eurion.net/zeitgeist/docs/0.8.2/">Python API documentation</a></li>
<li><a href="http://developer.ubuntu.com/api/ubuntu-12.04/c/zeitgeist/">C API documentation</a></li>
<li><a href="http://zeitgeist-project.com/">Zeitgeist project website</a></li>
<li><a href="https://launchpad.net/zeitgeist-project">Meta-project on Launchpad</a></li>
<li><a href="https://bugs.freedesktop.org/describecomponents.cgi?product=Zeitgeist">Bug tracker on FreeDesktop.org</a></li>
</ul>
<p><img src="http://bloc.eurion.net/wp-content/uploads/2012/07/collabora.jpg" alt="" title="Collabora" width="300" height="99" class="aligncenter size-full wp-image-2032" /></p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2012/zeitgeist-python-api-tutorial/#comments">2 comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2012. |
<a href="http://bloc.eurion.net/archives/2012/zeitgeist-python-api-tutorial/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/gnome/" rel="tag">gnome</a>, <a href="http://bloc.eurion.net/archives/tag/zeitgeist/" rel="tag">zeitgeist</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2009/zeitgeist-api-02/' rel='bookmark' title='Introduction to Zeitgeist 0.2&#8242;s API'>Introduction to Zeitgeist 0.2&#8242;s API</a> <small>So now that Zeitgeist 0.2.0 is out I&#8217;ve thought I&#8217;d...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/zeitgeist-0-3-3-is-out/' rel='bookmark' title='Zeitgeist 0.3.3 is out!'>Zeitgeist 0.3.3 is out!</a> <small>From the release announcement: On behalf of the Zeitgeist Project...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/zeitgeist-0-5-1-released/' rel='bookmark' title='Zeitgeist 0.5.1 released!'>Zeitgeist 0.5.1 released!</a> <small>On behalf of the Zeitgeist Project team, I am pleased...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2012/zeitgeist-python-api-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Breu introducció al sistema de control de versions Subversion (SVN)</title>
		<link>http://bloc.eurion.net/archives/2012/introduccio-al-subversion/</link>
		<comments>http://bloc.eurion.net/archives/2012/introduccio-al-subversion/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 21:32:24 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet Ubuntu.cat]]></category>
		<category><![CDATA[desenvolupament]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[vcs]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1917</guid>
		<description><![CDATA[Us deixo aquí una breu introducció al Subversion (SVN), un sistema de control de versions (VCS) per al desenvolupament cooperatiu d&#8217;aplicacions informàtiques. El Subversion permet únicament una forma de treballar centralitzada i no el trobo gaire agradable d&#8217;utilitzar, de manera que si tens l&#8217;opció et recomano que utilitzis un sistema més modern com ara el [...]]]></description>
				<content:encoded><![CDATA[<p>Us deixo aquí una breu introducció al Subversion (SVN), un sistema de control de versions (VCS) per al desenvolupament cooperatiu d&#8217;aplicacions informàtiques.</p>
<p>El Subversion permet únicament una forma de treballar centralitzada i no el trobo gaire agradable d&#8217;utilitzar, de manera que si tens l&#8217;opció et recomano que utilitzis un sistema més modern com ara el Bazaar (del qual ja en vaig parlar en un apunt anterior: <a href="http://bloc.eurion.net/archives/2011/introduccio-al-bzr/">Breu introducció al Bazaar</a>) o el Git.</p>
<p>Ara bé, com que sovint no es té l&#8217;elecció (per exemple a l&#8217;incorporar-se en un projecte existent), aquí va el tutorial. Els conceptes que hi explico són molt bàsic, de manera que de fet es poden aplicar amb petits canvis a qualsevol altre sistema VCS.</p>
<p><a href="http://www.youtube.com/watch?v=bcRiJ1yrgjM">http://www.youtube.com/watch?v=bcRiJ1yrgjM</a></p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2012/introduccio-al-subversion/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2012. |
<a href="http://bloc.eurion.net/archives/2012/introduccio-al-subversion/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/desenvolupament/" rel="tag">desenvolupament</a>, <a href="http://bloc.eurion.net/archives/tag/subversion/" rel="tag">subversion</a>, <a href="http://bloc.eurion.net/archives/tag/svn/" rel="tag">svn</a>, <a href="http://bloc.eurion.net/archives/tag/vcs/" rel="tag">vcs</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/introduccio-al-bzr/' rel='bookmark' title='Breu introducció al sistema de control de versions Bazaar'>Breu introducció al sistema de control de versions Bazaar</a> <small>Introducci&oacute; A l&#39;hora de desenvolupar aplicacions inform&agrave;tiques en grup &eacute;s...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2012/introduccio-al-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>eSpeak GUI 0.4 is out!</title>
		<link>http://bloc.eurion.net/archives/2012/espeak-gui-0-4/</link>
		<comments>http://bloc.eurion.net/archives/2012/espeak-gui-0-4/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 15:29:56 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet Debian]]></category>
		<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[Programari lliure]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[speech-synthesis]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1907</guid>
		<description><![CDATA[A few of you may remember espeak-gui, a graphical user interface for eSpeak I did release two years ago. While I haven&#8217;t been dedicating much time to it, it&#8217;s still alive and I&#8217;m happy to announce its fourth release! This new release introduced automatic language guessing, a feature I&#8217;ve wanted for a while, as well [...]]]></description>
				<content:encoded><![CDATA[<p>A few of you may remember <a href="https://launchpad.net/espeak-gui">espeak-gui</a>, a graphical user interface for eSpeak I did <a href="http://bloc.eurion.net/archives/2010/introducing-espeak-gui/">release two years ago</a>. While I haven&#8217;t been dedicating much time to it, it&#8217;s still alive and I&#8217;m happy to announce its fourth release!</p>
<p>This new release introduced automatic language guessing, a feature I&#8217;ve <a href="http://bloc.eurion.net/archives/2010/language-identification-and-free-software/">wanted for a while</a>, as well as spell checking (contributed by Joe Burmeister).</p>
<p>Version 0.3, released a year ago and which I didn&#8217;t announce here, did also introduce Undo/Redo, pausing, file history logging, a bunch of translations and some voice options. It&#8217;s sister project, <a href="https://launchpad.net/python-espeak">python-espeak</a>, did also get some bug fixes since its first release.</p>
<p>As usual, <a href="https://launchpad.net/~rainct/+archive/voice/+packages">packages for both espeak-gui and python-espeak</a> are available in <a href="https://launchpad.net/~rainct/+archive/voice/">my PPA</a>, and since last month in <a href="http://packages.debian.org/sid/espeak-gui">Debian unstable</a>. Make sure you also install <strong>libtextcat0</strong> (version 2.2-8 or newer) to get the language identification support.</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2012/espeak-gui-0-4/#comments">One comment</a><br />
© Siegfried-Angel Gevatter Pujals, 2012. |
<a href="http://bloc.eurion.net/archives/2012/espeak-gui-0-4/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/gnome/" rel="tag">gnome</a>, <a href="http://bloc.eurion.net/archives/tag/gtk/" rel="tag">gtk</a>, <a href="http://bloc.eurion.net/archives/tag/programari-lliure/" rel="tag">Programari lliure</a>, <a href="http://bloc.eurion.net/archives/tag/python/" rel="tag">python</a>, <a href="http://bloc.eurion.net/archives/tag/speech-synthesis/" rel="tag">speech-synthesis</a>, <a href="http://bloc.eurion.net/archives/tag/ubuntu/" rel="tag">Ubuntu</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2010/espeak-gui-0-2/' rel='bookmark' title='espeak-gui 0.2'>espeak-gui 0.2</a> <small>Yesterday I did a first release of espeak-gui, so while...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/introducing-espeak-gui/' rel='bookmark' title='Introducing espeak-gui'>Introducing espeak-gui</a> <small>I&#8217;m joining the hype of presenting little new projects there...</small></li>
<li><a href='http://bloc.eurion.net/archives/2009/here-is-zeitgeist-0-2-1/' rel='bookmark' title='Here is Zeitgeist 0.2.1!'>Here is Zeitgeist 0.2.1!</a> <small>One month after the first Zeitgeist release (0.2), here is...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2012/espeak-gui-0-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debian Games Team Meeting</title>
		<link>http://bloc.eurion.net/archives/2011/debian-games-team-meeting/</link>
		<comments>http://bloc.eurion.net/archives/2011/debian-games-team-meeting/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 15:24:18 +0000</pubDate>
		<dc:creator>Contributed Article</dc:creator>
				<category><![CDATA[Planet Debian]]></category>
		<category><![CDATA[Planet GNOME]]></category>
		<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[packaging]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1870</guid>
		<description><![CDATA[This announcement was provided by Martin Erik Werner. I&#8217;m reproducing it for Planet Ubuntu. The Debian/Ubuntu Games Team is organizing another meeting. If you&#8217;re into developing and/or packaging of games, or just generally curious about games in Debian/Ubuntu, you should join! It will be held next Saturday, the 26th of November, in the #debian-games channel [...]]]></description>
				<content:encoded><![CDATA[<p><small><strong>This announcement was provided by Martin Erik Werner. I&#8217;m reproducing it for Planet Ubuntu.</strong></small></p>
<p>The <a href="http://wiki.debian.org/Games/Team">Debian/Ubuntu Games Team</a> is organizing another <a href="http://wiki.debian.org/Games/Meetings/2011-11-26">meeting</a>. If you&#8217;re into developing and/or packaging of games, or just generally curious about games in Debian/Ubuntu, you should join!</p>
<p>It will be held next Saturday, the 26th of November, in the #debian-games channel on irc.debian.org (also know as irc.oftc.net) at 10:00 UTC. More information is available on the wiki page <a href="http://wiki.debian.org/Games/Meetings/2011-11-26">Games/Meetings/2011-11-26</a>.</p>
<p>The agenda starts off with the usual round of introductions, so if you&#8217;re new to the Team, say hi! Then we&#8217;ll be going through the action items from the last meeting, including work on the Debian Games LiveCD, and what&#8217;s up with the /usr/games/ path anyways?</p>
<p>Next we&#8217;ll be moving onto how the Games Team is faring in terms of members: are new recruits finding it comfortable, should we advertise more?</p>
<p>Next up it&#8217;s the squeeky penguin: Wheezy is somewhere in the not-completely-distant future, how does that affect the Games Team, should we be scuffling to get specific tasks done?</p>
<p>Then onto the recurring question of Sponsoring, and how to improve it, should we be utilising <a href="http://mentors.debian.net/">DebExpo</a> more? What about our favourite <a href="http://pet.debian.net/pkg-games/pet.cgi">PET</a>?</p>
<p>Lastly, <a href="http://www.playdeb.net/">PlayDeb</a> is doing some really neat stuff, would it make sense for our team to push some changes to PlayDeb? Would it make sense for PlayDeb to push changes to Debian Games?</p>
<p>Hopes are for a good discussion, and a merry time, hope to see you all there!</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/debian-games-team-meeting/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/debian-games-team-meeting/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/debian/" rel="tag">Debian</a>, <a href="http://bloc.eurion.net/archives/tag/games/" rel="tag">games</a>, <a href="http://bloc.eurion.net/archives/tag/packaging/" rel="tag">packaging</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2009/one-week-with-debian/' rel='bookmark' title='One week with Debian'>One week with Debian</a> <small>Jaunty was a great experience, until around a month (or...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/debious-a-dubious-debian-packaging-gui/' rel='bookmark' title='Debious &#8211; A dubious Debian packaging GUI'>Debious &#8211; A dubious Debian packaging GUI</a> <small>Just some little (unfinished) concept mockup. Seeing that much of...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/a-list-of-some-commercial-gnulinux-games/' rel='bookmark' title='A list of some commercial GNU/Linux games'>A list of some commercial GNU/Linux games</a> <small>I thought I&#8217;d be nice to make a little list...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/debian-games-team-meeting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts de Teoria de la Computació: Gramàtiques incontextuals</title>
		<link>http://bloc.eurion.net/archives/2011/teoria-computacio-gramatiques-incontextuals/</link>
		<comments>http://bloc.eurion.net/archives/2011/teoria-computacio-gramatiques-incontextuals/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 22:11:36 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[formal-grammar]]></category>
		<category><![CDATA[language-theory]]></category>
		<category><![CDATA[theory-of-computation]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1823</guid>
		<description><![CDATA[Una gramàtica incontextual (CFG, Context Free Grammar) és un conjunt de regles de substitució on les parts esquerres són mots de longitud 1. Aquestes regles les anomenarem produccions i les seves parts esquerres variables (o no-terminals). Els símbols restants els anomenem terminals. Dues regles com per exemple i es poden representar de forma agrupada de [...]]]></description>
				<content:encoded><![CDATA[<p>Una <strong>gramàtica incontextual</strong> (CFG, <em>Context Free Grammar</em>)  és un conjunt de regles de substitució on les parts esquerres són mots de longitud 1. Aquestes regles les anomenarem <em>produccions</em> i les seves parts esquerres <em>variables</em> (o <em>no-terminals</em>). Els símbols restants els anomenem <em>terminals</em>.</p>
<p>Dues regles com per exemple  i  es poden representar de forma agrupada de la següent manera: .</p>
<p>En una gramàtica sempre hi ha una variable (normalment la primera que apareix) que anomenem <em>símbol inicial</em>. Les paraules generades per la gramàtica són aquelles formades per <em>terminals</em> a les quals es pot arribar des del símbol inicial.</p>
<p>Podem representar les substitucions necessàries per arribar a una paraula amb la sintaxi ja coneguda, o bé en forma d&#8217;arbre (<i>arbre de derivació</i> o <i>arbre sintàctic</i>).</p>
<p>Les gramàtiques incontextuals també es poden representar formalment com una tupla .</p>
<p>Un llenguatge s&#8217;anomena <strong>llenguatge incontextual</strong> si existeix una gramàtica que el genera. Existeixen algorismes  per comprovar si una paraula és generable per una gramàtica i generar-ne l&#8217;arbre sintàctic. Això és útil per a compiladors i intèrprets.</p>
<p>Quan una gramàtica permet més d&#8217;un arbre de derivació per a una paraula diem que és ambigua. Això no és desitjable quan volem utilitzar la gramàtica per interpretar el significat de les entrades.</p>
<p>Un criteri per determinat l&#8217;ambigüitat quan només utilitzem <i>regles lineals</i> (on cada alternativa de la part dreta només inclou una única variable): si no existeixen dues alternatives amb que es pugui generar el mateix, llavors la regla no genera ambigüitat.</p>
<p>
<hr /></p>
<h4>Operacions sobre gramàtiques</h4>
<p></p>
<p>Els llenguatges incontextuals estan tancats per unió: Tenim dues CFG  i  que generen els llenguatges  i . Suposem que els llenguatges no comparteixen variables (si no fos així, les podem reanomenar). Si definim la operació <i>unió de gramàtiques</i>  llavors aquesta compleix .</p>
<p>També ho són per <i>concatenació</i>. Amb les mateixes condicions que abans,  compleix .</p>
<p>Per l&#8217;operació estrella:  compleix .</p>
<p>Per l&#8217;operació <i>revessat</i>:  compleix  ja que .</p>
<p>I per <i>imatge de morfisme</i>:  i  tal que . En aquest cas a la tupla de la gramàtica resultant es substitueix  per .</p>
<p>En canvi, no són tancats per intersecció (si ) ni complementari.</p>
<p><em>Aquests apunts estan basats en els vídeos de <a href="http://www.lsi.upc.edu/~ggodoy/tc.html">Teoria de la Computació</a> de Guillem Godoy (UPC).</em></p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/teoria-computacio-gramatiques-incontextuals/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/teoria-computacio-gramatiques-incontextuals/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/formal-grammar/" rel="tag">formal-grammar</a>, <a href="http://bloc.eurion.net/archives/tag/language-theory/" rel="tag">language-theory</a>, <a href="http://bloc.eurion.net/archives/tag/theory-of-computation/" rel="tag">theory-of-computation</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/' rel='bookmark' title='Apunts de Teoria de la Computació: Teoria de llenguatges'>Apunts de Teoria de la Computació: Teoria de llenguatges</a> <small>Un alfabet () és un conjunt finit d&#8217;elements (símbols), habitualment...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/teoria-computacio-gramatiques-incontextuals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts de Teoria de la Computació: Teoria de llenguatges</title>
		<link>http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/</link>
		<comments>http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 12:49:05 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[formal-grammar]]></category>
		<category><![CDATA[language-theory]]></category>
		<category><![CDATA[theory-of-computation]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1767</guid>
		<description><![CDATA[Un alfabet () és un conjunt finit d&#8217;elements (símbols), habitualment caràcters alfanumèrics. Un mot és una llista de símbols d’un alfabet. El mot buit (llista de longitud 0) el denotarem amb el meta-símbol . Utilitzarem , , , , &#8230; per denominar paraules. Paraules: ab, bbb, a, Longituds: &#124;ab&#124;=2, &#124;bbb&#124;=3, &#124;a&#124;=1, &#124;&#124;=0 Extenem la notació [...]]]></description>
				<content:encoded><![CDATA[<p>Un <strong>alfabet</strong> () és un conjunt finit d&#8217;elements (símbols), habitualment caràcters alfanumèrics.</p>
<p>Un <em>mot</em> és una llista de símbols d’un alfabet. El mot buit (llista de longitud 0) el denotarem amb el meta-símbol . Utilitzarem , , , , &#8230; per denominar paraules.</p>
<p style="margin-left: 50px;">
  <br />
  Paraules: ab, bbb, a, <br />
  Longituds: |ab|=2, |bbb|=3, |a|=1, ||=0
</p>
<p>Extenem la notació de les longituds per a occurències d’un mot dins d’un altre: </p>
<p style="margin-left: 50px;">
  , , 
</p>
<p>Per referir-nos al símbol i-éssim del mot u utilitzarem: u[i]</p>
<p style="margin-left: 50px;">
  ab[1] = a, ab[2] = b
</p>
<p>Amb la operació producte ( o ) representem la concatenació de dues paraules. Per exemple:</p>
<p style="margin-left: 50px;">
  <br />
  Element neutre: <br />
  Associativitat: 
</p>
<p>
Amb  representem el conjunt de tots els mots possibles que podem construir amb l’alfabet . Exemple per a :</p>
<p><span id="more-1767"></span></p>
<p style="margin-left: 50px;">
  
</p>
<p>Un llenguatge sobre l’alfabet  és un subconjunt qualsevol . Per exemple:</p>
<ul>
<li>
  Paraules sobre l’alfabet {a, b} i de longituds múltiples de 2:<br />
  &nbsp; &nbsp;
</li>
<li>
  Paraules amb algun símbol «a»:<br />
  &nbsp; &nbsp;
</li>
<li>
  Paraules tals que tota ocurrència d’«a» ve seguida d’una occurència de «b»:<br />
  &nbsp; &nbsp;<br />
  &nbsp; &nbsp;
</li>
<p>
<hr /></p>
<p>Denotem el llenguatge que conté només el mot buit amb  ().</p>
<p>Definim la concatenació de dos llenguatges:</p>
<p style="margin-left: 50px;">
   </p>
<p>  Exemples:
  </p>
<p style="margin-left: 50px;">
    <br />
    Element neutre: <br />
    No funciona amb el conjunt buit: <br />
    Associativitat: 
  </p>
<p>Definim l&#8217;exponenciació de paraules:</p>
<p style="margin-left: 50px;">
  </p>
<p>  Exemples:
  </p>
<p style="margin-left: 50px;">
        
  </p>
<p>  Es compleix que: , .</p>
<p>Ídem per a l&#8217;exponenciació de llenguatges.</p>
<p>Definim també l&#8217;operació  (<a href="http://ca.wikipedia.org/wiki/Clausura_de_Kleene">clausura de Kleene</a>) d&#8217;un llenguatge. Aquesta dóna com a resultat un nou llenguatge que conté aquelles paraules que es poden obtenir a base d&#8217;escollir un nombre finit de paraules d&#8217;L i concatenar-les.</p>
<p style="margin-left: 50px;">
  <br />
  (Les paraules d&#8217; són concatencions de 0, 1, 2, &#8230; paraules d&#8217;L.)</p>
<p>  Per exemple:
  </p>
<p style="margin-left: 50px;">
    <br />
    <br />
    <br />
    
  </p>
<p>De forma semblant definim l&#8217;operació , la qual no obliga a incloure el mot buit.</p>
<p style="margin-left: 50px;">
  <br />
  <br />
  
</p>
<p>
<hr /></p>
<p>Denominem el <em>revessat</em> d&#8217;un mot : . Exemple:</p>
<p style="margin-left: 50px;">
  
</p>
<p>El revessat de la concatenació de dues paraules correspon al revessat de les dues paraules:</p>
<p style="margin-left: 50px;">
  
</p>
<p>També tenim el revessat d&#8217;un llenguatge:</p>
<p style="margin-left: 50px;">
  <br />
  </p>
<p>  Per exemple:
  </p>
<p style="margin-left: 50px;">
    
  </p>
<p>Definim un <strong>morfisme</strong> com una funció que transforma paraules d&#8217;un alfabet a un altre:</p>
<p style="margin-left: 50px;">
  <br />
  Commutativa amb la concatenació: 
</p>
<p style="margin-left: 50px;">
  <br />
  
</p>
<p>Gràcies a la commutativitat, tenim prou per definir un morfisme amb definir la imatge dels símbols de l’alfabet, ja que llavors l’imatge de qualsevol mot es pot calcular en termes de les imatges dels símbols.</p>
<p>Per exemple:</p>
<p style="margin-left: 50px;">
  <br />
  , , 
</p>
<p style="margin-left: 50px;">
  
</p>
<p>Per a un llenguatge L:</p>
<p style="margin-left: 50px;">
  <br />
   &nbsp; <br />
   &nbsp; <br />
  
</p>
<p>Una <strong>regla de reescriptura</strong> (o <em>substitució</em>) és un parell de paraules . Per exemple, la regla  substitueix tota ocurrència d&#8217;«ab» per «bba».</p>
<p>Representem una substitució de la forma . Per exemple:</p>
<p style="margin-left: 50px;">
  
</p>
<p>Si R és un conjunt de regles, podem indicar que  es transforma en &#8230;</p>
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>aplicant 1 regla d&#8217;R</td>
<td>aplicant 0 o mes substitucions amb regles d&#8217;R</td>
<td>aplicant 1 o més substitucions amb regles d&#8217;R</td>
<td>aplicant  substitucions amb regles d&#8217;R</td>
</tr>
</table>
<p></p>
<p><em>Aquests apunts estan basats en els vídeos de <a href="http://www.lsi.upc.edu/~ggodoy/tc.html">Teoria de la Computació</a> de Guillem Godoy (UPC).</em></ul>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/formal-grammar/" rel="tag">formal-grammar</a>, <a href="http://bloc.eurion.net/archives/tag/language-theory/" rel="tag">language-theory</a>, <a href="http://bloc.eurion.net/archives/tag/theory-of-computation/" rel="tag">theory-of-computation</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/teoria-computacio-gramatiques-incontextuals/' rel='bookmark' title='Apunts de Teoria de la Computació: Gramàtiques incontextuals'>Apunts de Teoria de la Computació: Gramàtiques incontextuals</a> <small>Una gramàtica incontextual (CFG, Context Free Grammar) és un conjunt...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/' rel='bookmark' title='Apunts de Càlcul: Funcions d&#8217;una variable'>Apunts de Càlcul: Funcions d&#8217;una variable</a> <small>Introducció Considerem una funció real de variable real tal que...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-calcul-cost-algorismes/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs'>Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs</a> <small>Introducci&oacute; Els algorismes s&oacute;n per tot arreu i per aix&ograve;...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts de Bases de Dades</title>
		<link>http://bloc.eurion.net/archives/2011/apunts-de-bases-de-dades/</link>
		<comments>http://bloc.eurion.net/archives/2011/apunts-de-bases-de-dades/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 18:35:02 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1206</guid>
		<description><![CDATA[Introducci&#243; Els tres mons M&#243;n &#160; Disseny&#8230; (BD) Enginyeria del Software Depend&#232;ncia tecnol&#242;gica M&#243;n real objectes del m&#243;n real conceptual especificaci&#243; independent M&#243;n conceptual coneixements / informaci&#243; M&#243;n de les representacions dades l&#242;gic i f&#237;sic disseny dependent M&#243;n conceptual Classes d&#39;objectes: quelcom real, identificable i distingible. &#8230; [FIXME: imatge diagrama UML] &#8230; M&#243;n de les [...]]]></description>
				<content:encoded><![CDATA[<h3>Introducci&oacute;</h3>
<h4>Els tres mons</h4>
<table border="1" style="margin-top: 1em; margin-bottom: 1em;">
<thead>
<tr>
<td style="text-align: center; ">M&oacute;n</td>
<td>&nbsp;</td>
<td style="text-align: center; ">Disseny&#8230; (BD)</td>
<td style="text-align: center; ">Enginyeria del Software</td>
<td style="text-align: center; ">Depend&egrave;ncia tecnol&ograve;gica</td>
</tr>
</thead>
<tbody>
<tr>
<td><strong>M&oacute;n real</strong></td>
<td><em>objectes del m&oacute;n real</em></td>
<td rowspan="2" style="text-align: center; ">conceptual</td>
<td rowspan="2" style="text-align: center; ">especificaci&oacute;</td>
<td rowspan="2" style="text-align: center; ">independent</td>
</tr>
<tr>
<td><strong>M&oacute;n conceptual</strong></td>
<td><i>coneixements / informaci&oacute;</i></td>
</tr>
<tr>
<td><strong>M&oacute;n de les representacions</strong></td>
<td><em>dades</em></td>
<td style="text-align: center; ">l&ograve;gic i f&iacute;sic</td>
<td style="text-align: center; ">disseny</td>
<td style="text-align: center; ">dependent</td>
</tr>
</tbody>
</table>
<h5>M&oacute;n conceptual</h5>
<p>Classes d&#39;objectes: quelcom real, identificable i distingible.</p>
<p>&#8230; [FIXME: imatge diagrama UML] &#8230;</p>
<h5>M&oacute;n de les representacions</h5>
<p>El m&eacute;s obvi seria utilitzar fitxers (i directoris), per&ograve; aquests no es permeten representar associacions tal com nosaltres volem. Per aquest motiu, neix el concepte de&nbsp;<strong>base de dades</strong>: un <u>conjunt estructurat de dades</u> que permet representar classes d&#39;objectes i les seves associacions amb <u>integraci&oacute;</u> (sense repeticions) i <u>compartici&oacute;</u> (molts usuari alhora) de dades.</p>
<h6>Evoluci&oacute;:</h6>
<ul>
<li>Model jer&agrave;rquic: arbres (IBM). Tenen el problema que un fill pot tenir nom&eacute;s un sol pare.</li>
<li>Model en xarxa: xarxes.</li>
<li>Model relacional (1969,&nbsp;<a href="http://ca.wikipedia.org/wiki/Edgar_F._Codd">Codd</a>): <u>taules</u>.</li>
</ul>
<h4>SGBD (<em>DBMS</em>)</h4>
<p>Un <strong>sistema gestor de bases de dades</strong>&nbsp;(<em>database management system</em>) &eacute;s un programa complex que facilita la representaci&oacute; de classes d&#39;objectes i les seves associacions i diverses tasques de gesti&oacute; de dades als programes d&#39;aplicaci&oacute;. Nosaltres utilitzarem el <em>PostgreSQL</em>.</p>
<p><span id="more-1206"></span></p>
<h3>El model relacional</h3>
<h4>Objectius i origens</h4>
<p>Origen: E. F. Codd, 1969.</p>
<p>Primers prototipus: al comen&ccedil;ament dels anys 80.</p>
<p>Objectius: Facilita que la base de dades sigui percebuda com una estructura l&ograve;gica independent de l&#39;estructura f&iacute;sica, simple i uniforme.</p>
<h4>Estructura de les dades</h4>
<p><a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Estructura-de-dades.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Estructura-de-dades.png" alt="" title="Estructura de dades" width="371" height="163" class="alignright size-full wp-image-1698" style="margin-top: 0;" /></a></p>
<table border="1">
<thead>
<tr>
<td><strong>Model relacional</strong></td>
<td><strong>SQL (ANSI)</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>Relacions</td>
<td>Taules</td>
</tr>
<tr>
<td>Atributs</td>
<td>Columnes</td>
</tr>
<tr>
<td>Tuples</td>
<td>Files</td>
</tr>
</tbody>
</table>
<p>Una <strong>relaci&oacute;</strong> es compon de:</p>
<ul>
<li><strong>Esquema</strong> de la relaci&oacute; (intensi&oacute;) (cap&ccedil;alera)<br />
		&Eacute;s el nom de la relaci&oacute; i els seus <strong>atributs</strong>. Per exemple: &laquo;estudiants(codi, dni, nom, tel&egrave;fon)&raquo;.</p>
<ul>
<li><strong>Atribut</strong>: &eacute;s el paper o rol que juga un <strong>domini</strong> en una relaci&oacute;.</li>
<li><strong>Domini</strong>: &eacute;s un conjunt de valors at&ograve;mics. Per exemple: &laquo;int&raquo;, &laquo;char(30)&raquo;, etc.</li>
<li><strong>Valors nuls</strong>: (SQL: <em>NULL</em>) desconegut i inaplicable.</li>
</ul>
</li>
<li><strong>Extensi&oacute;</strong> de la relaci&oacute;<br />
		L&#39;extensi&oacute; d&#39;una relaci&oacute; d&#39;esquema R(A1, A2, &#8230;, An) &eacute;s un conjunt de <strong>tuples</strong> Tj=&lt;V11, V12, &#8230;, Vn&gt;, on Vij &eacute;s un valor del domini d&#39;Aj o b&eacute; un valor nul.</p>
<ul>
<li><strong>Tupla</strong>: &eacute;s un element de l&#39;extensi&oacute; de la relaci&oacute;.</li>
<li><strong>Grau</strong>: &eacute;s el nombre d&#39;atributs d&#39;una relaci&oacute;.</li>
<li><strong>Cardinalitat</strong>: &eacute;s el nombre de tuples d&#39;una relaci&oacute;.</li>
</ul>
</li>
</ul>
<p>Una relaci&oacute; ha de contenir valors at&ograve;mics (un sol valor), no hi ha tuples repetides i no hi ha ordre entre les tuples ni entre els atributs.</p>
<p><strong>Superclau</strong>: &eacute;s un subconjunt dels atributs de l&#39;esquema de la relaci&oacute; que identifica les tuples de l&#39;extensi&oacute; de la relaci&oacute;.</p>
<p><strong>Clau</strong> (claus candidates): &eacute;s una superclau d&#39;una relaci&oacute; que no t&eacute; cap subconjunt propi que sigui alhora superclau. Es divideixen en la <strong>clau prim&agrave;ria</strong> (la clau candidata que hagi estat escollida) i <strong>claus secund&agrave;ries </strong>o alternatives.</p>
<p><strong>Clau forana</strong>: subconjunt dels atributs de l&#39;esquema de la relaci&oacute; que referencia una clau prim&agrave;ria d&#39;una altre relaci&oacute; o de la pr&ograve;pia relaci&oacute;.</p>
<h4>Regles d&#8217;integritat</h4>
<ul>
<li>
<p><strong>Regla d&#8217;integritat d&#8217;entitat</strong></p>
<p>Una clau primària d&#8217;una relació no pot tenir ni valors nuls ni valors repetits.</p>
</li>
<li>
<p><strong>Regla d&#8217;integritat referencial</strong></p>
<p>Els valors d&#8217;una clau forana poden ser només valors de la clau primària referenciada o valors nuls.</p>
<p>Polítiques d&#8217;actuació en cas d&#8217;esborrat o modificació de claus primàries amb claus foranes referenciant-les:
<ul>
<li><strong>Restricció</strong>: no es permet esborrar o modificar una clau primària referenciada per claus foranes (SQL: RESTRICT / NOACTION).</li>
<li><strong>Actualització en cascada</strong>: en cas d&#8217;esborrar o modificar una clau primària referenciada en alguna clau forana, s&#8217;esborren o modifiquen totes les referències (SQL: CASCADE).</li>
<li><strong>Anul&middot;lació</strong>: en cas d&#8217;esborrar o modificar una clau primària referenciada s&#8217;assignen valors nuls a totes les referències (SQL: SET NULL / SET DEFAULT).</li>
</ul>
</li>
<li>
<p><strong>Regla d&#8217;integritat de domini</strong></p>
<ol>
<li>Un valor no nul d&#8217;un atribut ha de pertànyer al domini de l&#8217;atribut.</li>
<li>Les operacions que es poden aplicar sobre els valors depenen dels dominis dels valors.</li>
</ol>
</li>
</ul>
<h3>Àlgebra relacional</h3>
<table border="0" class="noborder">
<tr>
<td>Unió</td>
<td>R=TAULA1&cup;TAULA2</td>
<td>uneix tots els resultats de dues taules amb columnes compatibles</td>
</tr>
<tr>
<td>Reanomenament</td>
<td colspan="2">R=TAULA1{foo->bar, meh->moh}</td>
</tr>
<tr>
<td>Intersecció</td>
<td>R=T1&cap;T2</td>
<td>torna els resultats coincidents de les dues taules</td>
</tr>
<tr>
<td>Diferència</td>
<td>R=T1-T2</td>
<td>suprimeix els resultats de T1 coincidents en T2</td>
</tr>
<tr>
<td>Producte cartesià</td>
<td>R=T1xT2</td>
<td>combina tots els resultats de 2 taules (no compatibles)</td>
</tr>
<tr>
<td>Selecció</td>
<td colspan="2">R=T1(superfície>16, mòdul=&#8217;B2&#8242;)</td>
</tr>
<tr>
<td>Projecció</td>
<td colspan="2">R=T1[nom, ciutat]</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td>Combinació (<em>join</em>)</td>
<td>R=EMPLEATS[despatx=id]DESPATXOS</td>
<td>combina i torna els resultats combinats</td>
</tr>
<tr>
<td style="vertical-align: top;"><em>Natural join</em></td>
<td style="vertical-align: top;">R=EMPLEATS[despatx*id]DESPATXOS<br />EMPLATS*DESPATXOS <small>(si les columnes tenen el mateix nom)</small></td>
<td style="vertical-align: top;">els resultats només contenen «despatx» i no l&#8217;«id» duplicat</td>
</tr>
</table>
<h3>Components lògics d&#8217;una base de dades</h3>
<p>Un <strong>esquema</strong>, per a un SGBD, és un conjunt <strong>definit</strong> i relacionat de components de dades i components de control.</p>
<table border="0" class="noborder">
<tr>
<td style="vertical-align: top;">
<pre>
CREATE SCHEMA nom_esquema
AUTHORIZATION identitat_usuari
[llista d'elemens de l'esquema]
</pre>
<p>Esborrat d&#8217;esquema:</p>
<pre>DROP SCHEMA nom_esquema RESTRICT/CASCADE</pre>
</td>
<td style="vertical-align: top;">Alternativament, en implementacions no estàndards:</p>
<pre>
CREATE DATABASE
CREATE DM
</pre>
</td>
</tr>
</table>
<h5>Connexions</h5>
<pre>CONNECT TO nom_servidor [AS nom_connexió] [USER ...]
DISCONNECT nom_connexió DEFAULT/CURRENT/ALL</pre>
<h5>Sessió</h5>
<pre>SET SESSION CHARACTERISTICS AS mode_trans</pre>
<h5>Transaccions</h5>
<pre>SET TRANSACTION mode_trans / START TRANSACTION
mode_trans: mode d'accés / nivell d'aïllament (READONLY / READ WRITE)
</pre>
<pre>
COMMIT: s'accepta tot.
</pre>
<pre>
ROLLBACK: no s'accepta res (es desfan els canvis).</pre>
<h5>Dominis</h5>
<pre>CREATE DOMAIN ciutats AS CHAR(15)
DEFAULT 'BCN'
CONSTRAINT ciutats_valides CHECK VALUE IN ('BCN', 'GIR', 'TGN')
</pre>
<h5>Taules</h5>
<pre>
CREATE TABLE empleats(
  codi_empl INTEGER PRIMARY KEY,
  nom_empl VARCHAR(30),
  dni CHAR(8) UNIQUE,
  sou REAL NOT NULL,
  data_naix DATE CONSTRAINT naix_impossible CHECK (data_naix >= 01/01/1900),
  data_jubilacio DATE,
  ciutat_resid CIUTATS,
  dept INTEGER DEFAULT 1 REFERENCES departaments(id)
</pre>
<p>Aquesta última referència també s&#8217;hauria pogut especificar al final:</p>
<pre>FOREIGN KEY (dept) REFERENCES departaments(id) [ON DELETE ...] [ON UPDATE ...]</pre>
<h5>Assercions</h5>
<p>Ens permeten definir restriccions d&#8217;integritat a més d&#8217;una taula. Es comproven sempre. SQL:
<pre>CREATE ASSERTION nom CHECK (condition)</pre>
<p>No estan implementades en cap SBGD, ja que disposen de <small>TRIGGER</small> (disparadors) que permeten la mateixa funcionalitat i són més potents.</p>
<h5>Vistes (esquemes externs)</h5>
<p>Una vista és una relació (es pot consultar i <em>actualitzar</em>) <strong>derivada</strong> (no existeix físicament, sinó que és <em>virtual</em>).</p>
<pre>CREATE VIEW nom (nom_col1, nom_col2, ...., nom_coln) AS <consulta SQL> [WITH CHECK OPTION]</consulta></pre>
<h5>Procediments (<em>PL/pgSQL</em>)</h5>
<pre>
CREATE FUNCTION troba_ciutat(dni_ciutat VARCHAR(9)) RETURNS VARCHAR(15) AS $$
DECLARE
  ciutat_client VARCHAR(15);
BEGIN
  SELECT ciutat INTO ciutat_client
    FROM empleats
    WHERE dni=dni_client;
  RETURN ciutat_client;
END;
$$LANGUAGE plpgsql;
</pre>
<h5>Disparadors (<em>triggers</em>)</h5>
<pre>
CREATE TRIGGER nom_disparador
  BEFORE UPDATE ON nom_taula
  FOR EACH ROW EXECUTE PROCEDUR acció;
</pre>
<h5>Privilegis</h5>
<pre>
GRANT privilegis ON objectes TO usuaris [WITH GRANT OPTION]
REVOKE [GRANT OPTION FOR] privilegis ON objects FROM usuaris [CASCADE|RESTRICT]
GRANT PUBLIC ...
</pre>
<pre>
CREATE ROLE nom;
SET ROLE nom;
</pre>
<h3>Traducció de disseny a model relacional</h3>
<p>La següent taula resumeix com transformar els elements d&#8217;un disseny UML per tal d&#8217;implementar-lo com a base de dades en un SGBD:</p>
<table>
<tr>
<th>Model semàntic</th>
<th>Model relacional</th>
</tr>
<tr>
<td>Classes d&#8217;objectes</td>
<td>Relació</td>
</tr>
<tr>
<td>Associació binària un a molts</td>
<td>Clau forana</td>
</tr>
<tr>
<td>Associació binària un a un</td>
<td>Clau forana</td>
</tr>
<tr>
<td>Associació binària molts a molts</td>
<td>Relació</td>
</tr>
<tr>
<td>Associació unària</td>
<td>Relació</td>
</tr>
<tr>
<td>Associació recursiva</td>
<td>(Igual que les altres)</td>
</tr>
<tr>
<td>Classe associativa</td>
<td>TODO: imatge&#8230;</td>
</tr>
</table>
<h3>Transaccions i concurrència</h3>
<h4>Transaccions</h4>
<p><strong>ACID</strong>: atomicitat, consistència, «isolació», durabilitat.</p>
<p>Tipus d&#8217;interferències entre transaccions:
<ul>
<li>actualització perduda (doble actualització)</li>
<li>lectura no confirmada</li>
<li>lectura no repetible</li>
<li>anàlisi inconsistent</li>
<li>fantasmes</li>
</ul>
<h4>Serialitzabilitat</h4>
<p>La teoria de la serialitzabilitat defineix de manera precisa les condicions que s&#8217;han de complir per considerar que les transaccions estan aïllades entre si correctament.</p>
<p>&#8230;</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/apunts-de-bases-de-dades/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/apunts-de-bases-de-dades/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/databases/" rel="tag">databases</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/sql/" rel="tag">sql</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/eda-diccionaris/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Diccionaris'>Apunts d&#8217;Estructures de Dades i Algorismes: Diccionaris</a> <small>Introducci&oacute; S&oacute;n un tipus abstracte de dades (TAD), &eacute;s a...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-p-np/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Les classes de problemes P i NP'>Apunts d&#8217;Estructures de Dades i Algorismes: Les classes de problemes P i NP</a> <small>Classes de problemes &ndash; P i NP Entrades Problemes Classes...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Programació dinàmica'>Apunts d&#8217;Estructures de Dades i Algorismes: Programació dinàmica</a> <small>1. Nombres de Fibonacci L&#39;algorisme trivial per al c&agrave;lcul dels...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/apunts-de-bases-de-dades/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trigonometria: Sinus, cosinus i tangent dels angles 30º, 45º i 60º</title>
		<link>http://bloc.eurion.net/archives/2011/trigonometria-sin-cos-tan-30-45-60/</link>
		<comments>http://bloc.eurion.net/archives/2011/trigonometria-sin-cos-tan-30-45-60/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 02:22:58 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1648</guid>
		<description><![CDATA[Com trobar els valors? Taula resum &#160; 30º 45º 60º sin cos tg No comments © Siegfried-Angel Gevatter Pujals, 2011. &#124; Permalink &#124; License &#124; Post tags: maths]]></description>
				<content:encoded><![CDATA[<table border="0" style="border: 0; width: 100%;">
<tr>
<td style="border: 0; vertical-align: top;">
<h5>Com trobar els valors?</h5>
<table border="0">
<tr>
<td><a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Triangle-amb-un-angle-de-45-graus.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Triangle-amb-un-angle-de-45-graus.png" alt="" title="Triangle amb un angle de 45 graus" width="250" height="191" class="aligncenter size-full wp-image-1688" /></a></td>
<td>
  </td>
</tr>
<tr>
<td rowspan="2"><a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Triangle-amb-angles-de-30-i-60-graus.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Triangle-amb-angles-de-30-i-60-graus-300x218.png" alt="" title="Triangle amb angles de 30 i 60 graus" width="300" height="218" class="aligncenter size-medium wp-image-1687" /></a></td>
<td>
  </td>
</tr>
<tr>
<td>
  </td>
</tr>
</table>
</td>
<td style="border: 0; vertical-align: top;">
<h5>Taula resum</h5>
<table border="0" style="font-size: large;">
<tr>
<th>&nbsp;</th>
<th>30º</th>
<th>45º</th>
<th>60º</th>
</tr>
<tr>
<th>sin</th>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
<tr>
<th>cos</th>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
<tr>
<th>tg</th>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
</table>
</td>
</tr>
</table>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/trigonometria-sin-cos-tan-30-45-60/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/trigonometria-sin-cos-tan-30-45-60/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/maths/" rel="tag">maths</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/' rel='bookmark' title='Apunts de Càlcul: Nombres reals i nombres complexos'>Apunts de Càlcul: Nombres reals i nombres complexos</a> <small>1. Nombres reals Naturals Propietats: Propietats: Enters La suma també...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/trigonometria-sin-cos-tan-30-45-60/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts de Càlcul: Funcions d&#8217;una variable</title>
		<link>http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/</link>
		<comments>http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 01:53:38 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[calculus]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1557</guid>
		<description><![CDATA[Introducció Considerem una funció real de variable real tal que existeix com a màxim un . Definim: Definim el domini d&#8217;una funció: I el recorregut d&#8217;una funció: També: &#160; Exemple Tipus de funcions Una funció : és parella és imparella és periòdica de període és creixent (no decreixent) és estrictament creixent és decreixent és estrictament [...]]]></description>
				<content:encoded><![CDATA[<h5>Introducció</h5>
<p>Considerem una funció real de variable real  tal que  existeix com a màxim un . Definim:</p>
<p>Definim el <a href="http://ca.wikipedia.org/wiki/Domini_(matem%C3%A0tiques)">domini</a> d&#8217;una funció:<br />
</p>
<p>I el <a href="http://ca.wikipedia.org/wiki/Recorregut_(matem%C3%A0tiques)">recorregut</a> d&#8217;una funció:<br />
</p>
<p>També: &nbsp;</p>
<p><strong>Exemple</strong></p>
<table border="0" style="margin-left: 50px;">
<tr>
<td>
  
</td>
<td>
 <br />
 <br />
 
</td>
</td>
</tr>
</table>
<h5>Tipus de funcions</h5>
<p>Una funció :</p>
<p><span id="more-1557"></span></p>
<ol>
<li>és <strong>parella</strong> </li>
<li>és <strong>imparella</strong> </li>
<li>és <strong>periòdica de període </strong> </li>
<li>és <strong>creixent</strong> (no decreixent) </li>
</li>
<li>és <strong>estrictament creixent</strong> </li>
</li>
<li>és <strong>decreixent</strong> </li>
</li>
<li>és <strong>estrictament decreixent</strong> </li>
<li>està <strong>acotada superiorment</strong> </li>
<li>està <strong>acotada inferiorment</strong> </li>
<li>està <strong>acotada</strong> </li>
<li>és <strong>injectiva</strong> </li>
<li>és <strong>exhaustiva</strong> </li>
<li>és <strong>bijectiva</strong>  és injectiva i exhaustiva ()</li>
</ol>
<h5>Operacions amb funcions</h5>
<table border="0" class="noborder">
<tr>
<td>

</td>
<td>

</td>
</tr>
</table>
<h5>Composició de funcions</h5>
<p>&nbsp;</p>
<h5>Funció inversa</h5>
<table border="0" class="noborder" style="margin-top: -10px;">
<tr>
<td>
 
</td>
<td>
 Funció injectiva  la seva funció inversa és   &nbsp; &nbsp; &nbsp; &nbsp; 
</td>
</tr>
</table>
<h5>Asímptotes</h5>

<table border="0">
<tr>
<td> és una <strong>asímptota vertical</strong> de la funció </td>
<td><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Asímptota-vertical.png" alt="" title="Asímptota vertical" width="111" height="94" class="aligncenter size-full wp-image-1633" /></td>
</tr>
<tr>
<td style="min-width: 300px;"> és una <strong>asímptota horizontal</strong>&#8230;</p>
<ul>
<li><strong>per la dreta</strong> </li>
<li><strong>per l&#8217;esquerra</strong> </li>
</ul>
</td>
<td><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Asímptota-horizontal.png" alt="" title="Asímptota horizontal" width="95" height="74" class="aligncenter size-full wp-image-1616" /></td>
</tr>
<tr>
<td colspan="2"> és una <strong>asímptota oblíqua</strong>&#8230;</p>
<ul>
<li><strong>per la dreta</strong> d&#8217; i </li>
<li><strong>per l&#8217;esquerra</strong> (igual que per la dreta però amb )</li>
</ul>
</td>
</tr>
</table>
<h5>Continuïtat</h5>
<table border="0" class="noborder">
<tr>
<td style="vertical-align: top;"></td>
<td style="vertical-align: top;">
<p> és <strong>contínua en </strong>  (amb ).</p>
<p> és <strong>contínua en </strong>  és contínua en , .</p>
</td>
</tr>
</table>
<h6>Tipus de punts de discontinuïtat d&#8217;una funció</h6>
<table border="0">
<tr>
<td>
<p> és un punt de <strong>discontinuïtat evitable</strong> d&#8217; .</p>
<p>Per evitar aquest tipus de discontinuïtat podem redefinir la funció: </p>
</td>
</tr>
<tr>
<td>
<p>Si  és un punt de <strong> discontinuïtat essencial</strong>.</p>
<p style="margin-left: 50px;">Si  és un punt de <strong>discontinuïtat asimptòtica</strong> o <strong>de 2a espècia.</strong></p>
<p style="margin-left: 50px;">Si  és un punt de discontinuïtat <strong>de salt finit</strong>.</p>
</td>
</tr>
</table>
<h5>Derivabilitat</h5>
<table border="0" class="noborder">
<tr>
<td style="vertical-align: top;"></td>
<td style="vertical-align: top;">
<p> és derivable en  si . Aquest és igual a  =  = pendent de la recta tangent a la curva  en el punt d&#8217;abscissa , .</p>
</td>
</tr>
<tr>
<td><a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Derivabilitat.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Derivabilitat-300x225.png" alt="" title="Derivabilitat" width="300" height="225" class="aligncenter size-medium wp-image-1694" /></a></td>
<td>Recta tangent a  on el punt d&#8217;: .</td>
</tr>
</table>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/calculus/" rel="tag">calculus</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/maths/" rel="tag">maths</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/' rel='bookmark' title='Apunts de Càlcul: Nombres reals i nombres complexos'>Apunts de Càlcul: Nombres reals i nombres complexos</a> <small>1. Nombres reals Naturals Propietats: Propietats: Enters La suma també...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-calcul-cost-algorismes/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs'>Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs</a> <small>Introducci&oacute; Els algorismes s&oacute;n per tot arreu i per aix&ograve;...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/computacio-teoria-de-llenguatges/' rel='bookmark' title='Apunts de Teoria de la Computació: Teoria de llenguatges'>Apunts de Teoria de la Computació: Teoria de llenguatges</a> <small>Un alfabet () és un conjunt finit d&#8217;elements (símbols), habitualment...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts de Càlcul: Nombres reals i nombres complexos</title>
		<link>http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/</link>
		<comments>http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 01:09:47 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[calculus]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1424</guid>
		<description><![CDATA[1. Nombres reals Naturals Propietats: Propietats: Enters La suma també és una operació interna i té element neutre (0) i element oposat. El producte no canvia (és igual que amb els nombres naturals). Racionals La suma segueix igual que en el cas anterior (associativa, commutativa, element neutre, element oposat). El producte guanya l&#8217;element invers: Podem [...]]]></description>
				<content:encoded><![CDATA[<h4>1. Nombres reals</h4>
<p>
<strong>Naturals</strong> </p>
<div style="margin-left: 50px;">
</p>
<p>Propietats: </p>

<p>Propietats: 
</p></div>
</p>
<p>
<strong>Enters</strong> </p>
<div style="margin-left: 50px;">
La suma també és una <a href="http://ca.wikipedia.org/wiki/Operaci%C3%B3_matem%C3%A0tica#Llei_de_composici.C3.B3_interna">operació interna</a> i té element neutre (0) i element oposat. El producte no canvia (és igual que amb els nombres naturals).
</div>
</p>
<p>
<strong>Racionals</strong> </p>
<div style="margin-left: 50px;">
La suma segueix igual que en el cas anterior (associativa, commutativa, element neutre, element oposat).</p>
<p>El producte guanya l&#8217;element invers: </p>
<p>Podem resumir-ho com a:  <a href="http://ca.wikipedia.org/wiki/Cos_(matem%C3%A0tiques)">cos commutatiu</a>.</p>
<p>A més,  té les propietats:</p>
<ol>
<li>donats 2 nombres racionals, existeixen infinits nombres entre ells ( és dens en ).<br />
 infinits nombres racionals diferents entre  i .<br />
Demostració: Suposem .</li>
</li>
<li> admet una expressió decimal exacta o peròdica. Exemples:<br />
, , .</li>
</ol>
</div>
<p><span id="more-1424"></span></p>
<p>
<strong>Irracionals</strong> </p>
<div style="margin-left: 50px;">
Són el conjunt dels nombres amb expressió decimal que tenen infinites xifres decimals no periòdiques.</p>
<p>Exemples: .
</p></div>
</p>
<p>
<strong>Reals</strong> </p>
<div style="margin-left: 50px">
 cos commutatiu ordenat (els nombres tenen ordre).
</div>
</p>
<h5>Relació d&#8217;ordre en </h5>

<p style="margin-top: 15px;"></p>
<h5 style="margin-top: 20px;">Elements notables d&#8217;un conjunt respecte de la </h5>
<table border="0">
<tr>
<td rowspan="2"></td>
<td>x és una cota inferior d&#8217;A  </td>
</tr>
<tr>
<td>x és una cota superior d&#8217;A  </td>
</tr>
</table>
<p>A està acotat inferiorment  /   és cota inferior d&#8217;A.<br />
A està acotat superiorment  /  és cota superior d&#8217;A.<br />
A està acotat  A està acotat superiorment i inferior.</p>
<p>x és el <em>ínfim</em> d&#8217;A  x és la major de les cotes inferiors d&#8217;A .<br />
x és el <em>suprem</em> d&#8217;A  x és la menor de les cotes superior d&#8217;A .</p>
<div style="margin-left: 50px;">
si <br />
si 
</div>
<p><strong>Teorema de l&#8217;extrem</strong> (també axioma del suprem) </p>
<p> acotat superiorment  / <br />
 acotat inferiorment  / </p>
<h5 style="margin-top: 20px;">Valor absolut</h5>

<p>Propietats:</p>
<p style="margin-top: 15px;"></p>
<p><!-- -------------------------------------------------- --></p>
<hr />
<h4 style="margin-top: 25px;">2. Nombres complexos</h4>
<p>La «unitat imaginària» és .</p>
<p>Els <strong>nombres complexos</strong> són els nombres , amb .</p>
<p>Conjunt dels nombres complexos: .</p>
<p>Donat </p>
<p>Donat , diem que el <em>conjugat</em> de  és .</p>
<p>En ,  amb , sempre té solució en . Exemple:</p>
<p style="margin-left: 50px;">
<br />
<small>(Recorda: )</small>
</p>
<h5>Operacions</h5>
<p><strong>Suma</strong></p>
<p style="margin-left: 50px;">

</p>
<p><strong>Producte</strong></p>
<p style="margin-left: 50px;">
<br />
<small>(Recorda: )</small>
</p>
<p> és un cos commutatiu.</p>
<p>L&#8217;<strong>invers</strong> de  és  </p>
<p><strong>Quocient</strong></p>
<p style="margin-left: 50px;">

</p>
<p>&nbsp;</p>
<h5>Mòdul d&#8217;un nombre complex</h5>
<p style="margin-left: 50px;">
</p>
<p>Propietats:
</p>

<p>&nbsp;</p>
<h5>Argument d&#8217;un nombre complex</h5>
<p style="margin-left: 50px;">
<table border="0">
<tr>
<td> angle que forma en  el vector origen (0,0) i final (a,b) amb el semieix .</td>
<td><a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Nombres_complexos.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Nombres_complexos.png" alt="" title="Nombres_complexos" width="295" height="247" class="aligncenter size-full wp-image-1544" /></a><br />(Els signes d&#8217;<strong>a</strong> i <strong>b</strong> determinen el quadrant.)</td>
<td><a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Quadrants.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Quadrants.png" alt="" title="Quadrants" width="195" height="195" class="aligncenter size-full wp-image-1545" /></a></td>
</tr>
</table>
<p>&nbsp;</p>
<h5>Com calcular la part real i la part imaginària sabent  i ?</h5>
<p style="margin-left: 50px;">
<br />

</p>
<h5>Representacions dels nombres complexos</h5>
<p>Amb , la forma  és anomenada la <strong>forma binòmica</strong> del nombre complex .</p>
<p>També podem expressar  per mitjà de  i  de la següent forma: . Aquesta representació s&#8217;anomena <strong>forma trigonomètrica</strong> de .</p>
<p>Finalment, també utilitzem la <strong>forma polar</strong>: &nbsp;</p>
<table border="0" style="margin-left: 50px;">
<tr>
<th colspan="2"><strong>Exemples:</strong></th>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
<p><strong>Representació gràfica</strong> dels nombres complexos en el pla complex:<br />
<a href="http://bloc.eurion.net/wp-content/uploads/2011/07/Representació-gràfica-dels-nombres-complexos.png"><img src="http://bloc.eurion.net/wp-content/uploads/2011/07/Representació-gràfica-dels-nombres-complexos.png" alt="" title="Representació gràfica dels nombres complexos" width="415" height="183" class="aligncenter size-full wp-image-1549" /></a></p>
<h5>Operacions en forma polar</h5>
<table border="0">
<tr>
<td rowspan="4"></td>
<td colspan="2"><em>(No es pot sumar ni restar!)</em></td>
</tr>
<tr>
<td><strong>producte:</strong> </td>
<td><strong>potència:</strong> </td>
</tr>
<tr>
<td><strong>quocient:</strong> </td>
<td><strong>arrel:</strong> </td>
</tr>
<tr>
<td colspan="2"><strong>igualtat:</strong> </td>
</tr>
</table>
<p>Si , per la fórmula de la potència: . Desenvolupant aquesta igualtat obtenim: , la <a href="http://ca.wikipedia.org/wiki/F%C3%B3rmula_de_De_Moivre">fórmula de Moivre</a>.</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/calculus/" rel="tag">calculus</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/maths/" rel="tag">maths</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/calcul-funcions-duna-variable/' rel='bookmark' title='Apunts de Càlcul: Funcions d&#8217;una variable'>Apunts de Càlcul: Funcions d&#8217;una variable</a> <small>Introducció Considerem una funció real de variable real tal que...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-calcul-cost-algorismes/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs'>Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs</a> <small>Introducci&oacute; Els algorismes s&oacute;n per tot arreu i per aix&ograve;...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-dividir-i-vencer/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer'>Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer</a> <small>Introducci&oacute; L&#39;esquema de programaci&oacute; de dividir i v&egrave;ncer &eacute;s una...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/calcul-nombres-reals-i-complexos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breu introducció al sistema de control de versions Bazaar</title>
		<link>http://bloc.eurion.net/archives/2011/introduccio-al-bzr/</link>
		<comments>http://bloc.eurion.net/archives/2011/introduccio-al-bzr/#comments</comments>
		<pubDate>Tue, 17 May 2011 16:49:03 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet Ubuntu.cat]]></category>
		<category><![CDATA[bzr]]></category>
		<category><![CDATA[desenvolupament]]></category>
		<category><![CDATA[vcs]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1389</guid>
		<description><![CDATA[Introducci&#243; A l&#39;hora de desenvolupar aplicacions inform&#224;tiques en grup &#233;s molt important disposar d&#39;un sistema de control de versions (VCS,&#160;version control system). Explicat molt breument, els VCS s&#243;n&#160;eines de desenvolupament que permeten desar captures del codi font (revisions) creant tot un historial de canvis a mida que avan&#231;a el desenvolupament del programa; a m&#233;s, permeten [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Introducci&oacute;<br />
	</strong></p>
<p>A l&#39;hora de desenvolupar aplicacions inform&agrave;tiques en grup &eacute;s molt important disposar d&#39;un sistema de control de versions (<strong>VCS</strong>,&nbsp;<em>version control system</em>). Explicat molt breument, els VCS s&oacute;n&nbsp;eines de desenvolupament que permeten desar captures del codi font (<em>revisions</em>) creant tot un historial de canvis a mida que avan&ccedil;a el desenvolupament del programa; a m&eacute;s, permeten compartir aquestes captures amb els companys de treball i normalment tenen capacitats per resoldre conflictes entre revisions creades en para?lel per diferents persones.</p>
<p>Un VCS potent utilitzat correctament pot incrementar la productivitat de forma dr&agrave;stica, al reduir problemes de coordinaci&oacute; facilitant que diferents desenvolupadors puguin compartir f&agrave;cilment les &uacute;ltimes versions de la seva feina i que&nbsp;m&eacute;s d&#39;una persona pugui fer canvis simultanis a un mateix conjunt de fitxers minimitzant els possibles conflictes resultants.</p>
<p>Hi ha un gran ventall de sistemes de control de versions disponibles, dels quals el m&eacute;s conegut &eacute;s segurament el <strong><a href="http://subversion.apache.org/">Subversion</a></strong>. Aquest, per&ograve;, permet &uacute;nicament un model <a href="http://en.wikipedia.org/wiki/Distributed_revision_control#Distributed_vs._centralized">centralitzat</a>&nbsp;i en general &eacute;s bastant limitat. Personalment prefereixo sistemes com ara el <a href="http://bazaar.canonical.com/en/"><strong>Bazaar</strong></a>&nbsp;(<em>bzr</em>). (El <a href="http://ca.wikipedia.org/wiki/Git"><strong>Git</strong></a> &eacute;s encara m&eacute;s potent, per&ograve; &eacute;s molt m&eacute;s dif&iacute;cil d&#39;aprendre a utilitzar, pel qual en aquest apunt em centrar&eacute; en el Bazaar; tamb&eacute; hi ha altres alternatives, com ara el <a href="http://ca.wikipedia.org/wiki/Mercurial">Mercurial</a>,&nbsp;per&ograve; no estic familiaritzat amb aquestes).</p>
<p><strong>Instal&middot;laci&oacute;</strong></p>
<p>En sistemes com ara l&#39;Ubuntu o Debian est&agrave; disponible en un paquet anomenat &laquo;bzr&raquo; i segurament el mateix sigui cert per a altres distribucions de GNU/Linux. Si feu servir un altre sistema operatiu podeu baixar-lo de&nbsp;<a href="http://wiki.bazaar.canonical.com/Download">bazaar.canonical.com</a>.</p>
<p>Com a nota al marge, el Bazaar tamb&eacute; disposa d&#39;una interf&iacute;cie gr&agrave;fica (<a href="http://doc.bazaar.canonical.com/explorer/en/">Bazaar Explorer</a>), per&ograve; ja que aquest apunt l&#39;escric orientat a desenvolupadors nom&eacute;s explicar&eacute; el seu &uacute;s des de la l&iacute;nia d&#39;ordres.</p>
<p><strong>Configuraci&oacute;</strong></p>
<p>Abans de poder fer operacions d&#39;escriptura cal que digueu al Bazaar com us voleu identificar. Podeu fer-ho de la seg&uuml;ent forma:</p>
<pre>bzr whoami &quot;<em>Nom Cognom</em> &lt;<em>email@domini.tld</em>&gt;&quot;</pre>
<p>En cas que feu servir el portal <a href="https://launchpad.net/">Launchpad</a>, tamb&eacute; podeu habilitat la integraci&oacute; amb aquest (si no coneixeu el Launchpad, podeu ignorar aix&ograve;):</p>
<pre>bzr launchpad-login <em>nom_usuari</em></pre>
<p><b>Primers passos</b></p>
<p>Imaginem que estem dins un directori &laquo;el-meu-projecte&raquo; on hi tenim un seguit de fitxers de codi (&laquo;main.c&raquo; i &laquo;utils.c&raquo;). Per comen&ccedil;ar a utilitzar el Bazaar amb aquest codi el primer que hem de fer &eacute;s crear una <em><strong>branca</strong></em>:</p>
<pre>bzr init</pre>
<p>Ara podem afegir-hi els fitxers que volem que controli:</p>
<pre>bzr add main.c utils.c</pre>
<p>i tot seguit podem crear una primera <em><strong>revisi&oacute;</strong></em> (una captura del contingut actual dels fitxers):</p>
<pre>bzr commit -m &quot;Primera revisi&oacute; del meu nou projecte...&quot;</pre>
<p>Un cop fet aix&ograve;, imaginem que acabem de fer uns canvis al fitxer <em>main.c</em>. Un cop comprovat que aquests funcionen correctament, procedirem a crear una segona revisi&oacute;:</p>
<p>bzr commit -m &quot;Aqu&iacute; aniria una descripci&oacute; dels &uacute;ltims canvis.&quot;</p>
<p>I ja tenim dues revisions en la nostra branca. Ara podem recuperar el llistat de canvis que hem fet amb:</p>
<pre>bzr log</pre>
<p>I veuriem alguna cosa com la seg&uuml;ents</p>
<pre>------------------------------------------------------------
<strong>revno: 2</strong>
committer: Nom Cognom &lt;email@domini.tld&gt;
branch nick: foo
timestamp: Tue 2011-05-17 18:19:48 +0200
message:
&nbsp;&nbsp;Alguns altres canvis que he fet...
------------------------------------------------------------
<strong>revno: 1</strong>
committer: Nom Cognom &lt;email@domini.tld&gt;
branch nick: projecte1
timestamp: Tue 2011-05-17 18:19:29 +0200
message:

&nbsp;&nbsp;Primera revisi&oacute; del meu nou projecte...
</pre>
<p>Si voleu analitzar en m&eacute;s detall una revisi&oacute;, podeu comparar dues (o m&eacute;s) revisions amb l&#39;ordre:</p>
<pre>bzr diff -r<strong>1</strong>..<strong>2</strong></pre>
<p>A m&eacute;s, quan arribeu a una versi&oacute; estable del vostre programa podeu marcar la revisi&oacute; actual amb una <em>etiqueta</em>, fent:</p>
<pre>bzr tag <em>nom-etiqueta</em></pre>
<p>Llavors podreu utilitzar &quot;tag:<em>nom-etiqueta</em>&quot; per referir-vos a aquella versi&oacute; en lloc d&#39;haver de consultar el n&uacute;mero de revisi&oacute; (<em>revno</em>).</p>
<p><strong>Compartint la branca amb altres</strong></p>
<p><meta content="text/html; charset=utf-8" http-equiv="content-type" /></p>
<p>Fins ara nom&eacute;s hem estat treballant en local (aix&ograve; &eacute;s possible ja que el Bazaar -al contrari de l&#39;SVN- &eacute;s un sistema distribu&iuml;t). Imaginem que ara voleu compartir el codi amb un company perqu&egrave; pugui ajudar amb el desenvolupament. Per aix&ograve; us caldr&agrave; disposar d&#39;un servidor (qualsevol ordinador accessible, en realitat) on els dos hi tingueu acc&eacute;s SFTP. Enviar-hi la vostra branca completa (amb totes les revisions) &eacute;s tan f&agrave;cil com:</p>
<pre>bzr push sftp://<em>el-meu-servidor</em>.<em>tld</em>/<em>directori</em>/<em>dest&iacute;</em>/<em>projecte1</em></pre>
<p>(Si m&eacute;s enll&agrave; de l&#39;SFTP tamb&eacute; teniu acc&eacute;s via SSH, i el servidor t&eacute; el <strong>bzr</strong>&nbsp;insta?lat, podeu utilitzar el mode de servidor inte?ligent amb &laquo;bzr+ssh://&raquo;. D&#39;altra banda, si el company/a no t&eacute; acc&eacute;s al servidor, sempre es pot posar la branca en un lloc accessible des de la web i llavors hi tindr&agrave; acc&eacute;s nom&eacute;s de lectura, via &laquo;http://&raquo;).</p>
<p>Per obtenir una c&ograve;pia de la branca, l&#39;altre persona pot fer:</p>
<pre>bzr branch&nbsp;sftp://<em>nom-d'usuari</em>@<em>el-meu-servidor</em>.<em>tld</em>/<em>directori</em>/<em>dest&iacute;</em>/<em>projecte1</em></pre>
<p>A partir d&#39;aqu&iacute;, els dos podeu fer &laquo;<em>bzr push</em>&raquo; per enviar els vostres canvis despr&eacute;s d&#39;un commit i &laquo;<em>bzr pull</em>&raquo; per recuperar canvis nous. En cas de produir-se un conflicte (el qual es produeix si es fa un <em>commit</em>&nbsp;sense tenir les &uacute;ltimes revisions de la branca del servidor) es pot arreglar amb &laquo;bzr merge&raquo;.</p>
<p>A m&eacute;s d&#39;aquests constants intercanvis, en qualsevol moment un dels dos pot decidir fer un <em>push</em>&nbsp;a una nova branca (per exemple, per desenvolupar alguna nova caracter&iacute;stica experimental) i quan la feina en aquesta estigui acabada, tornar-la a integrar (amb un <em>merge</em>) dins la branca principal (que, per cert, normalment s&#39;anomena&nbsp;<em>trunk</em>).</p>
<p><meta content="text/html; charset=utf-8" http-equiv="content-type" /></p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/introduccio-al-bzr/#comments">One comment</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/introduccio-al-bzr/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/bzr/" rel="tag">bzr</a>, <a href="http://bloc.eurion.net/archives/tag/desenvolupament/" rel="tag">desenvolupament</a>, <a href="http://bloc.eurion.net/archives/tag/vcs/" rel="tag">vcs</a><br/>
</small></p><div class='yarpp-related-rss yarpp-related-none'>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/introduccio-al-bzr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Activity Log Manager for Zeitgeist released!</title>
		<link>http://bloc.eurion.net/archives/2011/activity-log-manager-released/</link>
		<comments>http://bloc.eurion.net/archives/2011/activity-log-manager-released/#comments</comments>
		<pubDate>Tue, 17 May 2011 14:40:46 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet GNOME]]></category>
		<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[Programari lliure]]></category>
		<category><![CDATA[zeitgeist]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1381</guid>
		<description><![CDATA[On behalf of the Activity Log Manager team and the Zeitgeist Project, I am&#160;happy to announce the first release of Activity Log Manager (0.8.0), a user interface for managing Zeitgeist blacklists,&#160;deleting recent events as well as temporarily pausing the logging. Grab it while it&#39;s hot. Note that you&#39;ll need Zeitgeist 0.8.0 (or later) for it [...]]]></description>
				<content:encoded><![CDATA[<p><meta content="text/html; charset=utf-8" http-equiv="content-type" /></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; width: auto; max-width: 45em; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: 'UbuntuBeta Regular', Ubuntu, 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; line-height: 18px; ">On behalf of the Activity Log Manager team and the <a href="http://zeitgeist-project.com">Zeitgeist Project</a>, I am&nbsp;happy to announce the first release of <a href="https://launchpad.net/activity-log-manager">Activity Log Manager</a> (0.8.0), a user interface for managing Zeitgeist blacklists,&nbsp;deleting recent events as well as temporarily pausing the logging.</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; width: auto; max-width: 45em; text-align: center; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: 'UbuntuBeta Regular', Ubuntu, 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; line-height: 18px; "><meta content="text/html; charset=utf-8" http-equiv="content-type" /><span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: Arial, Verdana, sans-serif; line-height: normal; "><a href="http://bloc.eurion.net/wp-content/uploads/2011/05/activity-log-manager.png"><img alt="" class="aligncenter size-medium wp-image-1382" height="214" src="http://bloc.eurion.net/wp-content/uploads/2011/05/activity-log-manager-300x214.png" style="cursor: default; " title="activity-log-manager" width="300" /></a></span></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; width: auto; max-width: 45em; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: 'UbuntuBeta Regular', Ubuntu, 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; line-height: 18px; "><a href="https://launchpad.net/activity-log-manager/+download">Grab it</a> while it&#39;s hot. Note that you&#39;ll need Zeitgeist 0.8.0 (or later) for it to work. If you&#39;re an Ubuntu user you can get packages from <a href="https://launchpad.net/~zeitgeist/+archive/ppa">our PPA</a>; I&#39;ve also uploaded it to Debian.</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; width: auto; max-width: 45em; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: 'UbuntuBeta Regular', Ubuntu, 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; line-height: 18px; ">I&#39;d also like to use this chance to thank <a href="http://collabora.com/">Collabora</a>&nbsp;for sponsoring my (and <a href="http://seilo.geekyogre.com/">Seif</a>&#39;s) work on Zeitgeist!</span></p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/activity-log-manager-released/#comments">4 comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/activity-log-manager-released/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/gnome/" rel="tag">gnome</a>, <a href="http://bloc.eurion.net/archives/tag/programari-lliure/" rel="tag">Programari lliure</a>, <a href="http://bloc.eurion.net/archives/tag/zeitgeist/" rel="tag">zeitgeist</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2010/zeitgeist-0-5-1-released/' rel='bookmark' title='Zeitgeist 0.5.1 released!'>Zeitgeist 0.5.1 released!</a> <small>On behalf of the Zeitgeist Project team, I am pleased...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/zeitgeist-0-7-1-made-in-aarhus-released/' rel='bookmark' title='Zeitgeist 0.7.1 &#8220;Made in Aarhus&#8221; released!'>Zeitgeist 0.7.1 &#8220;Made in Aarhus&#8221; released!</a> <small>On behalf of the Zeitgeist team I am proud to...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/gnome-activity-journal-and-installing-it-on-ubuntu/' rel='bookmark' title='GNOME Activity Journal, and installing it on Ubuntu'>GNOME Activity Journal, and installing it on Ubuntu</a> <small>As already announced by Seif, the first development release of...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/activity-log-manager-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Zeitgeist 0.7.1 &#8220;Made in Aarhus&#8221; released!</title>
		<link>http://bloc.eurion.net/archives/2011/zeitgeist-0-7-1-made-in-aarhus-released/</link>
		<comments>http://bloc.eurion.net/archives/2011/zeitgeist-0-7-1-made-in-aarhus-released/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 16:11:40 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet GNOME]]></category>
		<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[Programari lliure]]></category>
		<category><![CDATA[zeitgeist]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1270</guid>
		<description><![CDATA[On behalf of the Zeitgeist team I am proud to announce the release of Zeitgeist 0.7.1 &#34;Made in Aarhus&#34;. This is a minor release before 0.8.0&#160;(which will be the first one introducing storage awareness). What is Zeitgeist? Zeitgeist is a service which logs the users&#39;s activities and events, anywhere from files opened to websites visited [...]]]></description>
				<content:encoded><![CDATA[<p>On behalf of the Zeitgeist team I am proud to announce the <a href="https://launchpad.net/zeitgeist/+announcement/7988">release</a> of Zeitgeist 0.7.1 &quot;Made in Aarhus&quot;. This is a minor release before <a href="https://launchpad.net/zeitgeist/+milestone/0.8.0">0.8.0</a>&nbsp;(which will be the first one introducing <a href="http://www.grillbar.org/wordpress/?p=536">storage awareness</a>).</p>
<p><strong>What is Zeitgeist?</strong></p>
<p>Zeitgeist is a service which logs the users&#39;s activities and events, anywhere from files opened to websites visited and conversations, and makes this information readily available for other applications to use. It is also able to establish relationships between items based on similarity and usage patterns.</p>
<p>The Zeitgeist engine is a user-level service and does not provide a GUI. It is intended to support dedicated journalling applications and deep integration with other desktop components.</p>
<p><strong>Where?</strong></p>
<p>Downloads: <a href="https://launchpad.net/zeitgeist/+download">launchpad.net/zeitgeist/+download</a> (<a href="http://launchpad.net/zeitgeist/0.7/0.7.1/+download/zeitgeist-0.7.1.tar.gz">zeitgeist-0.7.1.tar.gz</a>)</p>
<p>About Zeitgeist: <a href="http://zeitgeist-project.com">zeitgeist-project.com<br />
	</a>Wiki: <a href="http://wiki.zeitgeist-project.com">wiki.zeitgeist-project.com</a></p>
<p>See also <a href="https://launchpad.net/zeitgeist-datahub">Zeitgeist Datahub</a>, <a href="https://launchpad.net/gnome-activity-journal">GNOME Activity Journal</a> and the repository for additional <a href="https://launchpad.net/zeitgeist-dataproviders">Zeitgeist data-sources</a>. You may as well like <a href="https://launchpad.net/sezen">Sezen</a>.</p>
<p><strong>News since 0.7.0</strong></p>
<pre>Engine:

 - Expose property information in the D-Bus introspection output.
 - Mention column names explicitly when inserting events, for compatibility
   with the upcoming 0.8 release.

Python API:

 - Expose DataSourceRegistry&#39;s enabled status in a callback.
 - Automatically reconnect to Zeitgeist if the connection is lost when using
   methods asynchronously (so far this only happened for synchronous calls).
 - Reinstall all active monitors upon reconnection (LP: #673008, #727226).
 - Fix a (harmless) race condition requesting the bus name (LP: #732015).

Overall:

 - Added new event interpretation types: AcceptEvent, DenyEvent and ExpireEvent.
 - Include NCO in the generated ontologies.
 - Better ./configure check for python-rdflib.
 - Update the manpage to document exit codes.
</pre>
<p>Thanks to everyone who contributed to this release, and since I hadn&#39;t blogged about it before, also to everyone who made the <a href="http://live.gnome.org/Hackfests/Zeitgeist2011">Zeitgeist Hackfest in Aarhus</a> possible, including our sponsors:</p>
<p style="text-align: center; "><img alt="" class="aligncenter size-full wp-image-1276" height="57" src="http://bloc.eurion.net/wp-content/uploads/2011/03/collabora-logo-175.png" title="collabora-logo-175" width="175" />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;<img alt="" class="aligncenter size-full wp-image-1280" height="84" src="http://bloc.eurion.net/wp-content/uploads/2011/03/incuba.gif" title="incuba" width="114" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<img alt="" class="aligncenter size-medium wp-image-1279" height="41" src="http://bloc.eurion.net/wp-content/uploads/2011/03/aarhus-computer-science-300x41.png" title="aarhus-computer-science" width="300" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<img alt="" height="100" src="http://bloc.eurion.net/wp-content/uploads/2009/11/gnome-sponsored-badge-150x150.png" width="100" /></p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/zeitgeist-0-7-1-made-in-aarhus-released/#comments">2 comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/zeitgeist-0-7-1-made-in-aarhus-released/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/programari-lliure/" rel="tag">Programari lliure</a>, <a href="http://bloc.eurion.net/archives/tag/zeitgeist/" rel="tag">zeitgeist</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2010/zeitgeist-0-5-1-released/' rel='bookmark' title='Zeitgeist 0.5.1 released!'>Zeitgeist 0.5.1 released!</a> <small>On behalf of the Zeitgeist Project team, I am pleased...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/activity-log-manager-released/' rel='bookmark' title='Activity Log Manager for Zeitgeist released!'>Activity Log Manager for Zeitgeist released!</a> <small>On behalf of the Activity Log Manager team and the...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/zeitgeist-0-3-3-is-out/' rel='bookmark' title='Zeitgeist 0.3.3 is out!'>Zeitgeist 0.3.3 is out!</a> <small>From the release announcement: On behalf of the Zeitgeist Project...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/zeitgeist-0-7-1-made-in-aarhus-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On Intel AppUp, the ExoPC Slate, MeeGo and Ubuntu 10.10</title>
		<link>http://bloc.eurion.net/archives/2011/on-intel-appup-the-exopc-slate-meego-and-ubuntu-10-10/</link>
		<comments>http://bloc.eurion.net/archives/2011/on-intel-appup-the-exopc-slate-meego-and-ubuntu-10-10/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 21:51:29 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Planet Ubuntu]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[meego]]></category>
		<category><![CDATA[mwc]]></category>
		<category><![CDATA[tablet]]></category>
		<category><![CDATA[touchscreen]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1233</guid>
		<description><![CDATA[Introduction (Intel Rocks!) Last Wednesday I attended the Intel AppUp Developer Day, a workshop where Intel employees presented the MeeGo stack and introduced Intel AppUp, a software center which will be shipping in netbooks/tablets/carputers/etc. There was also a live demo on how to design interfaces with QML and one of the Angry Birds creator said [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Introduction (Intel Rocks!)</strong></p>
<p>Last Wednesday I attended the <a href="http://appdeveloper.intel.com/en-us/blog/2011/02/09/intel-appup-developer-program-mobile-world-congress">Intel AppUp Developer Day</a>, a workshop where Intel employees presented the MeeGo stack and introduced Intel AppUp, a software center which will be shipping in netbooks/tablets/carputers/etc. There was also a live demo on how to design interfaces with QML and one of the <a href="http://www.rovio.com/index.php?page=angry-birds">Angry Birds</a> creator said some words. Best of all, Intel was nice enough to give every participant a tablet!</p>
<p><strong>MeeGo (really alpha!)</strong></p>
<p>The ExoPC Slate came with&nbsp;Intel&#39;s new <a href="http://appdeveloper.intel.com/en-us/blog/2011/01/27/meego-tablets">tablet version of MeeGo</a>, which like its netbook counterpart seems to place great emphasis on social and multimedia uses, but it better suited for the touch screen. The system is still pre-alpha, though, and when I tried to use it lots of stuff failed to work. Asking about it at the MeeGo pavilion I was told to re-install the <a href="http://appdeveloper.intel.com/en-us/meego-sdk-suite">image</a>, which solved some of the problems. Still, I don&#39;t really see myself using it at this point, so I decided to also put Ubuntu on it.</p>
<p><strong>Installing Ubuntu</strong></p>
<p>The installation went smooth; I got a message about the bootloader not being able to be installed, but I just ignored it and had no problems. I had already left half of the 64GB SSD empty when installing MeeGo, since it uses brtfs which Ubuntu can&#39;t resize yet. Of course, I had to plug in mouse and keyboard (I used a USB hub, since the tablet only has two USB ports and one is required for the installation media). Boot is somewhat slower than what I&#39;d expect for an SSD, and sometimes shows some <a href="https://bugs.launchpad.net/ubuntu/+source/udev/+bug/647404">weird error messages</a>&nbsp;which seem to have no effect.</p>
<p>One outstanding problem is that GRUB doesn&#39;t support the touch screen (and for that matter neither does it recognize my wireless keyboard), so if I want to change between Ubuntu and MeeGo I have to plug in a normal USB keyboard.</p>
<p><strong>Getting the touch-screen to work (no multi-touch :()</strong></p>
<p>The touch-screen didn&#39;t work out of the box either but required some fiddling. Basically, I had to open /etc/default/boot and change &laquo;<em>GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash&quot;</em>&raquo; to &laquo;<em>GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash usbhid.quirks=0xeef:0x72a1:0&#215;40&quot;</em>&raquo; and run &laquo;<em>sudo update-grub</em>&raquo;, otherwise touching the screen would invariably send the pointer to the top-left. And basically, that&#39;s it, now it&#39;s working using the free drivers!</p>
<p>However, the free drivers only support a single finger. There&#39;s also the option of using the proprietary hid_egalax driver, which is supposed to correctly support tracking two fingers (and it does in MeeGo), but I didn&#39;t have so much luck in Ubuntu and functionally I don&#39;t really see a difference between them. To install it I downloaded the&nbsp;<a href="http://home.eeti.com.tw/web20/eGalaxTouchDriver/linuxDriver.htm">eGalaxTouch</a>&nbsp;tarball: <a href="http://home.eeti.com.tw/web20/drivers/touch_driver/Linux/20110117/eGalaxTouch-3.04.4912-32b-k26.tar.gz">eGalaxTouch-3.04.4912-32b-k26.tar.gz</a>. Then uncompressed the file, executed the setup script and restarted the computer. This time the result wasn&#39;t so nice, since in addition to still not doing any multi-touch, the pointer was showing up in the wrong place and somehow now the touch-screen device shows up four times. The pointer problem was easy to fix, though, by running XXXX and calibrating the four &quot;devices&quot;, so this basically left me just how I was with the free drivers.</p>
<p>Since with a single finger I have no way of triggering a right-click, I enabled the &quot;secondary click when pressing primary button&quot; accessibility option in the mouse preferences.</p>
<p><strong>Final touch (pun intended?)</strong></p>
<p>For typing I&#39;ve installed &quot;matchbox-keyboard&quot; and placed a launcher for it in the top panel. Suggestions on better alternatives are welcome (especially if they show up automatically when I focus a text box).</p>
<p>Now something I could do to at least get a little bit of coolness factor is enabling single-finger scroll support in Chromium, by installing the <a href="http://www.chromeextensions.org/appearance-functioning/chrometouch/">chromeTouch</a> extension (apparently there is also a similar extension for Firefox).</p>
<p>Finally, I disabled the key-binding for &quot;open music player&quot;, since by default the Slate&#39;s touch hot-key had been assigned to it and it kept opening Rhythmbox every time I accidentally went over the hot-key.</p>
<p><strong>References</strong></p>
<p>To wrap up this post, here&#39;s some random pages which helped me on my way here:</p>
<ul>
<li><a href="http://art.ubuntuforums.org/showthread.php?t=1541396">eGalax Touch Screen on Ubuntu 10.04</a></li>
<li><a href="http://samiux.blogspot.com/2010/11/howto-ubuntu-1010-on-gigabyte-touchnote.html">Ubuntu 10.10 on Gigabyte TouchNote T1028X</a></li>
<li><a href="http://wiki.meego.com/Installing_MeeGo_and_Handset_Images_on_ExoPC">Installing MeeGo and Handset Images on ExoPC</a></li>
<li><a href="http://ubuntuforums.org/showthread.php?t=1468376&amp;page=19">Ubuntu on EeePC T101MT</a></li>
<li><a href="http://www.exopc.com/forum/viewtopic.php?f=39&amp;t=2805#p44114">ExoPC does Ubuntu 10.10 Netbook</a></li>
<li><a href="https://help.ubuntu.com/community/EloTouchScreen">EloTouchScreen</a></li>
<li><a href="http://wiki.linuxmce.org/index.php/Egalax-Touchscreen">Egalax-TouchScreen</a></li>
<li><a href="https://wiki.ubuntu.com/X/Testing/Touchscreen">X/Testing/Touchscreen</a></li>
<li><a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/549447">Bug #549447: eGalax touch-screen configured as tablet</a></li>
</ul>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/on-intel-appup-the-exopc-slate-meego-and-ubuntu-10-10/#comments">3 comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/on-intel-appup-the-exopc-slate-meego-and-ubuntu-10-10/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/intel/" rel="tag">intel</a>, <a href="http://bloc.eurion.net/archives/tag/meego/" rel="tag">meego</a>, <a href="http://bloc.eurion.net/archives/tag/mwc/" rel="tag">mwc</a>, <a href="http://bloc.eurion.net/archives/tag/tablet/" rel="tag">tablet</a>, <a href="http://bloc.eurion.net/archives/tag/touchscreen/" rel="tag">touchscreen</a>, <a href="http://bloc.eurion.net/archives/tag/ubuntu/" rel="tag">Ubuntu</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2009/updated-voxforge-packages-in-ubuntu/' rel='bookmark' title='Updated Voxforge packages in Ubuntu'>Updated Voxforge packages in Ubuntu</a> <small>Just a quick note today to mention that I&#8217;ve updated...</small></li>
<li><a href='http://bloc.eurion.net/archives/2009/reducing-sshs-connection-time-on-ubuntu/' rel='bookmark' title='Reducing SSH&#8217;s connection time on Ubuntu'>Reducing SSH&#8217;s connection time on Ubuntu</a> <small>If you use SSH on your local network you may...</small></li>
<li><a href='http://bloc.eurion.net/archives/2010/gnome-activity-journal-and-installing-it-on-ubuntu/' rel='bookmark' title='GNOME Activity Journal, and installing it on Ubuntu'>GNOME Activity Journal, and installing it on Ubuntu</a> <small>As already announced by Seif, the first development release of...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/on-intel-appup-the-exopc-slate-meego-and-ubuntu-10-10/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Apunts d&#8217;Estructures de Dades i Algorismes: Programació dinàmica</title>
		<link>http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/</link>
		<comments>http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 17:54:12 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithmics]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1184</guid>
		<description><![CDATA[1. Nombres de Fibonacci L&#39;algorisme trivial per al c&#224;lcul dels nombres de Fibonacci repeteix molts c&#224;lculs. Podem evitar-ho desant tots els valors que calculem en una matriu i cercant-los all&#224; quan ens calguin abans de calcular-los un altre cop (memoization). Si nom&#233;s ens cal obtenir un sol nombre de Fibonacci, podem construir una versi&#243; iterativa [...]]]></description>
				<content:encoded><![CDATA[<h4>1. Nombres de Fibonacci</h4>
<p>L&#39;algorisme trivial per al c&agrave;lcul dels nombres de Fibonacci repeteix molts c&agrave;lculs. Podem evitar-ho desant tots els valors que calculem en una matriu i cercant-los all&agrave; quan ens calguin abans de calcular-los un altre cop (<em>memoization</em>). Si nom&eacute;s ens cal obtenir un sol nombre de Fibonacci, podem construir una versi&oacute; iterativa de l&#39;algorisme que eviti els c&agrave;lculs sense utilitzar espai de mem&ograve;ria addicional.</p>
<h4>2. Producte encadenat de matrius</h4>
<p>[FIXME: imatge multiplicaci&oacute; de matrius]. Hem vist que per multiplicar dues matrius podem utilitzar l&#39;algorisme escolar o l&#39;algorisme d&#39;Strassen. Amb el primer d&#39;ells, cal calcular  productes escalars.</p>
<p>Si volem dur a terme una seq&uuml;&egrave;ncia de multiplicacions, el nombre de productes escalars a fer canvia significativament segons com posem els par&egrave;ntesis (el qual no t&eacute; cap efecte sobre el resultat). Per exemple, amb tres matrius ,  i , l&#39;operaci&oacute;  resulta en  productes escalars. En canvi, l&#39;operaci&oacute; , amb les mateixes matrius, resultaria en  productes escalars.</p>
<p>Heus aqu&iacute; el problema la multiplicaci&oacute; encadenada de matrius: on &laquo;posar&raquo; els par&egrave;ntesis per poder dur a terme les multiplicacions amb el m&iacute;nim nombre de productes escalars?</p>
<p>Per for&ccedil;a bruta, amb&nbsp; matrius, les possibles formes de posar els par&egrave;ntesis s&oacute;n igual al nombre d&#39;arbres binaris amb&nbsp; fulles, el qual correspon a  ( &eacute;s el <a href="http://en.wikipedia.org/wiki/Catalan_number">nombre de Catalan</a>). Podem definir la seg&uuml;ent funci&oacute; per trobar el nombre m&iacute;nim de productes escalars per multiplicar les matrius&nbsp;, &#8230;, :</p>

<p>Aquesta operaci&oacute; duplica c&agrave;lculs &rarr; memoritzaci&oacute;! En resulta el seg&uuml;ent codi C++ que triga temps :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">vector<span style="color: #000080;">&lt;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;&gt;</span> mem<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>, vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>, <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
vector<span style="color: #000080;">&lt;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;&gt;</span> tall<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>, vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>, <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> m<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i, <span style="color: #0000ff;">int</span> j<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>mem<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> mem<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000080;">==</span> j<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> s <span style="color: #000080;">=</span> MAX_INT<span style="color: #008080;">;</span> <span style="color: #666666;">// infinit</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> k <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span> k <span style="color: #000080;">&lt;=</span> j<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>k<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> m<span style="color: #008000;">&#40;</span>i, k<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> m<span style="color: #008000;">&#40;</span>k<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>, j<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> p<span style="color: #008000;">&#91;</span>i<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> p<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> p<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&lt;</span> s<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            s <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span>
            tall<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> k<span style="color: #008080;">;</span> <span style="color: #666666;">// resposta al problema de com multiplicar-les</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> m<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> s<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Tamb&eacute; podem construir-ne una versi&oacute; iterativa:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;=</span> n<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> mem<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> n<span style="color: #008080;">;</span> i <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> <span style="color: #000040;">--</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> i<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> j <span style="color: #000080;">&lt;=</span> n<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>j<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">int</span> s <span style="color: #000080;">=</span> MAX_INT<span style="color: #008080;">;</span> <span style="color: #666666;">// infinit</span>
        <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> k <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span> k <span style="color: #000080;">&lt;=</span> j<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>k<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> mem<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> mem<span style="color: #008000;">&#91;</span>k<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> p<span style="color: #008000;">&#91;</span>i<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> p<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> p<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&lt;=</span> s<span style="color: #008000;">&#41;</span> s <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
        mem<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> s<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<h4>3. Problema de la subseq&uuml;&egrave;ncia comuna m&eacute;s llarga</h4>
<p>Tenim dues cadenes X=&quot;abcbdab&quot; i Y=&quot;bdcaba&quot; i volem trobar la subseq&uuml;&egrave;ncia comuna (per exemple, &quot;bca&quot;) m&eacute;s llarga (en aquest cas, la m&eacute;s llarga &eacute;s &quot;bdab&quot;). Definim&nbsp;,&nbsp;,&nbsp;=&#8230;.</p>
<ul>
<li>Si X i Y acaben igual: l&#39;&uacute;ltim car&agrave;cter d&#39;X (o Y) ha de ser l&#39;&uacute;ltim car&agrave;cter d&#39;LCS(X, Y).<br />
		LCS(X, Y) = .</li>
<li>Si X i Y no acaben igual, pensem qu&egrave; passa amb LCS(X, Y).<br />
		 Quina de les dues? La m&eacute;s llarga.</li>
</ul>
<p>Definim la funci&oacute;  = llargada de l&#39;LCS(, ).</p>


<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/algorithmics/" rel="tag">algorithmics</a>, <a href="http://bloc.eurion.net/archives/tag/eda/" rel="tag">eda</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/eda-dividir-i-vencer/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer'>Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer</a> <small>Introducci&oacute; L&#39;esquema de programaci&oacute; de dividir i v&egrave;ncer &eacute;s una...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-calcul-cost-algorismes/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs'>Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs</a> <small>Introducci&oacute; Els algorismes s&oacute;n per tot arreu i per aix&ograve;...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-grafs/' rel='bookmark' title='Apunts d’Estructures de Dades i Algorismes: Grafs'>Apunts d’Estructures de Dades i Algorismes: Grafs</a> <small>Definici&oacute; i propietats Graf: Graf dirigit (digraf): Un cam&iacute; de...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts d&#8217;Estructures de Dades i Algorismes: Les classes de problemes P i NP</title>
		<link>http://bloc.eurion.net/archives/2011/eda-p-np/</link>
		<comments>http://bloc.eurion.net/archives/2011/eda-p-np/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:59:50 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithmics]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1159</guid>
		<description><![CDATA[Classes de problemes &#8211; P i NP Entrades Problemes Classes de problemes (no excloents) P Coneixem algorismes amb temps pitjor polinomial (o millor) per a decidir el problema. NP Coneixem algorismes en temps polin&#242;mic indeterminista per a verificar si una soluci&#243; &#233;s correcta. Exemples de problemes que estan en NP: HAM &#8211; &#233;s dif&#237;cil trobar [...]]]></description>
				<content:encoded><![CDATA[<h4>Classes de problemes &ndash; P i NP</h4>
<table style="margin-top: 0.6em;">
<thead>
<tr>
<td>Entrades</td>
<td>Problemes</td>
<td colspan="2">Classes de problemes (no excloents)</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2" style="text-align: center;"></td>
<td rowspan="2" style="text-align: center;"></td>
<td><strong>P</strong></td>
<td>Coneixem algorismes amb temps pitjor polinomial (o millor) per a <strong>decidir</strong> el problema.</td>
</tr>
<tr>
<td><strong>NP</strong></td>
<td>Coneixem algorismes en <em>temps polin&ograve;mic indeterminista</em> per a <strong>verificar</strong> si una soluci&oacute; &eacute;s correcta.</td>
</tr>
</tbody>
</table>
<h5 style="margin-top: 1.2em;">Exemples de problemes que estan en NP:</h5>
<ul>
<li><strong>HAM</strong> &#8211; &eacute;s dif&iacute;cil trobar un cicle Hamiltoni&agrave; en un graf (<em>backtracking</em>), per&ograve; donada una sent&egrave;ncia de v&egrave;rtexs &eacute;s f&agrave;cil comprovar si &eacute;s una soluci&oacute;.</li>
<li><strong>Element m&iacute;nim</strong>.</li>
<li><strong>TSP</strong> (problema del viatjant de comer&ccedil;).</li>
<li><strong>Colorabilitat</strong>.</li>
<li><strong>Quadrat llat&iacute;</strong>.</li>
<li><strong>Sudoku</strong>.</li>
</ul>
<h5 style="margin-top: -10px;">Teorema</h5>
<p style="margin-top: 0.6em; margin-bottom: 1em;"></p>
<p style="margin-top: 0.6em; margin-bottom: 1em;">Queda una <a href="http://claymath.org/millennium/">pregunta clau</a>: ?</p>
<h4>Reducci&oacute;</h4>
<p>Siguin  i  dos problemes decisionals. Diem que  es redueix a  en temps polin&ograve;mic si podem trobar un algorisme polin&ograve;mic , &eacute;s a dir, que converteixi tota soluci&oacute; a  en una soluci&oacute; d&#39;.</p>
<p>En altres paraules, una reducci&oacute; en temps polin&ograve;mic d&#39; a&nbsp; &eacute;s un algorise&nbsp;.</p>
<p>Podem reduir, per exemple, el problema del graf hamiltoni&agrave; (HAM) al problema del viatjant de comer&ccedil; (TSP).</p>
<p><strong>Teorema:</strong> Si  i , llavors .</p>
<p>Un problema decisional  &eacute;s <strong>NP-hard</strong> si tot problema en NP es pot reduir a ell en temps polin&ograve;mic. .</p>
<p>Un problema &eacute;s <strong>NP-complet</strong> si &eacute;s NP-hard i es troba en NP.</p>
<p><strong>Teorema:<br />
	</strong>.</p>
<p><strong>Teorema:<br />
	</strong></p>
<p><strong>Teorema de Cook&nbsp;</strong>(~1970)<br />
	 (va ser el primer problema NP-complet).</p>
<p>El problema decisional <strong>CIRCUIT-SAT</strong>&nbsp;pren com a entrada un circuit amb&nbsp; entrades booleanes, una sortida i portes AND, OR i NOT i el que pregunta &eacute;s, &laquo;hi ha alguna entrada del circuit que faci que la sortida sigui 1?&raquo;.</p>
<p>Nota: Una possible soluci&oacute; donada per justificar que un problema decisional t&eacute; soluci&oacute; s&#39;anomena <strong>testimoni</strong>.</p>
<h4>Solucions pr&agrave;ctiques per a problemes NP</h4>
<ul>
<li>Heur&iacute;stiques.</li>
<li>Aproximacions.</li>
<li>Paral&middot;lelisme, ordinadors qu&agrave;ntics&#8230;</li>
</ul>
<h4>El problema de l&#39;aturada</h4>
<p>A part de les classes de problemes P, NP i NP-C n&#39;hi ha moltes d&#39;altres, i una d&#39;elles que cal mencionar &eacute;s la dels problemes <strong>irresolubles</strong>: aquells que l&#39;ordinador (o millor dit, una m&agrave;quina de Turing) no pot solucionar.</p>
<p>Un exemple de problema irresoluble &eacute;s el de l&#39;<strong>aturada</strong>: donada la descripci&oacute; d&#39;un programa i el seu estat inicial, determinar si el programa, si l&#39;executem, arribar&agrave; a completar-se o b&eacute; funcionar&agrave; fins la fi de l&#39;eternitat. Podem veure-ho amb el seg&uuml;ent programa d&#39;exemple:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> String Programa<span style="color: #008080;">;</span>
<span style="color: #0000ff;">typedef</span> String Entrada<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// Funci&amp;oacute; que retorna cert si el programa p, donada l&amp;#39;entrada</span>
<span style="color: #666666;">// x, arriba a aturar-se</span>
<span style="color: #0000ff;">bool</span> acaba<span style="color: #008000;">&#40;</span>Programa p, Entrada x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">void</span> vinga<span style="color: #008000;">&#40;</span>Programa p<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// Entra en un bucle infinit si el programa p, donant-li com a entrada</span>
    <span style="color: #666666;">// el mateix codi del programa, arriba a aturar-se</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>acaba<span style="color: #008000;">&#40;</span>p, p<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Si analitzem aquest programa i executem <em>vinga(vinga)</em> veiem que pot haver-hi dos casos:</p>
<ol>
<li>Que acabi &#8211; si acaba, <em>vinga</em> entra en el bucle i no acaba &rarr; contradicci&oacute;.</li>
<li>Que no acabi &#8211; si no acaba, <em>vinga</em> acaba &rarr; contradicci&oacute;.</li>
</ol>
<p style="margin-top: -10px;">Aix&iacute; doncs, no es pot solucionar el problema de l&#39;aturada.</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/eda-p-np/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/eda-p-np/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/algorithmics/" rel="tag">algorithmics</a>, <a href="http://bloc.eurion.net/archives/tag/eda/" rel="tag">eda</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/eda-cerca-exhaustiva/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Cerca exhaustiva'>Apunts d&#8217;Estructures de Dades i Algorismes: Cerca exhaustiva</a> <small>Cerca exhaustiva La cerca exhaustiva &eacute;s un m&egrave;tode de disseny...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-dividir-i-vencer/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer'>Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer</a> <small>Introducci&oacute; L&#39;esquema de programaci&oacute; de dividir i v&egrave;ncer &eacute;s una...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-grafs/' rel='bookmark' title='Apunts d’Estructures de Dades i Algorismes: Grafs'>Apunts d’Estructures de Dades i Algorismes: Grafs</a> <small>Definici&oacute; i propietats Graf: Graf dirigit (digraf): Un cam&iacute; de...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/eda-p-np/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts d&#8217;Estructures de Dades i Algorismes: Cerca exhaustiva</title>
		<link>http://bloc.eurion.net/archives/2011/eda-cerca-exhaustiva/</link>
		<comments>http://bloc.eurion.net/archives/2011/eda-cerca-exhaustiva/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:26:29 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithmics]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1143</guid>
		<description><![CDATA[Cerca exhaustiva La cerca exhaustiva &#233;s un m&#232;tode de disseny d&#39;algorismes que consisteix en mirar-se sistem&#224;tica i intel&#183;ligentment totes les possibles solucions a un problema donat. Generalment els problemes que es resolen mitjan&#231;ant aquesta t&#232;cnica s&#243;n problemes d&#39;optimitzaci&#243; o combinatoris. La t&#232;cnica consisteix en generar impl&#237;citament un arbre representant totes les possibles solucions i explorar-lo [...]]]></description>
				<content:encoded><![CDATA[<h4>Cerca exhaustiva</h4>
<p>La <strong>cerca exhaustiva</strong> &eacute;s un m&egrave;tode de disseny d&#39;algorismes que consisteix en mirar-se sistem&agrave;tica i <em>intel&middot;ligentment</em> totes les possibles <em>solucions</em> a un problema donat.</p>
<p>Generalment els problemes que es resolen mitjan&ccedil;ant aquesta t&egrave;cnica s&oacute;n problemes d&#39;optimitzaci&oacute; o combinatoris.</p>
<p>La t&egrave;cnica consisteix en generar impl&iacute;citament un arbre representant totes les possibles solucions i explorar-lo en profunditat, deixant de rec&oacute;rrer aquelles branques que corresponguin a &laquo;candidats a soluci&oacute;&raquo; que no compleixen les restriccions del problema donat. Nosaltres la veurem per <strong><em>backtracking</em></strong>.</p>
<h5>Exemple. El problema de les &laquo;n&raquo; reines</h5>
<p>Donat un tauler d&#39;x caselles i&nbsp; reines, cal situar-les de manera que no s&#39;amenacin entre elles (segons les regles dels escacs). V&eacute;s aqu&iacute; algunes opcions:</p>
<ol>
<li>Podem mirar totes les possibles configuracions i veure quines compleixen les restriccions del problema. Aix&ograve; s&oacute;n&nbsp; combinacions; amb&nbsp; aix&ograve; s&oacute;n&nbsp; possibilitats.</li>
<li>Podem limitar-nos a posar una &uacute;nica reina en cada l&iacute;nia. Aix&ograve; s&oacute;n&nbsp; possibilitats; amb&nbsp;,&nbsp;.</li>
<li>Podem posar una &uacute;nica reina en cada fila i columna. Aix&ograve; s&oacute;n&nbsp; possibilitats; amb&nbsp;,&nbsp;.</li>
<li>Podem posar una &uacute;nica reina en cada fila, columna i diagonal.</li>
</ol>
<p>El problema amb aquestes propostes &eacute;s que fins que no hem acabat de construir una configuraci&oacute; no es mira si les condicions es compleixen o no. Ja en podr&iacute;em desestimar moltes mentre s&#39;estan construint: utilitzem la t&egrave;cnica del <em>backtracking</em>.</p>
<p>Una part important d&#39;aquesta t&egrave;cnica consisteix en determinar una manera per a representar les possibles configuracions (solucions) del problema. En el cas de les reines, ho farem amb una taula d&#39; posicions, tal que&nbsp; &eacute;s la columna on va la reina i que al tauler anir&agrave; en&nbsp;.</p>
<p>Definim un vector&nbsp;-completable de la seg&uuml;ent manera: sigui&nbsp;-completable, i&nbsp;. Les solucions al problema de les&nbsp; reines s&oacute;n els vector&nbsp;-completables.</p>
<p>Observacions:</p>
<ol>
<li>  (les dues darrers condicions cobreixen les diagonals).</li>
<li>El vector ha de ser&nbsp;-completable i, a m&eacute;s,&nbsp;.</li>
<li>Tots els vectors s&oacute;n&nbsp;-completables.</li>
<li>Les solucions al problema s&oacute;n els vectors n-completables.</li>
</ol>
<h5>Exemple. El problema de la motxilla</h5>
<p>&laquo;Una motxilla t&eacute; lloc per a C unitats de pes. Tria d&#39;entre&nbsp; objectes amb pesos&nbsp; i valor&nbsp; la combinaci&oacute; d&#39;objectes amb pes total inferior a C amb el valor m&agrave;xim&raquo;.</p>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/eda-cerca-exhaustiva/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/eda-cerca-exhaustiva/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/algorithmics/" rel="tag">algorithmics</a>, <a href="http://bloc.eurion.net/archives/tag/eda/" rel="tag">eda</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/eda-p-np/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Les classes de problemes P i NP'>Apunts d&#8217;Estructures de Dades i Algorismes: Les classes de problemes P i NP</a> <small>Classes de problemes &ndash; P i NP Entrades Problemes Classes...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-dividir-i-vencer/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer'>Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer</a> <small>Introducci&oacute; L&#39;esquema de programaci&oacute; de dividir i v&egrave;ncer &eacute;s una...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-programacio-dinamica/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Programació dinàmica'>Apunts d&#8217;Estructures de Dades i Algorismes: Programació dinàmica</a> <small>1. Nombres de Fibonacci L&#39;algorisme trivial per al c&agrave;lcul dels...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/eda-cerca-exhaustiva/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts d’Estructures de Dades i Algorismes: Grafs</title>
		<link>http://bloc.eurion.net/archives/2011/eda-grafs/</link>
		<comments>http://bloc.eurion.net/archives/2011/eda-grafs/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 12:39:57 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithmics]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1103</guid>
		<description><![CDATA[Definici&#243; i propietats Graf: Graf dirigit (digraf): Un cam&#237; de longitud &#233;s una seq&#252;&#232;ncia de v&#232;rtexs connectats (per arrestes/arcs) entre ells. Si tots els v&#232;rtexs s&#243;n diferents, el cam&#237; &#233;s simple. Un cicle &#233;s un cam&#237; simple amb la peculiaritat que comen&#231;a i acaba al mateix v&#232;rtex. El di&#224;metre d&#39;un graf &#233;s el m&#224;xim de [...]]]></description>
				<content:encoded><![CDATA[<h4>Definici&oacute; i propietats</h4>
<p><strong>Graf</strong>:<br />
	</p>
<p><strong>Graf dirigit</strong> (<em>digraf</em>):<br />
	</p>
<p>Un <strong>cam&iacute;</strong> de longitud  &eacute;s una seq&uuml;&egrave;ncia de v&egrave;rtexs connectats (per arrestes/arcs) entre ells. Si tots els v&egrave;rtexs s&oacute;n diferents, el cam&iacute; &eacute;s <strong>simple</strong>. Un <strong>cicle</strong> &eacute;s un cam&iacute; simple amb la peculiaritat que comen&ccedil;a i acaba al mateix v&egrave;rtex.</p>
<p>El <strong>di&agrave;metre</strong> d&#39;un graf &eacute;s el m&agrave;xim de tots els camins m&iacute;nims.</p>
<p>Diem que un graf&nbsp; &eacute;s <strong>connex</strong> si per tot parell de v&egrave;rtexs&nbsp; existeix un cam&iacute; que comen&ccedil;a en&nbsp; i acaba en&nbsp;.</p>
<p>Un graf no dirigit, connex i ac&iacute;clic (sense cicles) &eacute;s un <strong>arbre</strong> (<em>arbre lliure</em>); &eacute;s un graf no dirigit on hi ha exactament un cam&iacute; entre cada parell de v&egrave;rtexs. Els arbres tenen les seg&uuml;ents propietats:</p>
<ul>
<li>un arbre amb&nbsp; v&egrave;rtex t&eacute;&nbsp; arestes;</li>
<li>si s&#39;afegeix una aresta a un arbre llavors tindr&agrave; un (&uacute;nic) cicle;</li>
<li>si s&#39;elimina una aresta d&#39;un arbre llavors deixa de ser connex.</li>
</ul>
<p><span id="more-1103"></span></p>
<p>Un graf dirigit &eacute;s <strong>fortament connex</strong>&nbsp;si tots els parells de v&egrave;rtexs (considerant l&#39;ordre) tenen un cam&iacute; que els uneix, i <strong>d&egrave;bilment connex</strong> si &eacute;s connex al convertir-lo en un graf no dirigit.</p>
<p>Un v&egrave;rtex&nbsp; &eacute;s <strong>adjacent</strong> al v&egrave;rtex&nbsp; si&nbsp; ( si &eacute;s un graf dirigit).</p>
<p>El <strong>grau</strong> d&#39;un v&egrave;rtex &eacute;s el nombre de v&egrave;rtexs adjacents a ell i el grau d&#39;un graf &eacute;s el grau m&agrave;xim dels v&egrave;rtexs.</p>
<p>En grafs no dirigits,&nbsp;, es compleix el seg&uuml;ent teorema:&nbsp;.</p>
<p>Un graf &eacute;s <strong>complet</strong> si cont&eacute; el m&agrave;xim nombre d&#39;arestes/arcs possible. En el cas d&#39;un graf aquest &eacute;s&nbsp; i en el cas d&#39;un graf dirigit&nbsp;.</p>
<p>Un graf connex i no dirigit &eacute;s <strong>Euleri&agrave;</strong> si i nom&eacute;s si existeix un cam&iacute; que inclou cada aresta del graf exactament un cop.</p>
<p>Un graf &eacute;s <strong>Hamiltoni&agrave;</strong> si i nom&eacute;s si cont&eacute; un cicle Hamiltoni&agrave; (un cicle simple de longitud&nbsp;).</p>
<p>Un graf &eacute;s <strong>planar</strong> si &eacute;s possible representar-lo en paper sense que es creui cap l&iacute;nia. El teorema de Kuratowski afirma que nom&eacute;s el grafs que no contenen&nbsp; (el graf complet bipartit de 6 v&egrave;rtexs) ni&nbsp; (el graf complet de 5 v&egrave;rtexs) s&oacute;n planars. Enlla&ccedil;: <a href="http://ca.wikipedia.org/wiki/Graf_planar">article a la Viquip&egrave;dia</a>.</p>
<p>Els grafs tamb&eacute; poden tenir les seg&uuml;ents caracter&iacute;stiques, que no utilitzarem en aquest curs:</p>
<ul>
<li>Bucle (<em>loop</em>): aresta/arc que comen&ccedil;a i acaba en el mateix v&egrave;rtex.</li>
<li>Multigrafs: graf amb m&eacute;s d&#39;una aresta/arc connectant el mateix parell de v&egrave;rtexs.</li>
</ul>
<h4>Implementaci&oacute;</h4>
<p>El tipus abstracte de dades (TAD) <em>graf</em> compta amb m&egrave;todes com <em>crea</em>, <em>inserta_aresta</em>, <em>compta_vertex</em>, etc. Les dades es poden representar de diverses maneres.</p>
<h5>Matriu d&#39;ajdac&egrave;ncia</h5>
<p>Consisteix en representar el graf en una matriu de booleans . Per a grafs no dirigits i sense bucles, &eacute;s una matriu triangular, sim&egrave;trica en els dos costats.</p>
<p>&#8230; [FIXME: aqu&iacute; van dues imatges d&#39;exemple i les matrius corresponents] &#8230;</p>
<ul>
<li>Espai: </li>
<li>Temps de creaci&oacute;:  ( m&eacute;s el temps de lectura del graf)</li>
</ul>
<h5>Llista d&#39;adjac&egrave;ncia</h5>
<table style="width: 100%; border: 0;">
<tbody>
<tr style="border: 0;">
<td style="border: 0;">
<table>
<tbody>
<tr>
<td>1</td>
<td>2, 3</td>
</tr>
<tr>
<td>2</td>
<td>1, 4</td>
</tr>
<tr>
<td>3</td>
<td>1, 4, 5</td>
</tr>
<tr>
<td>4</td>
<td>2, 3, 6</td>
</tr>
<tr>
<td>5</td>
<td>3, 6</td>
</tr>
<tr>
<td>6</td>
<td>4, 5</td>
</tr>
</tbody>
</table>
</td>
<td style="border: 0;">

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> vector<span style="color: #000080;">&lt;</span>list<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;&gt;</span> graf<span style="color: #008080;">;</span>
<span style="color: #666666;">// o millor:</span>
<span style="color: #0000ff;">typedef</span> vector<span style="color: #000080;">&lt;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;&gt;</span> graf<span style="color: #008080;">;</span></pre></td></tr></table></div>

</td>
</tr>
</tbody>
</table>
<ul>
<li>Espai:  on  &eacute;s el nombre de v&egrave;rtex i  el nombre d&#39;arestes.</li>
</ul>
<h5>Quina de les representacions &eacute;s m&eacute;s convenient?</h5>
<p>La matriu &eacute;s m&eacute;s eficient en temps (acc&egrave;s directe a qualsevol posici&oacute; en ) per&ograve; en espai pot ser molt ineficient (quan cont&eacute; molts zeros, en el cas de grafs esparsos). Utilitzem la matriu per a grafs densos ().</p>
<p><strong>Exemple</strong></p>
<p>Tenim un graf amb  v&egrave;rtex i  arestes.</p>
<p>L&#39;espai en mem&ograve;ria que aquest ocupar&agrave; en cas d&#39;utilitzar una matriu d&#39;adjac&egrave;ncia, suposant que un boole&agrave; ocupa un byte, &eacute;s  (suposant que un boole&agrave; ocupa un bit, serien ).</p>
<p>Si en lloc d&#39;una matriu utilitzem una llista d&#39;adjac&egrave;ncia, on cada enter (o punter) ocupa 4 bytes, l&#39;espai que ocupar&agrave; &eacute;s  (multipliquem per 2 al suposar que es tracta d&#39;un graf no dirigit).</p>
<h4>Recorreguts</h4>
<p>Un <strong>recorregut</strong> &eacute;s una manera sistem&agrave;tica de visitar tots els v&egrave;rtex d&#39;un graf.</p>
<h5>Recorregut en profunditat</h5>
<p>El <strong>recorregut en profunditat</strong> (DFS, <em>depth first search</em>), similar al recorregut en pre-ordre dels arbres, consisteix en visitar un v&egrave;rtex i continuar el recorregut amb un v&egrave;rtex adjacent o l&#39;&uacute;ltim v&egrave;rtex visitat que no hagi estat visitat fins ara.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">list<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> dfs<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> graf<span style="color: #000040;">&amp;</span> G<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    list<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> L<span style="color: #008080;">;</span>
    vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">bool</span><span style="color: #000080;">&gt;</span> visitat<span style="color: #008000;">&#40;</span>G.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    stack<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> S<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> G.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>not visitat<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            S.<span style="color: #007788;">push</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>not S.<span style="color: #007788;">empty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                <span style="color: #0000ff;">int</span> v <span style="color: #000080;">=</span> S.<span style="color: #007788;">top</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> S.<span style="color: #007788;">pop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                L.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> visitat<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
                <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> w <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> w <span style="color: #000080;">&lt;</span> G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>w<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>not visitat<span style="color: #008000;">&#91;</span>G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>w<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> S.<span style="color: #007788;">push</span><span style="color: #008000;">&#40;</span>G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>w<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> L<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<h5>Recorregut en amplada</h5>
<p>El <strong>recorregut en amplada</strong> (BFS, <em>breadth first search</em>) &eacute;s similar al recorregut per nivells en un arbre. La implementaci&oacute; &eacute;s similar a la del recorregut en profunditat, per&ograve; utilitzant una cua en lloc d&#39;una pila.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">list<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> bfs<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> graf<span style="color: #000040;">&amp;</span> G<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    list<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> L<span style="color: #008080;">;</span>
    vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">bool</span><span style="color: #000080;">&gt;</span> encuat<span style="color: #008000;">&#40;</span>G.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    queue<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> Q<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> G.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>not encuat<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            Q.<span style="color: #007788;">push</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> encuat<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>not Q.<span style="color: #007788;">empty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                <span style="color: #0000ff;">int</span> v <span style="color: #000080;">=</span> Q.<span style="color: #007788;">front</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> Q.<span style="color: #007788;">pop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                L.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> w <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> w <span style="color: #000080;">&lt;</span> G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>w<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>not encuat<span style="color: #008000;">&#91;</span>G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>w<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                        Q.<span style="color: #007788;">push</span><span style="color: #008000;">&#40;</span>G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>w<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> encuat<span style="color: #008000;">&#91;</span>G<span style="color: #008000;">&#91;</span>v<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>w<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> L<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<h5>Ordenaci&oacute; topol&ograve;gica</h5>
<p>Donat un graf dirigit i ac&iacute;clic (DAG, <em>directed acyclic graph</em>), , una <strong>ordenaci&oacute; topol&ograve;gica</strong> de&nbsp; &eacute;s una ordenaci&oacute; dels seus v&egrave;rtexs tal que per tot parell de v&egrave;rtexs&nbsp;, si existeix un cam&iacute; d&#39; a&nbsp; al graf&nbsp;, aleshores&nbsp; no pot apar&egrave;ixer abans que&nbsp; a l&#39;ordenaci&oacute;.</p>
<p>Algorisme: Calculem el grau d&#39;entrada (el n&uacute;mero d&#39;arcs entrants) de tots els nodes. Afegim aquells on el grau &eacute;s zero en una pila i restem 1 al grau de tots els seus nodes adjacents; aquells adjacents que passin a grau 0 tamb&eacute; els afegim a la pila.</p>
<p>Com podem veure, l&#39;ordenaci&oacute; topol&ograve;gica &eacute;s una aplicaci&oacute; del recorregut en profunditat. Tamb&eacute; &eacute;s evident que no &eacute;s &uacute;nica, ja que pot tenir molts resultats possibles:</p>
<p><a href="http://bloc.eurion.net/wp-content/uploads/2011/01/Possibilitats-de-lordenacio-topològica.png"><img alt="" class="aligncenter size-medium wp-image-1138" height="224" src="http://bloc.eurion.net/wp-content/uploads/2011/01/Possibilitats-de-lordenacio-topològica-300x224.png" title="Possibilitats de l'ordenacio topològica" width="300" /></a></p>
<h5>Algorisme de Dijkstra</h5>
<p>Un graf  &eacute;s un&nbsp;<strong>graf amb pesos</strong> (<em>weighted graph</em>) si cada aresta  (o arc&nbsp;) del graf t&eacute; associat un valor&nbsp;. Si ,&nbsp; &eacute;s un graf amb pesos positius; si&nbsp;, &eacute;s un graf amb pesos no negatius.</p>
<p>Donat un graf&nbsp; amb pesos, el pes (tamb&eacute; anomenat valor, cost o dist&agrave;ncia, si els pesos s&oacute;n positius) &eacute;s la suma dels pesos de les arestes (o arcs) del cam&iacute;.</p>
<p>Donats dos v&egrave;rtexs&nbsp; qualssevol, diem que un cam&iacute; d&#39; a&nbsp; &eacute;s m&iacute;nim (o de pes m&iacute;nim) si el seu pes &eacute;s m&eacute;s petit o igual que el pes de qualsevol altre cam&iacute; d&#39; a&nbsp;. (Si no hi ha cap cami d&#39; a&nbsp; diem, per definici&oacute;, que el pes &eacute;s&nbsp;).</p>
<p>L&#39;<strong>algorisme de Dijkstra</strong> (pronunciaci&oacute;: &#39;d3Ikstra) calcula els camins m&iacute;nims d&#39;un v&egrave;rtexs&nbsp;&nbsp;cap a tots els altres v&egrave;rtexs del graf. Es tracta d&#39;un algorisme <strong>vora&ccedil;</strong> (<em>greedy</em>).</p>
<p>&#8230; [FIXME: aqu&iacute; va un exemple] &#8230;</p>
<p>Observacions:</p>
<ul>
<li>L&#39;algorisme de Dijkstra no funciona si hi ha pesos negatius.</li>
<li>El seu cost &eacute;s&nbsp;.</li>
</ul>
<h4>An&agrave;lisi de costs</h4>
<h5 style="margin-top: 0.6em;">Cost del recorregut en amplada</h5>
<ol>
<li>Cada v&egrave;rtex del graf entra i surt de la cua exactament una vegada. Aix&ograve; correspon a un temps .</li>
<li>La llista d&#39;adjac&egrave;ncies de cada v&egrave;rtex es recorre una &uacute;nica vegada, en el moment de treure el v&egrave;rtex de la cua. Per tant, per cada v&egrave;rtex&nbsp; aix&ograve; correspon a un temps&nbsp;, i en total, per a tots els v&egrave;rtexs, aix&ograve; correspon a un temps&nbsp;.</li>
<li>Hi ha el cost de les inicialitzacions, que &eacute;s&nbsp;.</li>
</ol>
<p>En total, el cost del recorregut en amplada &eacute;s&nbsp;.</p>
<h5 style="margin-top: 0.4em;">Cost del recorregut en profunditat</h5>
<ol>
<li>El bucle exterior es fa&nbsp; vegades.</li>
<li>Per cada iteraci&oacute;, el bucle interior es fa per tots els adjacents a cada v&egrave;rtex amb un cost . En total, el cost &eacute;s&nbsp;.</li>
<li>El cost de les inicialitzacions &eacute;s&nbsp;.</li>
</ol>
<p>En total, el cost del recorregut en profunditat &eacute;s&nbsp;.</p>
<h5 style="margin-top: 0.4em;">Cost de l&#39;ordenaci&oacute; topol&ograve;gica</h5>
<p>&Eacute;s igual al cost del recorregut en profunditat.</p>
<h5 style="margin-top: 0.4em;">Cost de l&#39;algorisme de Dijkstra</h5>
<ul>
<li>Sense fer servir cues de prioritat:<br />
		Per a cada v&egrave;rtex que s&#39;afegeix al conjunt soluci&oacute; el cost en temps &eacute;s  en cas pitjor. Com que s&#39;hi han d&#39;afegir els&nbsp; v&egrave;rtexs del grup, en total el cost &eacute;s&nbsp;.</li>
<li>Fent servir cues de prioritat per guardar les arestes/arcs:<br />
		A cada pas afegim un nou element al conjunt soluci&oacute;, tret de la cua de prioritats, amb cost&nbsp;. En total:&nbsp;.</li>
</ul>
<h4>Enlla&ccedil;os rellevants</h4>
<ul>
<li><a href="http://www.lsi.upc.edu/~ada/apunts/GV/ada-slides-4.pdf">ADA: Algorismes sobre grafs</a>, per Gabriel Valiente.</li>
<li><a href="http://ca.wikipedia.org/wiki/Graf">Article sobre grafs</a> a la Viquip&egrave;dia.</li>
</ul>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/eda-grafs/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/eda-grafs/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/algorithmics/" rel="tag">algorithmics</a>, <a href="http://bloc.eurion.net/archives/tag/eda/" rel="tag">eda</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/eda-calcul-cost-algorismes/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs'>Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs</a> <small>Introducci&oacute; Els algorismes s&oacute;n per tot arreu i per aix&ograve;...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-diccionaris/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Diccionaris'>Apunts d&#8217;Estructures de Dades i Algorismes: Diccionaris</a> <small>Introducci&oacute; S&oacute;n un tipus abstracte de dades (TAD), &eacute;s a...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-dividir-i-vencer/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer'>Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer</a> <small>Introducci&oacute; L&#39;esquema de programaci&oacute; de dividir i v&egrave;ncer &eacute;s una...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/eda-grafs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apunts d&#8217;Estructures de Dades i Algorismes: Diccionaris</title>
		<link>http://bloc.eurion.net/archives/2011/eda-diccionaris/</link>
		<comments>http://bloc.eurion.net/archives/2011/eda-diccionaris/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 22:28:53 +0000</pubDate>
		<dc:creator>RainCT</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithmics]]></category>
		<category><![CDATA[eda]]></category>
		<category><![CDATA[fib]]></category>
		<category><![CDATA[universitat]]></category>

		<guid isPermaLink="false">http://bloc.eurion.net/?p=1079</guid>
		<description><![CDATA[Introducci&#243; S&#243;n un tipus abstracte de dades (TAD), &#233;s a dir, un conjunt d&#39;elements i un conjunt d&#39;operacions sobre ells. Un diccionari &#233;s un conjunt d&#39;elements amb una clau associada (treta d&#39;un conjunt amb un ordre total definit) amb les operacions de cercar, inserir i esborrar un element. Una estructura de dades &#233;s una estructura [...]]]></description>
				<content:encoded><![CDATA[<h4>Introducci&oacute;</h4>
<p>S&oacute;n un <strong>tipus abstracte de dades</strong> (TAD), &eacute;s a dir, un conjunt d&#39;elements i un conjunt d&#39;operacions sobre ells.</p>
<p>Un <strong>diccionari</strong> &eacute;s un conjunt d&#39;elements amb una clau associada (treta d&#39;un conjunt amb un ordre total definit) amb les operacions de cercar, inserir i esborrar un element.</p>
<p>Una <strong>estructura de dades</strong> &eacute;s una estructura que ens permet implementar TAD.</p>
<h4>Implementacions de diccionaris</h4>
<h5 style="margin-top: 1em;">1) Taules (no ordenades)</h5>
<ul>
<li>Inserir un element nou: .</li>
<li>Esborrar un element: cost de cercar l&#39;element () + cost de treure&#39;l de la taula (varia segons el mecanisme d&#39;eliminaci&oacute;, possiblement ).</li>
</ul>
<h5>2) Llistes (enlla&ccedil;ades, encadenades)</h5>
<p>Per rec&oacute;rrer una llista s&#39;ha de fer de forma seq&uuml;encial, mitjan&ccedil;ant <strong>iteradors</strong> (punters).</p>
<p><a href="http://bloc.eurion.net/wp-content/uploads/2011/01/Llista-encadenada.png"><img alt="" class="aligncenter size-medium wp-image-1080" height="36" src="http://bloc.eurion.net/wp-content/uploads/2011/01/Llista-encadenada-300x36.png" title="Llista encadenada" width="300" /></a></p>
<ul>
<li>Inserir un element nou:<br />
		&nbsp;&nbsp;- al principi: ;<br />
		&nbsp;&nbsp;- al final de la llista, recorrent-la sencera:&nbsp;.</li>
<li>Cercar un element:&nbsp;</li>
<li>Esborrar un element: </li>
</ul>
<h5>3) Taules de dispersi&oacute; (<em>hash tables</em>)</h5>
<p><a href="http://bloc.eurion.net/wp-content/uploads/2011/01/Taula-de-dispersió.png"><img alt="" class="aligncenter size-medium wp-image-1086" height="155" src="http://bloc.eurion.net/wp-content/uploads/2011/01/Taula-de-dispersió-300x155.png" title="Taula de dispersió" width="300" /></a></p>
<p>El disseny de la funci&oacute; de <em>hash</em> &eacute;s molt important per obtenir taules ben equilibrades.</p>
<p>En cas pitjor, el cost ser&agrave; de , inserint al final amb una funci&oacute; de dispersi&oacute; que resulti en llistes llargues. Per&ograve;, si la funci&oacute; de dispersi&oacute; est&agrave; ben dissenyada, repartir&agrave; els elements equitativament, resultant llistes de mitjana  amb un cost .</p>
<p><span id="more-1079"></span></p>
<h5>4) Arbres binaris de cerca (ABC, o <em>Binary Search Tree</em>, BST)</h5>
<p><a href="http://bloc.eurion.net/wp-content/uploads/2011/01/Arbre-binari-de-cerca-1.png"><img alt="" class="alignleft size-thumbnail wp-image-1097" height="150" src="http://bloc.eurion.net/wp-content/uploads/2011/01/Arbre-binari-de-cerca-1-150x150.png" style="float: right; margin-left: 5px;" title="Arbre binari de cerca (1)" width="150" /></a></p>
<p>Un ABC &eacute;s un arbre binari on cada node t&eacute; una clau associada i els sub-arbres esquerra i dret compleixen les seg&uuml;ents propietats:</p>
<ol>
<li> clau  associada a un node del sub-arbre esquerra d&#39;un node amb clau  es compleix que .</li>
<li> clau  associada a un node del sub-arbre dret d&#39;un node amb clau  es compleix que .</li>
</ol>
<p>Observacions:</p>
<ol>
<li>Suposem que totes les claus s&oacute;n diferents.</li>
<li>Un arbre buit &eacute;s per definici&oacute; un ABC.</li>
</ol>
<ul>
<li>Construir un ABC a partir d&#39;un arbre buit i un conjunt d&#39; claus:<br />
		&nbsp;&nbsp;- cas millor:  (arbre equilibrat);<br />
		&nbsp;&nbsp;- cas mitj&agrave;: , suposant que totes les permutacions de les&nbsp; claus s&oacute;n igualment probables;<br />
		&nbsp;&nbsp;- cas pitjor:&nbsp; (ordenats).</li>
<li>Inserir una clau en un arbre d&#39; nodes:&nbsp;, on&nbsp; &eacute;s l&#39;al&ccedil;ada de l&#39;arbre.<br />
		</li>
<li>Cercar una clau en un arbre d&#39;al&ccedil;ada&nbsp;:&nbsp;.</li>
<li>Esborrar:<br />
		<img alt="" class="alignleft size-thumbnail wp-image-1093" height="150" src="http://bloc.eurion.net/wp-content/uploads/2011/01/Arbre-binari-de-cerca-3-150x150.png" style="float: left; margin-right: 5px;" title="Arbre binari de cerca (3)" width="150" />&nbsp;- Esborrar el 9: esborrar un fulla; &eacute;s f&agrave;cil.<br />
		&nbsp;- Esborrar el 7: esborrar un node amb un sub-arbre buit, &eacute;s f&agrave;cil.<br />
		&nbsp;- Esborrar l&#39;11: cal substituir-lo pel m&iacute;nim del sub-arbre dret (o b&eacute; pel m&agrave;xim del sub-arbre esquerra).</p>
<p style="clear: both;">&nbsp;</p>
</li>
</ul>
<h4>Arbres AVL (Adel&#39;son-Vel&#39;sk&icirc;i-Landis)</h4>
<p>Un arbre <strong>AVL</strong>&nbsp;&eacute;s un arbre binari de cerca tal que per tot node l&#39;al&ccedil;ada del seu seu-arbre esquerre no difereix en m&eacute;s d&#39;una unitat que l&#39;al&ccedil;ada del seu sub-arbre dret.</p>
<ul>
<li>Cercar una clau: algorisme id&egrave;ntic al dels ABC i de cost .</li>
<li>Inserir una clau: es fa servir el mateix algorisme dels ABC i despr&egrave;s, si la propietat de les al&ccedil;ades ja no &eacute;s certa, es reestructura l&#39;arbre per tal que torni a ser un arbre AVL.<br />
		Per tal de dur a terme la reestructuraci&oacute;, cada node ha de contenir informaci&oacute; de la seva al&ccedil;ada. A m&eacute;s, definim el concepte de <strong>factor d&#39;equilibri</strong>, com a l&#39;al&ccedil;ada del sub-arbre esquerra menys l&#39;al&ccedil;ada del sub-arbre dret; per ser . Al fer una inserci&oacute;, el primer node en tenir un mal factor d&#39;equilibri (&eacute;s a dir, de valor absolut superior a 1) &eacute;s el <strong>node cr&iacute;tic</strong>&nbsp;i &eacute;s on caldr&agrave; fer una <strong>rotaci&oacute;</strong>. Podem trobar-nos amb quatre casos:</p>
<ul style="margin-bottom: 0.4em;">
<li>Inserci&oacute; al sub-node esquerre del sub-node esquerre del node cr&iacute;tic (cas LL, <em>left-left</em>): cal fer una rotaci&oacute; simple.</li>
<li>Inserci&oacute; al sub-node dret del sub-node esquerre del node cr&iacute;tic (cas LR): cal fer una rotaci&oacute; doble.</li>
<li>Inserci&oacute; al sub-node esquerre del sub-node dret del node cr&iacute;tic (cas RL): cal fer una rotaci&oacute; doble.</li>
<li>Inserci&oacute; al sub-node dret del sub-node dret del node cr&iacute;tic (cas RR): cal fer una rotaci&oacute; doble.</li>
</ul>
<p>		El cost d&#39;una inserci&oacute; &eacute;s  (on h &eacute;s l&#39;al&ccedil;ada de l&#39;abre,&nbsp;) i el d&#39;una rotaci&oacute; &eacute;s .</li>
<li>Esborrar una clau: poden caldre fins a  passos per a rebalancejar l&#39;arbre.</li>
</ul>
<h4>Cues de prioritat</h4>
<p>Es creen en temps  amb l&#39;algorisme <strong><em>heapify</em></strong>; s&oacute;n un arbre que compleix la propietat que la clau de tot node &eacute;s inferior o igual a la clau del node pare.</p>
<ul>
<li>Crear una cua de prioritats: .</li>
<li>Consultar-ne el valor m&iacute;nim o m&agrave;xim: .</li>
<li>Esborrar-ne el valor m&iacute;nim o m&agrave;xim: .</li>
<li>Inserir un element: .</li>
</ul>
<h4>Tipus abstractes de dades de la llibreria est&agrave;ndard de C++</h4>
<table style="margin-top: 0.5em;">
<tbody>
<tr>
<td><strong>&lt;stack&gt;</strong></td>
<td>push, pop, top, size, empty</td>
<td><abbr title="Last in, first out">LIFO</abbr></td>
</tr>
<tr>
<td><strong>&lt;queue&gt;</strong></td>
<td>push, pop, front, size, empty</td>
<td><abbr title="First in, first out">FIFO</abbr></td>
</tr>
<tr>
<td><strong>priority_queue</strong></td>
<td>push, pop, top, size, empty</td>
<td>ordenada</td>
</tr>
<tr>
<td><strong>pair</strong></td>
<td colspan="2">Amb <em>&lt;utility&gt;</em>, proporciona operadors (==, &gt;=, &lt;=, etc.) sobrecarregats per a parells de dades.</td>
</tr>
<tr>
<td><strong>&lt;set&gt;</strong></td>
<td colspan="2">cost d&#39;inserci&oacute;: <br />
				<em>begin</em> &rarr; de tipus <em>set&lt;&#8230;&gt;::iterator</em><br />
				<em>end</em> &rarr; &iacute;dem, referencia l&#39;element seg&uuml;ent a l&#39;&uacute;ltim</td>
</tr>
</tbody>
</table>

<hr />
<p><small>
<a href="http://bloc.eurion.net/archives/2011/eda-diccionaris/#comments">No comments</a><br />
© Siegfried-Angel Gevatter Pujals, 2011. |
<a href="http://bloc.eurion.net/archives/2011/eda-diccionaris/">Permalink</a> |
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">License</a> |
Post tags: <a href="http://bloc.eurion.net/archives/tag/algorithmics/" rel="tag">algorithmics</a>, <a href="http://bloc.eurion.net/archives/tag/eda/" rel="tag">eda</a>, <a href="http://bloc.eurion.net/archives/tag/fib/" rel="tag">fib</a>, <a href="http://bloc.eurion.net/archives/tag/universitat/" rel="tag">universitat</a><br/>
</small></p><div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href='http://bloc.eurion.net/archives/2011/eda-grafs/' rel='bookmark' title='Apunts d’Estructures de Dades i Algorismes: Grafs'>Apunts d’Estructures de Dades i Algorismes: Grafs</a> <small>Definici&oacute; i propietats Graf: Graf dirigit (digraf): Un cam&iacute; de...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-dividir-i-vencer/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer'>Apunts d&#8217;Estructures de Dades i Algorismes: Dividir i Vèncer</a> <small>Introducci&oacute; L&#39;esquema de programaci&oacute; de dividir i v&egrave;ncer &eacute;s una...</small></li>
<li><a href='http://bloc.eurion.net/archives/2011/eda-calcul-cost-algorismes/' rel='bookmark' title='Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs'>Apunts d&#8217;Estructures de Dades i Algorismes: Càlcul de costs</a> <small>Introducci&oacute; Els algorismes s&oacute;n per tot arreu i per aix&ograve;...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bloc.eurion.net/archives/2011/eda-diccionaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
