PHP Classes

How to Use a PHP Transportation Calculation Script with the Package Northwest Corner Method: Initial solution for the transportation problem

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-03-04 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
northwest-corner-met 1.0GNU General Publi...5Algorithms, PHP 5, Geography
Description 

Author

When calculating the costs associated with transporting materials to and from one or more destinations is necessary, the northwest corner method is a heuristic applied to a special structure of linear programming problems.

The method can be used to implement a solution that outlines the feasibility of developing a project or task.

This package provides an initial basic solution that satisfies all the restrictions and calculates the transportation steps recursively according to the original algorithm without implying that the total optimal cost is reached.

This method is especially used when quick organizational solutions are required.

This package can find the initial solution for the transportation problem.

It provides a script that processes values from a form containing details about a transportation problem, such as the transportation offer, demand, and costs.

When a material must be transported to and from a destination, the northwest corner method can help approximate consumption and associated expenses.

This allows important cost estimation calculations to determine the feasibility of developing a project or task.

The script can perform calculations and presents a step-by-step solution with the variable activity, cost per unit, and distribution costs.

Innovation Award
PHP Programming Innovation award nominee
February 2025
Nominee
Vote
Transportation problems are complex because vehicles need to visit several places.

Depending on the order in which vehicles visit the places, they may spend more or less money depending on the costs of going from one place to another place.

This package provides an initial solution to the transportation problem using the Northwest Corner Method.

Manuel Lemos
Picture of Roberto Aleman
  Performance   Level  
Name: Roberto Aleman <contact>
Classes: 20 packages by
Country: Venezuela Venezuela
Innovation award
Innovation award
Nominee: 11x

Winner: 1x

Instructions

No installation required. Only the data entered by the users and the program shows the results are necessary.

There are 2 files that process the data, calcular.php works as native php functions, northwestcornermethod.php is the class,

Example

<!DOCTYPE html>
<html>
<head>
    <title>Northwest Corner Method by Roberto Aleman, ventics.com</title>
    <link rel="stylesheet" type="text/css" href="style.css">
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
>
</head>
<body style="
    padding: 1em;
">
    <h1>Northwest Corner Method</h1>
    Credits to <a href="https://ventics.com">Roberto Aleman, ventics.com</a>

    <div id="input-data">
        <h2>Enter Data:</h2>
        <form id="northwestForm" method="post" action="">
            <label for="oferta">Plant Capacity (separated by commas):</label>
            <input type="text" id="oferta" name="oferta" value="80, 30, 60, 45"><br><br>
            <label for="demanda">Warehouse Requirements (separated by commas):</label>
            <input type="text" id="demanda" name="demanda" value="70, 40, 70, 35"><br><br>
            <label for="costos">Transportation Costs (comma-separated rows):</label><br>
            <textarea id="costos" name="costos" rows="4" cols="30">
5,2,7,3
3,6,6,1
6,1,2,4
4,3,6,6</textarea><br><br>
            <button type="submit">Calculate</button>
        </form>
    </div>

    <div id="resultados">
        <?php
       
if ($_SERVER["REQUEST_METHOD"] == "POST") {
            include
'northwestcornermethod.php'; // Include your class file

           
$oferta_str = $_POST['oferta'];
           
$demanda_str = $_POST['demanda'];
           
$costos_str = $_POST['costos'];

           
$northwest = new NorthwestCornerMethod($oferta_str, $demanda_str, $costos_str);
           
$northwest->solve();
            echo
$northwest->getResultados();
        }
       
?>
</div>

    <script src="script.js"></script>

    Credits to <a href="https://ventics.com">Roberto Aleman, ventics.com</a>

</body>
</html>


Details

Northwest-Corner-Method

Northwest Corner Method

Project Description: Northwest Corner Method Application Developed by Roberto Alemán, ventics.com

This project is an interactive PHP application designed to solve transportation problems using the Northwest Corner Method. It specifically addresses scenarios involving 4 plants and 4 warehouses, each with their respective supply and demand requirements.

