Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2006, 11:10 AM
skroops skroops is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 1 skroops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 58 sec
Reputation Power: 0
Ruby help, programming noob

I'm trying to make a program to automatically make a work schedule.

There's a number of different things I need to implement, such as off days, specific jobs for different people, "on-call" workers, etc.

I tried it one way yesterday but that didn't work well at all. I think the way I was trying to assign people to jobs was too complicated so I started over today.

I decided on setting up a class "Soldier" that will include the persons name as a string, and then have a series of priority codes to decide to which of the different available seats at work they will be assigned. There are three possible values for the person's priority on a job: 2, it's the person's main job; 1, qualifed; or 0, unqualified.

I will put those soldiers in an array called 'team'. I eventually want to write this array to a file at the end of the program, and then import that file the next time it is run, but I'll figure that out later.

Now I was planning to write a series of statements for each job and have it search my array and look for the person who had the highest priority code on that job, then assign that persons name to that job (represented by an object of class Truck).

Problem I have is that I can't figure out how to search through each persons entry for that specific value in an array. I would then take the highest one, push him to the end of the array, or copy to another array and take his name out of the list and continue to the next job.

Also as you can see in the code here, when I define my class Soldier I have to then remap those private variables to public ones. Is there a way I can make those things public in the initialize def, instead of having to define each of them individually?
Thanks for any help.

(This is what I have so far on the new one):

Code:
----
#~ We have 5 trucks, in 4 of them (truck 1, 2, 5, and ASV)there are 3 slots, a driver, tc (passenger), and a gunner.  in the forth truck (wrecker 1), is just a driver and tc.

#~ The program I'm trying to make needs to do the following:
#~ * Place qualified people in the truck they are qualified in
#~ * Take the extra people once the trucks are filled and give them that day off, 
#~ * Cycle the people that are off so that the first person off isn't off again until everyone else has been off.
#~ * Two seperate lists of people for off-days: NCO's and lower-enlisted
#~ * NCO's can only be off wed-sunday, and only one at a time.
#~ * Thursday truck1 and truck2's gunner are off, but "on-call" so will still be slotted in a truck, but will also take an available day-off.
#~ * Sunday is like thursday,  but also the team-sergeant (SSG Gib) will be on-call, and will take an nco day-off.
#~ * Every day we need two people on radio duty.  On days that no NCOs were off the day before, it will be divided into two shifts, with the lower-enlsted that were off the day before taking
#~ both shifts.  On days where an nco other than SSG Gib were off the day before, that NCO will take the whole shift, and two lower enlisted that were off will take the first and second half of the shift.

class Truck #generic truck
  def initialize
    @dr = nil #driver
    @tc = nil #tc (passenger)
    @gu = nil #gunner
  end
  
  def dr
    @dr
  end
  def dr=(newDr)
    @dr = newDr
  end
  
  def tc
    @tc
  end
  def tc=(newTc)
    @tc = newTc
  end
  
  def gu
    @gu
  end
  def gu=(newGu)
    @gu = newGu
  end
  
end

class Soldier #personnel and priority
  def initialize(name,gun1dr,gun1tc,gun1gu,gun2dr,gun2tc,gun2gu,gun5dr,gun5tc,gun5gu,wrk1dr,wrk1tc,nco)
    @name = name
    @gun1dr = gun1dr
    @gun1tc = gun1tc
    @gun1gu = gun1gu
    @gun2dr = gun2dr
    @gun2tc = gun2tc
    @gun2gu = gun2gu
    @gun5dr = gun5dr
    @gun5tc = gun5tc
    @gun5gu = gun5gu
    @wrk1dr = wrk1dr
    @wrk1tc = wrk1tc
    @nco = nco
  end
  def name
    @name
  end
  def gun1dr
    @gun1dr
  end
  def gun1tc
    @gun1tc
  end
  def gun1gu
    @gun1gu
  end
  def gun2dr
    @gun2dr
  end
  def gun2tc
    @gun2tc
  end
  def gun2gu
    @gun2gu
  end
  def gun5dr
    @gun5dr
  end
  def gun5tc
    @gun5tc
  end
  def gun5gu
    @gun5gu
  end
  def wrk1dr
    @wrk1dr
  end
  def wrk1tc
    @wrk1tc
  end
  def nco
    @nco
  end
end
#add hadRto? for whether they had rto last day off

#(name,gun1dr,gun1tc,gun1gu,gun2dr,gun2tc,gun2gu,gun5dr,gun5tc,gun5gu,wrk1dr,wrk1tc,nco)
#will only do this the first time to generate text file
team = Array.new

