Click here to Skip to main content
15,886,362 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionRe: Get best 5 names and their quantity from 3000 strings, by 40 columns. Pin
Paul Conrad21-Aug-15 17:57
professionalPaul Conrad21-Aug-15 17:57 
QuestionBin Packing Pin
Cenator18-Aug-15 19:59
Cenator18-Aug-15 19:59 
AnswerRe: Bin Packing Pin
OriginalGriff18-Aug-15 20:02
mveOriginalGriff18-Aug-15 20:02 
GeneralRe: Bin Packing Pin
harold aptroot19-Aug-15 2:04
harold aptroot19-Aug-15 2:04 
GeneralRe: Bin Packing Pin
Cenator19-Aug-15 2:29
Cenator19-Aug-15 2:29 
GeneralRe: Bin Packing Pin
harold aptroot19-Aug-15 2:55
harold aptroot19-Aug-15 2:55 
AnswerRe: Bin Packing Pin
Patrice T21-Aug-15 12:20
mvePatrice T21-Aug-15 12:20 
GeneralRe: Bin Packing Pin
Cenator21-Aug-15 16:25
Cenator21-Aug-15 16:25 
Hi
This is about my "project course".

The project almost completed by c#.

[^]
______________
I used a greedy algorithm to placing items in bins so it is not a optimized algorithm. Cry | :((

here is my placing function:

C#
public static string placeItemInBin(Item itemToPlacing)
{
    sortBinList();
    LinkedListNode<Bin> binNode;
    bool isPlaced = false;
    int allSideStates = 1;

    while (allSideStates <= 2)
    {
        binNode = listOfBins.First;
        while (isPlaced == false && binNode != null)
        {
            if (binNode.Value.RemainLength >= itemToPlacing.Length)
                if (binNode.Value.RemainWeight >= itemToPlacing.Weight
                    && binNode.Value.Width >= itemToPlacing.Width
                    && binNode.Value.Height >= itemToPlacing.Height)
                {
                    LinkedListNode<Partition> partitionNode;
                    LinkedListNode<Partition> Best;
                    Best=null;
                    partitionNode = binNode.Value.parts.First;
                    while (partitionNode != null)
                    {
                        //Best Fit :
                        if (partitionNode.Value.num == -1
                            && partitionNode.Value.size >= itemToPlacing.Length
                            && (Best == null || partitionNode.Value.size <= Best.Value.size))
                        {
                            Best = partitionNode;
                            if (Best.Value.size == itemToPlacing.Length)
                                break;
                        }
                        partitionNode = partitionNode.Next;
                    }
                    if (Best != null) //Now Is Time To Place Item In Bin
                    {
                        string placingDetail;

                        if (Best.Value.size == itemToPlacing.Length)//No Need To Separate Nodes
                        {
                            Best.Value.num = itemToPlacing.Number;
                            itemToPlacing.CmPlaceInBin = Best.Value.cmBegin;
                        }
                        else //Separate Nodes
                        {
                            Partition newPart = new Partition(itemToPlacing.Length, itemToPlacing.Number,
                                Best.Value.cmBegin);
                            Best.Value.cmBegin += itemToPlacing.Length;
                            Best.Value.size -= itemToPlacing.Length;
                            //Add New Part Node:
                            binNode.Value.parts.AddBefore(Best, newPart);
                            //
                            itemToPlacing.CmPlaceInBin = newPart.cmBegin;
                        }

                        itemToPlacing.BinNumber = binNode.Value.Number;
                        binNode.Value.RemainLength -= itemToPlacing.Length;
                        binNode.Value.RemainWeight -= itemToPlacing.Weight;
                        binNode.Value.RemainVolume -= itemToPlacing.Length
                            * binNode.Value.Width * binNode.Value.Height;
                        isPlaced = true;
                        if (itemToPlacing.IsRotate == true)
                            placingDetail = "Item: Number: " + itemToPlacing.Number +
                            " (Rotated), Placed In Bin Number: " + binNode.Value.Number;
                        else
                            placingDetail = "Item: Number: " + itemToPlacing.Number +
                            " (Not Rotated), Placed In Bin Number: " + binNode.Value.Number;
                        return placingDetail;
                    }
                }
            binNode = binNode.Next;
        }
        itemToPlacing.changeSideState();
        allSideStates++;
    }
    //Bin Not Found
    itemToPlacing.BinNumber = -1;
    itemToPlacing.CmPlaceInBin = -1;
    return "Not Found";
}

SuggestionRe: Bin Packing Pin
Patrice T21-Aug-15 17:05
mvePatrice T21-Aug-15 17:05 
AnswerRe: Bin Packing Pin
Patrice T21-Aug-15 18:15
mvePatrice T21-Aug-15 18:15 
GeneralRe: Bin Packing Pin
Cenator21-Aug-15 20:53
Cenator21-Aug-15 20:53 
GeneralRe: Bin Packing Pin
harold aptroot21-Aug-15 23:29
harold aptroot21-Aug-15 23:29 
GeneralRe: Bin Packing Pin
Cenator22-Aug-15 0:04
Cenator22-Aug-15 0:04 
AnswerRe: Bin Packing Pin
Patrice T22-Aug-15 3:46
mvePatrice T22-Aug-15 3:46 
QuestionStrict alternation Pin
Bowri18-Aug-15 4:11
Bowri18-Aug-15 4:11 
AnswerRe: Strict alternation Pin
Simon_Whale18-Aug-15 5:12
Simon_Whale18-Aug-15 5:12 
GeneralRe: Strict alternation Pin
Bowri18-Aug-15 7:14
Bowri18-Aug-15 7:14 
GeneralRe: Strict alternation Pin
Richard MacCutchan18-Aug-15 7:40
mveRichard MacCutchan18-Aug-15 7:40 
GeneralRe: Strict alternation Pin
Bowri18-Aug-15 18:11
Bowri18-Aug-15 18:11 
AnswerRe: Strict alternation Pin
Patrice T21-Aug-15 12:16
mvePatrice T21-Aug-15 12:16 
Questionl-Exclusion Pin
Bowri18-Aug-15 4:09
Bowri18-Aug-15 4:09 
SuggestionRe: l-Exclusion Pin
Richard MacCutchan18-Aug-15 6:39
mveRichard MacCutchan18-Aug-15 6:39 
GeneralRe: l-Exclusion Pin
Bowri18-Aug-15 7:17
Bowri18-Aug-15 7:17 
GeneralRe: l-Exclusion Pin
Richard MacCutchan18-Aug-15 7:38
mveRichard MacCutchan18-Aug-15 7:38 
GeneralRe: l-Exclusion Pin
Bowri18-Aug-15 18:10
Bowri18-Aug-15 18:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.