Bay 12 Games Forum

Please login or register.

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

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

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9435 on: May 02, 2016, 02:49:36 pm »

Pretty sure tree from carbon it's open source.

Pretty sure the cron daemon is open source.
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 #9436 on: May 02, 2016, 08:41:11 pm »

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.

This definitely doesn't sound related the cron/crontab utility on linux, which just executes things at a given time. As for the actual algorithm, my instinct (which is fairly rusty for algorithmic problems) tells me that this is sorta a knapsack problem.
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 #9437 on: May 02, 2016, 09:10:14 pm »

The knapsack problem is a bit different: fill knapsack(s) of volume V as full as possible from N items, but leftovers don't matter. The bin-packing problem is a little closer: take N items and pack them into the least amount of bins of volume V.

But scheduling is about filling a set amount of bins as empty as possible, using all N items:

https://en.wikipedia.org/wiki/Scheduling_(computing)
https://en.wikipedia.org/wiki/Job_shop_scheduling
https://en.wikipedia.org/wiki/Job_shop_scheduling#Offline_makespan_minimization
https://en.wikipedia.org/wiki/Multiprocessor_scheduling
https://en.wikipedia.org/wiki/Partition_problem

My guess is that the lecturer was talking about one of the algorithms addressed here, but referring to it as the "cron algorithm".
« Last Edit: May 02, 2016, 09:30:40 pm by Reelya »
Logged

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9438 on: May 02, 2016, 10:46:48 pm »

: D N-Body simulator for something I'm working on.

This took far longer than I wanted it to. Also, the display sizes are not accurate representations of the data at work.
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9439 on: May 03, 2016, 03:13:04 am »

I'm trying to finish my raytracer for a class assignment. I'm almost done, but my helper functions are causing errors:
Code: [Select]
1>c:\users\bumber\documents\visual studio 2013\projects\proj2\proj2\raytrace.hh(425): error C2662: 'void raytrace::Scene::compute_ray(int,int,const std::shared_ptr<const raytrace::Image>,std::shared_ptr<raytrace::Vector4>,std::shared_ptr<raytrace::Vector4>)' : cannot convert 'this' pointer from 'const raytrace::Scene' to 'raytrace::Scene &'
1>          Conversion loses qualifiers
1>c:\users\bumber\documents\visual studio 2013\projects\proj2\proj2\raytrace.hh(426): error C2662: 'bool raytrace::Scene::trace_ray(std::shared_ptr<raytrace::Vector4>,std::shared_ptr<raytrace::Vector4>,std::shared_ptr<raytrace::SceneObject>)' : cannot convert 'this' pointer from 'const raytrace::Scene' to 'raytrace::Scene &'
1>          Conversion loses qualifiers
1>c:\users\bumber\documents\visual studio 2013\projects\proj2\proj2\raytrace.hh(429): error C2662: 'std::shared_ptr<gmath::Vector<double,3>> raytrace::Scene::lambert_shade(const std::shared_ptr<const raytrace::Intersection>,const std::shared_ptr<const raytrace::SceneObject>)' : cannot convert 'this' pointer from 'const raytrace::Scene' to 'raytrace::Scene &'
1>          Conversion loses qualifiers
I'm not even sure where the type of the class is coming into play.

Source:
http://pastebin.com/mqzYizbp
http://pastebin.com/dFRUJCBP
http://pastebin.com/A8h5KT79
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9440 on: May 03, 2016, 04:00:21 am »

You can't take a reference to a const variable, because a reference means changeable.

You can fix this a few ways: remove the const tag where it's being added, cast the const variable to the non-const type, or change the function so that it takes a const reference (preferred if it's not changing the value).

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9441 on: May 03, 2016, 04:32:39 am »

Allright here's the Cron algorithm itself:

1. Allocate the tasks among the processors randomly, thust getting an approximate solution

   1.1 Let j := 1, that is we're assigning task 1 to a random processor

   1.2 Generate a random integer in range [1..N], k := random(1, N)

   1.3 Assign task 1 to processor k

   1.4 Increment j := j + 1

   1.5 j > M? If it is so, go to Step 2 else repeat steps 1.1 - 1.5 

