0

I am using the following packing problem code from github: https://github.com/davidmchapman/3DContainerPacking. I can't show all the code on there but here's what I wrote. I have never used C# and am wondering why my result returns null. I made the following program to input my data and return my result but it doesn't seem to work. Am I calling the other programs in my solution incorrectly?

using CromulentBisgetti.ContainerPacking;
using CromulentBisgetti.ContainerPacking.Algorithms;
using CromulentBisgetti.ContainerPacking.Entities;

List<Container> containers = new List<Container>();
containers.Add(new Container(1, Convert.ToDecimal(12030), Convert.ToDecimal(2400), Convert.ToDecimal(2390)));



List<Item> itemsToPack = new List<Item>();
itemsToPack.Add(new Item(3, Convert.ToDecimal(3100), Convert.ToDecimal(1280.382), Convert.ToDecimal(880), 1));
itemsToPack.Add(new Item(590261, Convert.ToDecimal(2380), Convert.ToDecimal(460), Convert.ToDecimal(735), 1));
itemsToPack.Add(new Item(4, Convert.ToDecimal(1638.161), Convert.ToDecimal(891.535), Convert.ToDecimal(2753.832), 2));
itemsToPack.Add(new Item(2, Convert.ToDecimal(1500), Convert.ToDecimal(1224.091), Convert.ToDecimal(462), 1));
itemsToPack.Add(new Item(290698, Convert.ToDecimal(1400), Convert.ToDecimal(190), Convert.ToDecimal(150), 2));
itemsToPack.Add(new Item(490661, Convert.ToDecimal(1250), Convert.ToDecimal(560), Convert.ToDecimal(4500), 1));
*plus a bunch more items*


List<int> algorithms = new List<int>();
algorithms.Add((int)AlgorithmType.EB_AFIT);

List<ContainerPackingResult> result = PackingService.Pack(containers, itemsToPack, algorithms);
Rand Random
  • 7,300
  • 10
  • 40
  • 88
shongololo
  • 21
  • 5
  • 3
    Why are you using `Convert.ToDecimal(12030)` everywhere when you could just use _decimal literals_? ([use the `M` suffix](https://stackoverflow.com/q/977484/159145)) e.g. `12030M` will be a `Decimal` value. – Dai Jun 20 '23 at 09:00
  • what is `PackingService`? Where is it defined? Probably you need to look there, in order to answer your question. – MakePeaceGreatAgain Jun 20 '23 at 09:00
  • @MakePeaceGreatAgain The answers to your questions are in the provided link to GitHub. – oerkelens Jun 20 '23 at 09:02
  • 3
    i had a look in the git repo and the PackingService.Pack method should never return null. how do you see that the result is null? are you maybe running into an exception somewhere? – Molbac Jun 20 '23 at 09:04
  • @Molbac I did a debug at the last line and the result showed in the autos window. How would I know if I run into an exception? Should I add a "using" at the top of my code for the PackingService? – shongololo Jun 20 '23 at 09:11
  • 2
    It is typically up to the one asking questions to ensure the question contain all necessary information to solve it. While links can be useful for background information, they can go dead, so they should not be relied on anything that is needed for the question to make sense. – JonasH Jun 20 '23 at 09:11
  • @JonasH sorry I genuinely just don't have a good enough understanding of C# to make sure I provide the necessary information. I wouldn't know what to add and what to leave out since I don't know where the problem stems from – shongololo Jun 20 '23 at 09:15
  • @shongololo when debugging, did you execute the last line or did you stop at the last line? – Molbac Jun 20 '23 at 09:16
  • @Molbac I stopped at the last line, then I continued but the autos window disappears after executing the last line – shongololo Jun 20 '23 at 09:27
  • 2
    @shongololo add another line. some Console.WriteLine(). stop there and then you should see some value in the result variable. – Molbac Jun 20 '23 at 09:29
  • @Molbac Thank you that showed me a result I appreciate it. Since my result has other properties imbedded, do you know of a way to clearly display? – shongololo Jun 20 '23 at 09:39
  • 1
    @shongololo while debugging you can look inside the result object and see all its properties and values. you can also try the .ToString() method, if it is implemented. – Molbac Jun 20 '23 at 09:44

0 Answers0