caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "alphablock" <alphablock@wanadoo.fr>
To: "caml-list" <caml-list@yquem.inria.fr>
Subject: Problème de l'achat par lots
Date: Sun, 3 Jul 2005 22:41:23 +0200	[thread overview]
Message-ID: <002801c5800f$ab1d0e00$a22cf8c1@oemcomputer> (raw)


Bonsoir à tous les chameliers,


J'ai défini un type "inventaire" qui est une liste de paires
(quantité,pièce) ainsi que 2 opérations de base. Les listes sont triées
selon le nom des pièces. La 1ère opération réalise l'union de deux
inventaires, la 2nd opération réalise la différence de deux inventaires et
renvoit une paire de listes (pièces restantes,pièces manquantes) :


type inventory = (int * string) list;;

let rec union_inventory (a:inventory) (b:inventory) =
  match a,b with
  | [],_ -> b
  | _,[] -> a
  | (qa,pa as ha)::ta,(qb,pb as hb)::tb ->
      if pa < pb then ha::(union_inventory ta b)
      else if pa > pb then hb::(union_inventory a tb)
      else (qa+qb,pa)::(union_inventory ta tb);;

let rec difference_inventory (a:inventory) (b:inventory) =
  match a,b with
  | [],_ -> [],b
  | _,[] -> a,[]
  | (qa,pa as ha)::ta,(qb,pb as hb)::tb ->
      if pa < pb then
        let r,m = difference_inventory ta b
        in  ha::r,m
      else if pa > pb then
        let r,m = difference_inventory a tb
        in  r,hb::m
      else
        let r,m = difference_inventory ta tb in
        if qa < qb then r,(qb-qa,pa)::m
        else if qa > qb then (qa-qb,pa)::r,m
        else r,m;;


Maintenant je voudrais implémenter une opération plus complexe. Soit un
inventaire recherché par un achateur, et soit une liste de lots-inventaires
en vente. L'acheteur veut maximiser son investissement, c'est-à-dire avoir
le moins de pièces manquantes possible et le moins de pièces supperflues
possible. Comment trouver la(les) combinaison(s) de lots la(les) plus
avantageuse(s) ?

Je ne vois pas bien comment il faut aborder le problème:
* est-ce un "backpack problem" ?
* est-ce un "union-find problem" ?
* est-ce un "genetic-oriented problem" ?
* sinon qu'est-ce que c'est ?

merci de votre aide,

- damien

web page: http://perso.wanadoo.fr/alphablock/




             reply	other threads:[~2005-07-03 20:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-03 20:41 alphablock [this message]
2005-07-31 11:46 Problème_de_l'achat_par_lots Diego Olivier Fernandez Pons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='002801c5800f$ab1d0e00$a22cf8c1@oemcomputer' \
    --to=alphablock@wanadoo.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).