2. Improving the schedule we have got

   2.1 Calculate the loads on the processors

   2.2 Let p* be the processor which load is maximal (define it as T_max).
            Let p' be the processor which load is minimal (define it as T_min)
   
   2.3 Calculating delta := T_max - T_min

   2.4 Looking through the tasks on processor p*

   2.5 If we find a task which execution time is less than delta, assign it to
            processor p' (removing it from p*) and return to step 2.1, else go to step 2.6

   2.6 For each i (i := 1..k), for each j (j := 1..l):
       If tau(t_i) > tau(t_j) and tau(t_i) - tau(t_j) < delta, then swap t_i and t_j, return to 2.1

            (Where t_i is the i-th task assigned to p*, k tasks alltogether; t_j is the j-th task
            assigned to p', l tasks altogether)

   2.7 If no task reallocation has been done on step 2.6, then we conclude that the schedule
        can't be improved any further, go to step 3.

3. THE END
« Last Edit: May 03, 2016, 04:44:11 am by RoguelikeRazuka »
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9442 on: May 03, 2016, 07:24:17 am »

You can't take a reference to a const variable, because a reference means changeable.

You can fix this a few ways: remove the const tag where it's being added, cast the const variable to the non-const type, or change the function so that it takes a const reference (preferred if it's not changing the value).
The problem is I'm not sure where it's being added. The compiler is complaining about the type of the class itself (this pointer.) Here's the relevant class with the unimportant stuff gutted:
Code: (C++) [Select]
  // Class for an entire scene, tying together all the other classes in this module.
  class Scene {
  private:
    //declaring a bunch of smart pointer vectors
  public:
    Scene(std::shared_ptr<Light> ambient_light, std::shared_ptr<Color> background_color, std::shared_ptr<Camera> camera, bool perspective) : //-constructor with initialization list-
    //-fill some vectors here-
    std::shared_ptr<Image> render(int width, int height) const { //this class's most important function
      //declare some more things
      //for loops
      compute_ray(x,y,image,origin,dir); // <-- problematic function call
      //more stuff
      return image;
    }
  private:
    void compute_ray(int x, int y, const std::shared_ptr<const Image> image, std::shared_ptr<Vector4> origin, std::shared_ptr<Vector4> dir) { //origin and dir will be modified
        double l = _camera->l(), b = _camera->b(), u, v; //_camera is a private variable of Scene; l() and b() are const functions
        std::shared_ptr<Vector4> right;
        u = l + (_camera->r() - l)*(x + 0.5)/(image->width()*1.0); //r() is also a const function
        v = b + (_camera->t() - b)*(y + 0.5)/(image->height()*1.0); //as is t()
        right = _camera->up->cross(-*dir); //up() is const, return type const Vector4&; cross(const Vector4& right) is const, returns Vector4 pointer
        *right = (*right)/right->magnitude(); //this is normalizing the vector
        if(_perspective) {
          dir = *(*(*-_camera->gaze()*(-_camera->d())) + (*right)*u) + _camera->up()*v //d() is const; gaze() is const, return type const Vector4&;
          *origin = _camera->location(); //location() is const, returns Vector4&
        }
        else {
          *dir = _camera->gaze();
          origin = *(_camera->location() + (*right)*u) + _camera->up()*v;
        }
        return;
    }

As far as I can tell, the error refers to the line "compute_ray(x,y,image,origin,dir);" which would implicitly be "this.compute_ray(x,y,image,origin,dir);"

I'd try removing const from the render function, but the instructor put that there. Does the function's const just mean it doesn't modify members of the class (i.e., other classes are fair game?) Maybe the solution is to put const on the compute_ray function, to assure it I'm still not touching the class? I'll try later tomorrow, but it sounds like the right answer.

Edit: Yes, that fixed it. Now I just need to figure out change my Vector4's into Matrix3x3's to cross multiply, then back again.
« Last Edit: May 04, 2016, 07:50:46 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9443 on: May 03, 2016, 07:57:48 am »

Render is a const function, this means that it can't call compute_ray, because it isn't const.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9444 on: May 03, 2016, 08:06:19 am »

Ahh yeah, that would be the problem. A const function won't change the object, so it's an error to call a non-const function from that, since that could break the const-ness.
« Last Edit: May 03, 2016, 08:16:04 am by Reelya »
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9445 on: May 03, 2016, 08:13:47 am »

So yeah, problems with "this" means you look at the code that's creating the object, not the class itself.

Code: [Select]
class someclass {
void constfunc() const {
nonconstfunc();
}

void nonconstfunc() {
;
}
};

error: passing 'const someclass' as 'this' argument of 'void someclass::nonconstfunc()' discards qualifiers [-fpermissive]

You are mistaken.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9446 on: May 03, 2016, 08:17:21 am »

But that is the code that's creating the reference (which is what we are having problems passing). I wasn't aware that it was called from code within the same class until just now however because I didn't have time to read all the code dump. But still, the point stands that you look at the code initiating the function call, rather than the callee.
« Last Edit: May 03, 2016, 08:22:00 am by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9447 on: May 03, 2016, 03:13:42 pm »

Trying to make a program for a college class that writes data to a file from a structure, and can read data from the file to display on screen. Currently have two char pointers in the struct for use in dynamically made arrays. When reading the struct data from the binary file, the program crashes upon trying to print either array of chars. Presumably because it doesn't assign anything to the pointers when reading data from the file?

Can I not use pointers and dynamic memory for binary file input/output? O am I just doing something wrong?
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9448 on: May 03, 2016, 03:15:24 pm »

You're doing something wrong.
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9449 on: May 03, 2016, 03:36:03 pm »

I'm not really sure what I'm doing wrong then. New to working with binary data files. The few examples I've worked on from my college textbook don't give many details on what's written to the binary file or read from the binary file. As far as I can see, it just writes data for a struct to a file, and when read from the file it copies all the data from the initial struct, which was stored in the file, to the new struct. The example programs do not use any pointers or dynamic arrays, though. That's something I thought would work the same way. Obviously not, since it's broken.

Only reason I'm using char arrays in the struct is because the instructions say to.

Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.
Pages: 1 ... 628 629 [630] 631 632 ... 796