(* Copyright 1992 Digital Equipment Corporation. *)
(* Distributed only by permission.*)
(* Last modified on Thu Apr 28 09:47:52 PDT 1994 by najork *)
(*      modified on Thu Jul  8 22:22:57 PDT 1993 by mhb   *)
(*      modified on Wed Jul 29 23:11:45 PDT 1992 by johnh *)

IMPORT BinpackAux, IntList, RealList;

OUTPUT Setup (nBins, nWts: INTEGER[Fmt.Int]);
(* Call once at the beginning to identify for views how many
   weights there will be for packing and how many bins to use.
   The algorithm terminates when all weights have been processed. *)

OUTPUT NewWeight (id: INTEGER[Fmt.Int]; wt: REAL[Fmt.Real]);
(* Got a new weight to try packing into a bin. Id's are between
   0 and nWts-1. Weights are between 0 and 1, and each bin can 
   hold at most 1 unit of weight. It is not guaranteed that the
   id's will be sequential. *)

OUTPUT Pack (bin: INTEGER[Fmt.Int]; total: REAL[Fmt.Real]);
(* Pack the current weight into the specified bin, raising the
   amount stored in that bin to the specified total. Bins are 
   numbered starting at 0.*)

OUTPUT Ignore ();
(* The current weight cannot be packed into any bin; simply ignore it *)

OUTPUT Probe (bin: INTEGER[Fmt.Int]; total: REAL[Fmt.Real]);
(* Probe to the current weight to see if it fits into 
   the specified bin, which has the specified total. *)


(* 
**   The following regular expression defines the 
**   output event stream generated by a Binpack algorithm:
**
**           Setup (NewWeight Probe* (Pack | Ignore))*
**
*)


FEEDBACK TryToDeleteWeight (id: INTEGER[Fmt.Int]);
(* Signal the algorithm to delete the id'th weight from whatever 
   bin it was packed in. *)

FEEDBACK TryToEmptyBin (bin: INTEGER[Fmt.Int]);
(* Signal the algorithm to remove all weights from the 
   specified bin. *)

UPDATE RepackBin (
  bin: INTEGER[Fmt.Int]; 
  old, new: IntList.T[BinpackAux.IntListToText];
  amts: RealList.T[BinpackAux.RealListToText]);
(* Remove all weights from the specified bin (those in the old list), and
   repack the bin (from bottom to top) with those weights in the new list. 
   The value of each weight in the new list is given by the amts list. *)