team.push(Soldier.new("SPC Smi",0,0,0,0,0,0,0,1,0,2,0,false))
team.push(Soldier.new("SGT Tho",0,0,0,0,2,0,0,0,0,0,0,true))
team.push(Soldier.new("SPC Sta",0,0,0,0,0,0,1,0,0,2,0,false))
team.push(Soldier.new("PFC Vuk",0,0,0,0,0,0,0,0,0,0,3,false))
team.push(Soldier.new("SGT Edd",0,2,0,0,0,0,0,1,0,1,0,true))
team.push(Soldier.new("PFC Bol",0,0,0,0,0,3,0,0,0,0,0,false))
team.push(Soldier.new("PFC Sip",0,0,0,3,0,0,0,0,0,0,0,false))
team.push(Soldier.new("SPC Est",2,0,0,0,0,0,0,0,0,0,0,false))
team.push(Soldier.new("SPC Fer",2,0,0,0,0,0,0,0,0,0,0,false))
team.push(Soldier.new("PFC Wil",0,0,3,0,0,0,0,0,0,0,0,false))
team.push(Soldier.new("PFC Hou",0,0,0,0,0,0,0,0,2,0,0,false))
team.push(Soldier.new("SPC Wag",0,0,0,0,0,0,1,0,0,0,2,false))
team.push(Soldier.new("SPC And",2,0,0,2,0,0,0,0,0,0,0,false))
team.push(Soldier.new("SPC Sap",0,0,0,0,0,0,0,0,2,0,0,false))
team.push(Soldier.new("PFC Riv",2,0,0,0,0,0,0,0,0,0,0,false))
team.push(Soldier.new("SGT Eld",0,3,0,0,0,0,0,0,0,0,0,true))
team.push(Soldier.new("SPC Ten",0,0,0,0,0,0,2,0,0,0,0,false))
team.push(Soldier.new("SGT Mil",0,1,0,0,0,0,0,2,0,0,0,true))
team.push(Soldier.new("SSG Gib",0,0,0,0,0,0,0,0,0,0,0,false))
team.push(Soldier.new("SGT Min",0,1,0,0,2,0,0,0,0,1,0,true))

#make 2 different arrays for nco and soldier
#import soldier array
#import nco array


#assign off days and RTO duty for nco
  #check day
  #if day is a sunday, add SSG Gib to off days, he will be on-call
  #if day is wednesday through saturday
    #pull nco off the front of the list
    #add him to days off
    #move him to another array
  #put last nco on rto duty
  #add the remaining to the front of the copy in the same order they are in
  #if day is monday or tuesday, add them to main job assignment roster
  #take the copy and export it to text file
#end

#assign off days and rto for soldier
  #check had rto flag on last soldiers
  #if there are more soldiers that had rto than needed
    #randomly assign rto to them
    #add soldier to rto duty
    #set rto flag
  #elsif
    #add soldier to rto duty
    #set rto flag
  #end
#end

#check day
  #if day is a thursday or sunday
    #add gunners as on-call
    #add remaining off-days
  #elsif day is other
    #pull soldiers off the front of array
    #put them on off list
    #copy array
  #end
  #add remaining to soldier off roster
  #export to text file
#end

#assign remaining workers to main job roster
  
#assign jobs
  #check each truck
  #find the person with the highest priority code for each job
  #assign them to that job
  #if there is more than one person that has the same code, randomly assign them
    
#export jobs,rto, and off days to csv formatted spread sheet file
  
    

Reply With Quote
  #2  
Old August 15th, 2006, 01:51 PM
thebudbottle thebudbottle is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 16 thebudbottle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 30 sec
Reputation Power: 0
I'd have a look at the attr_reader attr_writer methods. They can be called statically and be given a list of symbols, all of whose corresponding value are then accessible simply by calling object.attribute, or object.attribute = x for writable variables.

For (a redundant) example:
Code:
class MyClass

    attr_reader :myvariable1, :myvariable2
    attr_writer :myvariable1, :myvariable2

    def initialize(val1, val2)
        @myvariable1 = val1
        @myvariable2 = val2
    end

end


myobj = myClass.new(1,2)
myobj.myvariable1 = 12

puts "Val 1: #{myobj.myvariable1}, val 2: #{myobj.myvariable2}"

OUTPUT:
ruby test.rb
Val 1: 12, val 2: 2


Hope this helps,

Chris

Reply With Quote
  #3  
Old August 16th, 2006, 03:21 PM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,538 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1050
In addition, look at attr_accessor, which does both

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Ruby help, programming noob

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap