This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns rxjava-datomic.query | |
(:require [datomic.api :as d]) | |
(:use [clojure.repl :only [pst]]) | |
(:import [rx Observable] | |
datomic.Peer)) | |
(defn query [qry & inputs] | |
(Observable/toObservable | |
(Peer/q qry (object-array inputs)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- optimal-plan-ordered [bids] | |
(let [optimal-plan-after (fn [flight] | |
(let [earliest (+ (:DEPART flight) (:DUREE flight)) | |
after (drop-while #(< (:DEPART %) earliest) bids)] | |
(if (empty? after) {:gain 0 :path '()} (optimal-plan-ordered after)))) | |
current-plan (fn [flight] | |
(let [{:keys [gain path]} (optimal-plan-after flight)] | |
{:gain (+ (:PRIX flight) gain) :path (conj path (:VOL flight))}))] | |
(reduce #(if (> (:gain %2) (:gain %1)) %2 %1) (map current-plan bids)))) |