(let ((*tasks* (make-hash-table)) (STATUS_UNKNOWN 0) (STATUS_CANT_DO 1) (STATUS_CAN_DO 2) (STATUS_DONE 3) (howManyToDiscover (list)) (discoverIndex 0) (thisMany 0)) (defstruct task cost value-orig value value-list value-index parent childeren status index team) (defun getNewTasksPre () (clearTasks) (dotimes (x (floor (* (floor (get-static 'size)) 2.5))) (getNewTask)) ;(setf *tasks* (reverse *tasks*)) (dotimes (x 6) (push (poisson (* (/ (get-static 'dynamisim) 50) 20)) howManyToDiscover))) (defun getTotalCost () (reduce #'+ (mapcar #'task-cost (ht2lst *tasks*)))) (defun getNewTasksPost () (let ((teams (get-team-indexes)) (weightedList (list)) (remainder 0)) (startTree (get-team-indexes)) (dolist (team teams) (let ((numtasks (+ (* (team-size (get-team team)) 2.5) remainder))) (setf remainder (- numtasks (floor numtasks))) (setf numtasks (- numtasks remainder)) (let* ((criticalityMultiplier (our-sample 'criticalityModifier))) (makeTaskTree (- (floor numtasks) 1) team (if (= 1 (floor (random criticalityMultiplier))) (expt criticalityMultiplier (get-static 'Criticality)) 1)))))) (interDependancy) (initialDiscover) (markPossibleTasks) nil) (defun interDependancy () (dohash (k v *tasks*) (if (> (get-static 'interDependancy) (random 100)) (let ((swapWith (+ 1 (floor (random (hash-table-count *tasks*)))))) (let ((thisTeam (task-team v)) (thatTeam (task-team (gethash swapWith *tasks*)))) (setf (task-team (gethash k *tasks*)) thatTeam (task-team (gethash swapWith *tasks*)) thisTeam)))))) (defun initialDiscover (&optional (howMany (progn (floor (* (hash-table-count *tasks*) (get-static 'initialKnown)))))) (setf thisMany howMany) (dotimes (x howMany) (setf (task-status (gethash (+ x 1) *tasks*)) STATUS_CANT_DO))) (let ((lastIndex 1) (lastAssigned 1)) (defun startTree (teams) (dolist (team teams) (setf (task-team (gethash lastAssigned *tasks*)) team (task-parent (gethash lastAssigned *tasks*)) 0) (incf lastAssigned) (incf lastIndex))) (defun clearAssignment () (setf lastIndex 1 lastAssigned 1)) (defun makeTaskTree (numtasks team costMultiplier) ;(format t "NumTasks: ~A~%" numtasks) (setf (task-parent (gethash lastAssigned *tasks*)) team) (let ((startedAt lastAssigned)) (dotimes (x numtasks) (let ((numKids (floor (our-sample 'NumChilderen)))) (dotimes (y numKids) ;(format t "~A < ~A~%" (+ 1 lastIndex) (hash-table-count *tasks*)) (if (<= lastIndex (+ startedAt numtasks)) (if (<= (incf lastIndex) (hash-table-count *tasks*)) (progn (push lastIndex (task-childeren (gethash lastAssigned *tasks*))) ;(setf (task-team (gethash lastAssigned *tasks*)) team) (setf (task-parent (gethash lastIndex *tasks*)) (task-index (gethash lastAssigned *tasks*))))))) (setf (task-team (gethash lastAssigned *tasks*)) team) (setf (task-cost (gethash lastAssigned *tasks*)) (* costMultiplier (task-cost (gethash lastAssigned *tasks*)))) (incf lastAssigned) (if (<= lastIndex (+ startedAt numtasks)) (incf lastIndex))))))) (defun task-relativeValue (task) (let ((culture (/ (get-static 'culture) 100))) (+ (* (task-value task) culture) (* (task-value-orig task) (- 1 culture))))) (defun getTaskRelativeValue (taskid) (task-relativeValue (gethash taskid *tasks*))) (defun getTasksForTeam (teamid type) ;still need to do the hybrid pruning... (mapcar #'task-index (remove-if #'(lambda (z) (if (not (equal type 'HY)) nil (if (> (/ (task-relativeValue z) (task-cost z)) (/ (reduce #'+ (mapcar #'getTaskRelativeValue (getTasksForTeam teamid 'AG))) (reduce #'+ (mapcar #'getTaskCost (getTasksForTeam teamid 'AG))))) nil t))) (stable-sort (copy-list (remove-if-not #'(lambda (x) (and (equal (task-team x) teamid) (equal (task-status x) STATUS_CAN_DO))) (ht2lst *tasks*))) #'> :key (cond ((equal type 'AG) #'task-relativeValue) ((equal type 'AG2) #'(lambda (y) (/ (task-relativeValue y) (task-cost y)))) ((equal type 'HY) #'(lambda (y) (/ (task-relativeValue y) (task-cost y)))) ((equal type 'PB) #'(lambda (y) (/ (task-value-orig y) (task-cost y))))))))) (defun ht2lst (ht) (let (lst) (maphash #'(lambda (k v) (push v lst)) ht) lst)) (defun sortBest(tasks) (sort tasks #'> :key #'(lambda (x) (if (> (getTaskValue x) 0) (/ (getTaskValue x) (getTaskCost x)) 0)))) (defun sortWorst(tasks) (sort tasks #'< :key #'(lambda (x) (if (> (getTaskValue x) 0) (/ (getTaskValue x) (getTaskCost x)) 0)))) (defun getTaskCost (taskid) (task-cost (gethash taskid *tasks*))) (defun getTaskValue (taskid) (task-value (gethash taskid *tasks*))) (defun getTaskOrigionalValue (taskid) (task-value-orig (gethash taskid *tasks*))) (defun getAllKnownTasks (&optional (keyFunction #'(lambda (z) (/ (task-value z) (task-cost z))))) (mapcar #'task-index (stable-sort (copy-list (remove-if #'(lambda (x) (equal (task-status x) STATUS_UNKNOWN)) (ht2lst *tasks*))) #'> :key keyFunction))) (defun getTask (taskid) (gethash taskid *tasks*)) (defun finishTask (taskid) (setf (task-status (gethash taskid *tasks*)) STATUS_DONE) (markPossibleTasks)) (defun markPossibleTasks () (mapc #'(lambda (x) (if (equal (task-status x) STATUS_CANT_DO) (if (= 0 (length (remove-if-not #'(lambda (y) (equal (task-status (gethash (task-index x) *tasks*)) STATUS_DONE)) (task-childeren x)))) (setf (task-status x) STATUS_CAN_DO)))) (ht2lst *tasks*))) ;(dolist (task *tasks*) ;(format t "~A ~A ~%" (task-index task) (task-status task)))) (defun discoverNewTasks () (let ((addThisTime (nth discoverIndex howManyToDiscover))) ;(print "Step 2") (dohash (index task *tasks*) ;(print "Step 3") ;(print (task-status task)) ;(print "Step 3.2") ;(print addThisTime) (if (and (> addThisTime 0) (equal (task-status task) STATUS_UNKNOWN)) (progn ;(print "Step 4") (setf (task-status task) STATUS_CANT_DO) (decf addThisTime))))) ;(print "Step 5") (markPossibleTasks) ;(print "Step 6") (incf discoverIndex)) (let ((taskindex 0)) (defun getNewTask () (let ((task (make-task))) (setf (task-cost task) (our-sample 'taskCost) (task-value task) (our-sample 'taskValue) (task-value-orig task) (task-value task) (task-index task) (incf taskindex) (task-status task) STATUS_UNKNOWN (task-value-index task) 0 (task-parent task) 0) (dotimes (x 6) (push (* (normal 0 (* (/ (get-static 'dynamisim) 50) 2)) (dist9-max (gethash 'taskValue *dists*))) (task-value-list task))) (setf (gethash (task-index task) *tasks*) task))) (defun clearTasks () (clearAssignment) (setf taskindex 0 *tasks* (make-hash-table) howManyToDiscover (list) discoverIndex 0))) (defun changeTaskValues () "this is what it does" (dohash (index task *tasks*) (if (> (task-value task) 0) (setf (task-value task) (max 0 (+ (nth (- (incf (task-value-index task)) 1) (task-value-list task)) (task-value task))))))) (defun resetTasks () (dohash (index task *tasks*) (setf (task-value task) (task-value-orig task) (task-value-index task) 0 (task-status task) STATUS_UNKNOWN)) (setf discoverIndex 0) (initialDiscover thisMany)) (defun showTasks() (showh *tasks*)) (defun getTasks () (ht2lst *tasks*)))