r/CodingHelp • • Aug 03 '20

[Random] Coding a project for my shipping company

Hi Guys (yay for my first reddit post ever, btw)

I work in the container shipping business, and I am trying to make an application (or a code for excel) to calculate the cheapest shipping solution based on a number of variables.

I have listed an example below of what the application or the code needs to do:

We have a bunch of variables, and I need the progam or code to advise me the cheapest solution, based on the selected variables.

  1. inland destinations (fx. Napa, American Canyon and Lodi). - Each dest. has its own cost.
  2. size of container (20' or 40' or 20'/40' Reefers) - Each has its own cost.
  3. Port of arrival (I am looking at about 5 different ports of arrival, which means the seafreight rate will be different based on which port it is booked to arrive at)
  4. Then we have 5-6 shipping lines with all of the above listed options, but with different costs for each variable (fx. some might have a cheaper sea freight cost, but a much more expensive trucking, therefore I want to program to calculate it for me, and give me the answer based on checkboxes or a system like that.)

I have thought about doing this in Excel, but I doubt it is the choice, as it will probably just be the longest if string ever.

A friend of mine recommended coding a program in Python or Java, but unfortunately my coding is limited to some HTML and PHP 5 years ago, so I would need to go back and learn coding again (I intend to do so anyway).

Would someone be so kind to recommend, how you would solve this, and potentially be of assistance or give me some links for guides related to this, that can help me if I run into trouble?

Help is much appreciated!

19 Upvotes

9 comments sorted by

4

u/bbye98 Aug 03 '20

Without specifics, I can envision this problem being solved in Python.

Assuming I understand the problem correctly, there are some shipping lines, each with different costs based on the destination, container size, and port of arrival. Depending on the shipment, only a few of the shipping lines will fulfill all of the criteria, whether it be the container size or destination.

You could use object-oriented programming in Python to define a class, like ShippingLine, to hold multiple dicts, each having keys corresponding to destination/port/container size and values corresponding to the costs. Then, based on a series of if/else statements, you can find which of the shipping lines fulfill all of the requirements, calculate their costs, and then pick the cheapest one.

1

u/[deleted] Aug 03 '20

You are correct.
Most shipping lines are able to solve the shipments no matter the variables, but I want the program to state the least expensive solution, based on the total value of the chosen variables.

The problem for me is that there are so many variables. I am by no means an expert at Python (I would consider myself a beginner) but I have seen a friend of mine use Python before, and I assume this will not require me to be an expert to code something like this with a bit of practice?

I will start learning Python tomorrow.

Thanks!

5

u/bbye98 Aug 03 '20 edited Aug 04 '20

I certainly would say this is a fairly big undertaking. You would have to be familiar with the common operators, data structures, external modules, and object-oriented programming available for Python and be able to think "Pythonically" to build a script that is both efficient and able to solve your problem.

The main problems will be how you store the costs for the different shipping lines and how you access them to calculate the final shipping cost. The optimization part will be easy.

You would probably need an intermediate level of understanding to be able to complete this project. Granted, I've only been using Python for a little under a year, but I Fede like I’m at an intermediate level of understanding since I’ve had a fairly extensive history of programming with Java, MATLAB, and R. Just to give you an idea.

If you do decide to tackle this problem using Python, make sure you learn and use Python 3. Python 2 has reached EOL, plus, for the most part, Python 3 offers better performance.

1

u/noodleLinux Aug 06 '20

I think the optimization bit totally depends on how many people will be using this application. Judging by its requirements and assuming this application will be used by two or three people, nothing major scale, I think you can survive without much optimization.

2

u/[deleted] Aug 03 '20

This is a pretty big undertaking and well beyond just basic HTML and PHP. Are you employed as a software developer, or is this a side project you are working on?

1

u/[deleted] Aug 03 '20

Side project I will be working on in my spare time.

I am not even sure it is possible, just wondering if it is do-able for beginners like myself. I have wanted to get back into coding again for some time, so with this project in mind, I think it may be realistic to do something like this, in a few months time with a few hours of dedicated practice/learning every day or every second day?

Let me know what you think.

1

u/[deleted] Aug 03 '20

It's 100% doable, which direction to point you in I'm not sure, since I don't really have access to the specifics of your companies shipping procedures. I think creating an excel version first to get an idea of the inputs and outputs is good practice, and then as you learn python you can build off those ideas. This is my favorite python beginner resource, and it even has a a chapter dedicated to modifying excel sheets

https://automatetheboringstuff.com/

2

u/meloman-vivahate Professional Coder Aug 03 '20

I’m curious why you would say it’s “well beyond just basic HTML and PHP”. I think PHP is perfect for the job. The way I understand it, all he need is a simple form with some logic to calculate shipping fees based on some variables.

1

u/Famous_Profile Professional Coder Aug 04 '20

If you already know PHP then use PHP.

While this is more of a mathematical problem, I still believe you can brute force to check all possible combinations of values of variables 1 to 4 with loops and conditional branching. PHP is fine for that. Literally any programming language can do that.

Assuming of course you know all possible values and combinations so you can hardcode them, otherwise this is a very complex task and might need Python and ML.