Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 627 628 [629] 630 631 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886963 times)

lethosor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9420 on: April 28, 2016, 08:04:18 pm »

Is the keyboard hooked up to the tablet, or is it a wireless keyboard with a receiver connected to the pi?
I'm a bit surprised that pygame keyboard events are working with a headless pi, since pygame uses SDL internally, which typically requires a windowed environment for keyboard events. Anyway, I'm pretty sure that it won't read keyboard events over SSH, unless you can also get it to read keyboard events from a local terminal (on the pi) somehow.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9421 on: April 28, 2016, 08:26:46 pm »

You'd need to create an event handler for receiving the remote signal that corresponds to the keypress.

I'm not sure how you would do that, but I found this: http://www.paramiko.org/
It's a Python SSH interface, so with some programming it would probably be able to do what you want.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9422 on: May 02, 2016, 03:40:43 am »

About C#. The thing is that I need to implement a simple custom dictionary class that inherits from the IDictionary interface, and I want to know which (already implemented in .NET) collection type would it be wise to use as a private collection for storing the dictionary items? Could somebody provide me with more or less intelligible example showing how to implement the generic version of IDictionary?
« Last Edit: May 02, 2016, 03:43:11 am by RoguelikeRazuka »
Logged

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9423 on: May 02, 2016, 03:52:22 am »

You'd need to create an event handler for receiving the remote signal that corresponds to the keypress.

I'm not sure how you would do that, but I found this: http://www.paramiko.org/
It's a Python SSH interface, so with some programming it would probably be able to do what you want.

pygame also has some community made server-client libs  http://pygame.org/project-Mastermind+Networking+Lib-859-.html
Logged

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9424 on: May 02, 2016, 08:10:27 am »

About C#. The thing is that I need to implement a simple custom dictionary class that inherits from the IDictionary interface, and I want to know which (already implemented in .NET) collection type would it be wise to use as a private collection for storing the dictionary items? Could somebody provide me with more or less intelligible example showing how to implement the generic version of IDictionary?

But .net already has dictionaries, and if you're going to use one as the backing for your custom dictionary... That sounds kind of silly.

Could you describe what you're actually trying to accomplish? (Or, put more simply, "what do you want?")
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9425 on: May 02, 2016, 08:42:26 am »

Could be asking what kind of data structure to store the key-item relationship behind the scenes of the abstract data type "dictionary."
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9426 on: May 02, 2016, 09:06:11 am »

About C#. The thing is that I need to implement a simple custom dictionary class that inherits from the IDictionary interface, and I want to know which (already implemented in .NET) collection type would it be wise to use as a private collection for storing the dictionary items? Could somebody provide me with more or less intelligible example showing how to implement the generic version of IDictionary?

But .net already has dictionaries, and if you're going to use one as the backing for your custom dictionary... That sounds kind of silly.

Could you describe what you're actually trying to accomplish? (Or, put more simply, "what do you want?")
Could be asking what kind of data structure to store the key-item relationship behind the scenes of the abstract data type "dictionary."
That's what I was thinking too.

A heap seems like a good choice, since with a dictionary, insert/delete and fast searching are the main operations, which are things heaps are good at.
« Last Edit: May 02, 2016, 09:09:15 am by Reelya »
Logged

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9427 on: May 02, 2016, 10:21:49 am »

About C#. The thing is that I need to implement a simple custom dictionary class that inherits from the IDictionary interface, and I want to know which (already implemented in .NET) collection type would it be wise to use as a private collection for storing the dictionary items? Could somebody provide me with more or less intelligible example showing how to implement the generic version of IDictionary?
Could you describe what you're actually trying to accomplish? (Or, put more simply, "what do you want?")

It's a simple educational task which purpose is to learn the concept of interfaces in C#. I got to implement my own List, Queue, Dictionary classes that inherit from some of IDictionary, IList, IEnumerable, and ICollection interfaces. I have already coded the List and Queue classes (List is based on an array of T and inherits from ICollection<T>, IList<T>, IEnumerable<T>, Queue aggregates a List instance and utilizes the methods its class provides, inheriting from ICollection<T>), but I'm unsure how I would do that for my dictionary class. I've been planning to use a vector (C# array) of DictionaryEntry,  though I don't know if it would be correct or anything.

To make it more clear, here's the code:

http://pastebin.com/w2LxX0EZ

As you see, no kind of *best* implementation is required, something really basic just to show what interfaces in C# are all about.
« Last Edit: May 02, 2016, 10:59:02 am by RoguelikeRazuka »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9428 on: May 02, 2016, 10:36:21 am »

