Giter VIP home page Giter VIP logo

cutting-stock-java's Introduction

This java library solves cutting stock problem using greedy approach. Greedy approach may not give the optimal solution but gives an acceptable solution quickly. Using this library is simple.

Here is a simple example

If I have metal rods of size 700mm and I want to cut it into pieces of different sizes suppose 700,500,250 and 380. And I want pieces example

700(mm) * 4 pieces
500(mm) * 3 pieces
250(mm) * 4 pieces
320(mm) * 5 pieces

To cut this efficiently by minimizing the waste, here is the code.

Java Code

import java.util.Map;
import java.util.Map.Entry;
import org.optimization.CuttingStock;

public class MainClass {

	public static void main(String[] args) {

		int blocks[]={700,500,250,380};
		int quantities[]={4,3,6,5};
		int i=0,max_size=2000;
		Map<Integer, Integer> map;
	    CuttingStock cuttingStock= new CuttingStock(max_size,blocks,quantities);
		while(cuttingStock.hasMoreCombinations())
		{
			System.out.println("\nCombination no "+(++i));
			map=cuttingStock.nextCombination();
			for (Entry<Integer, Integer> entry : map.entrySet()) 
			{
				  Integer key = entry.getKey();
				  Integer value = entry.getValue();
				  System.out.println(key+"  *  "+value);
			}
		}
	}
}

Output will be

Combination no 1
250  *  6
500  *  1

Combination no 2
700  *  1
500  *  1
380  *  2

Combination no 3
700  *  1
500  *  1
380  *  2

Combination no 4
700  *  2
380  *  1

cutting-stock-java's People

Contributors

gaurav2493 avatar

Watchers

Edgar Elias Peña De La Torre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.