Project Components:

User Interface (HTML, CSS, JavaScript): Allows users to input the necessary data: Production capacity of each plant (supply). Requirements of each warehouse (demand). Transportation costs associated with each plant-warehouse pair. Presents the results in a clear and organized manner: Solution table, showing the quantity of units assigned from each plant to each warehouse. Distribution cost table, detailing the variable activity, cost per unit, and total distribution cost. Total distribution cost. Utilizes AJAX to send data to the server and receive responses without page reloads. Server-Side Logic (PHP): Receives data input by the user. Implements the Northwest Corner Method algorithm to calculate the optimal solution. Calculates the distribution costs associated with each assignment. Generates HTML code to display the results in the user interface. Key Features:

Dynamic Data Input: Users can modify capacity, requirement, and cost values as needed. Step-by-Step Calculation: The program displays the unit allocation process, making the method easy to understand. Clear Results Visualization: Tables and total cost provide a comprehensive view of the solution. Distribution Cost Calculation: Costs associated with each allocation are detailed, and the total cost is calculated. Objective:

The primary objective of this project is to provide an interactive and educational tool that enables users to understand and apply the Northwest Corner Method to solve transportation problems. Additionally, by allowing dynamic data input, it facilitates experimentation with different scenarios and the generation of customized solutions.

Basic Concepts about Northwest Corner Method

Transportation Problem: Involves determining the optimal quantity of goods to ship from various origins (factories, warehouses) to various destinations (customers, distribution centers) to minimize total transportation costs. Northwest Corner: Refers to the upper-left cell in a transportation table that represents the origins and destinations.

Method Steps

Build the Transportation Table: Organize the data into a table where the rows represent the origins, the columns represent the destinations, and the cells contain the unit transportation costs.

Assign the Maximum Possible Quantity: Start in the northwest corner cell and assign the largest possible quantity of units, taking into account the supply constraints of the origin and the demand of the destination.

Adjust Supply and Demand: Subtract the assigned quantity from the origin's supply and the destination's demand. If the supply is exhausted, eliminate the corresponding row. If the demand is met, eliminate the corresponding column.

Move to the Next Cell: If the row was eliminated, move to the next cell down in the same column. If the column was eliminated, move to the next cell to the right in the same row. If both the row and column were eliminated, move to the next cell diagonally.

Repeat the Process: Continue assigning quantities and adjusting supply and demand until all constraints are satisfied.

Considerations

The northwest corner method is easy to apply, but it does not guarantee the optimal solution. Its main objective is to obtain an initial feasible solution that can be improved with other methods, such as the Stepping Stone method or the MODI method.

In summary

The northwest corner method is a useful tool to start solving transportation problems, providing a basis for finding more efficient solutions.


  Files folder image Files (16)  
File Role Description
Plain text file calcular.php Appl. Application script
Plain text file classdemo.php Example Example
Plain text file index.html Data Demonstration page
Plain text file LICENSE Lic. License text
Image file Northwest corner S...Method Figure 1.jpg Screen Northwest corner Solution Method Figure 1x
Image file Northwest corner S...Method Figure 2.jpg Screen Northwest corner Solution Method Figure 2
Image file Northwest corner S...Method Figure 3.jpg Screen Northwest corner Solution Method Figure 3
Image file Northwest corner S...Method Figure 4.jpg Screen Northwest corner Solution Method Figure 4
Image file Northwest corner S...Method Figure 5.jpg Screen Northwest corner Solution Method Figure 5
Image file Northwest corner S...Method Figure 6.jpg Screen Northwest corner Solution Method Figure 6
Image file Northwest corner S...ion Method Figure 7 Screen Northwest corner Solution Method Figure 7.jpg
Image file Northwest corner S...ion Method Figure 8 Screen Northwest corner Solution Method Figure 8.jpg
Plain text file northwestcornermethod.php Class Class
Plain text file README.md Doc. Documentation
Plain text file script.js Data Auxiliary data
Plain text file style.css Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 50%
Total:0
This week:0