There's no "correct" way. That's what an interface is for: the interface is specified, and then you do the implementation however it works best. So basically, your internal stuff doesn't need to inherit from IList, even if you use a list internally. An interface is for external clients only.
« Last Edit: May 02, 2016, 10:38:27 am by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9429 on: May 02, 2016, 10:38:25 am »

you could even store keys and values in two arrays and search for the position of the key, then return the value.

it'd be slow and defeat the purpose, yes, but it can still obey the dictionary interface, I think.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9430 on: May 02, 2016, 10:43:45 am »

Actually, that's more efficient than interleaving key/value pairs, because of memory caching. If you interleave the data, then cachelines include all the key and value data, which you then read past to get just the keys. If you separate out the keys, then the CPU's memory lookahead works much better: you're only reading through the keys, then doing a single table lookup to get the value once you known you have a valid key.

Obviously, this effect is more pronounced for big data sets or if the size of the values is large. e.g. an empty C++ STL std::string is ~24 bytes. Presumably, the actual contents of the string is stored elsewhere, but 24 bytes is the minimal overhead for the concrete part of the std::string.

So if you have int keys and std::string values, the interleaving them means you're reading 28 bytes to get 1 key to compare. It's about 200 clock cycles to load a cache line of 64 bytes, so you're getting maybe 90-100 clock cycles per key you check. If you have only the int keys in an array, then you can load 16 of them in the 200 clock cycles, and 12 clock cycles is plenty of time to compare 2 ints and increment a pointer. So that would be a speedup factor of about 8 times just by having separate arrays for int keys and std::string values.

But of course, linear arrays are pretty brute-force for this type of problem. If the keys are sortable in any way, you can exploit that: since dictionary keys don't have to be in any order, you can store them in a sorted data structure to begin with, which can be a binary tree, or a hashing system if you want.
« Last Edit: May 02, 2016, 05:17:42 pm by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9431 on: May 02, 2016, 11:06:21 am »

I am mildly amused that my random inefficient idea turns out to be a not bad way to code something. I do think that the chief downside is slow removals of items, though.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9432 on: May 02, 2016, 11:21:07 am »

Oh yeah does anybody know anything about so-called *Cron* algorithm? I don't know exactly how one would spell the name correct, though. This algorithm serves for solving the scheduling problem where there are M tasks and N processors (executors, devices etc) given each of the tasks is executed in the same amount of time no matter to which processor it's assigned, that is the said *doers* all have an equal score of productivity. Teacher says this algorithm beats any onther heurstic ones that solve this problem, even genetic ones. BUT I could not find any information about this Cron algorithm on the web.
« Last Edit: May 02, 2016, 12:08:46 pm by RoguelikeRazuka »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9433 on: May 02, 2016, 11:27:16 am »

well, given M tasks that can be executed in the same amount of time no matter what, and N processors, it seems all you'd need to do is schedule them in a round-robin way. Are you sure you presented the problem correctly?

Also, Wikipedia has a bunch of examples of scheduling algorithms. Asking your teacher is a surefire way too.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9434 on: May 02, 2016, 11:49:14 am »

Oh well.

Suppose we have a computing system including N independent processors, threads, devices, executors etc (set P = {p_1,...,p_N}). There are also M tasks (set T = {t_1,...,t_M}) being passed in the said computing system to be handled. We know how much time (or any other meaningful resource in a particular case) is needed to process a given t_i from T, some tau(t_i), by either processor, that is each task can be executed by each of the processors in the same amount of time, and note that processors can't delegate some of the tasks assigned to them to any other processor. The objective is to find such schedule that the total amount of time to execute all tasks on either processor would be minimal.

A schedule is a mapping A_R : T -> P such that if A_R(t_i) = p_j, task t_i from T is said to be assigned to processor p_j from P. A schedule can be also defined as a partition of set T into N disjunctive subsets.

The criterium (that is objective function) to determine how good the outcoming schedule (and thus the algorithm we've used) is is the following: f_r = max f_j (1<=j<=n) -> min, where f_j = tau(t_j_1) + ... + tau(t_j_k) stands for how much time it requires for processor p_j to execute all the tasks (k' tasks alltogether) assigned to it.
« Last Edit: May 02, 2016, 12:21:33 pm by RoguelikeRazuka »
Logged
Pages: 1 ... 627 628 [629] 630 631 ... 796