Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Linear Programming

Author  Topic 

WoodHouse
Posting Yak Master

211 Posts

Posted - 2009-08-31 : 11:34:20
Hi Guys

I need to create Linear Programming in SQL SERVER 2005
Any links please provide me. Are some one has done please share to me.

Equation like this
5x+4y<=10
3x-y<=15

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-31 : 13:36:42
You mean you want to solve for X and Y given those two expressions using t-sql ?

Be One with the Optimizer
TG
Go to Top of Page

WoodHouse
Posting Yak Master

211 Posts

Posted - 2009-09-01 : 00:10:17
Hi

Yes i need to solve X and Y
5x+4y<=10
3x-y<=15

For example i took above equation

5x+4y<=10
3x-y<=15
s1+s2-s3=0

for above problem we need to find X & Y
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-01 : 00:44:58
SQL is not the language for that. It's a data manipulation and retrieval language, not for general-purpose programming or symbolic mathematics.

BTW, you cannot solve the equations containing <= as an operator, the number of solutions is infinite.
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2009-09-01 : 01:08:49
be patient - Peso will come along any minute now with an SVD algorithm in t-sql


elsasoft.org
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-09-01 : 10:41:13
quote:
Originally posted by robvolk
BTW, you cannot solve the equations containing <= as an operator, the number of solutions is infinite.


Linear programming is a method of finding optimal solutions using graphs of areas under a curve. It does include the use of inequalities.
http://en.wikipedia.org/wiki/Linear_programming

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-09-01 : 11:09:29
Do you have a distinct range of limits and are you talking about INTEGERS only?

If so does this work?

-- Need a table of Numbers
IF OBJECT_ID('dbo.F_TABLE_NUMBER_RANGE') IS NOT NULL DROP FUNCTION dbo.F_TABLE_NUMBER_RANGE

GO
CREATE FUNCTION dbo.F_TABLE_NUMBER_RANGE
(
@startNumber INT
, @endNumber INT
)
RETURNS TABLE AS RETURN
(
WITH powers AS (
SELECT
[N01], [N02], [N03]
FROM
(
SELECT [N01] = 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3
UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7
UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11
UNION SELECT 12 UNION SELECT 13 UNION SELECT 14 UNION SELECT 15
) NO1

CROSS JOIN (
SELECT [N02] = 0 UNION SELECT 16 UNION SELECT 32 UNION SELECT 48
UNION SELECT 64 UNION SELECT 80 UNION SELECT 96 UNION SELECT 112
UNION SELECT 128 UNION SELECT 144 UNION SELECT 160 UNION SELECT 176
UNION SELECT 192 UNION SELECT 208 UNION SELECT 224 UNION SELECT 240
) NO2

CROSS JOIN (
SELECT [N03] = 0 UNION SELECT 256 UNION SELECT 512 UNION SELECT 768
UNION SELECT 1024 UNION SELECT 1280 UNION SELECT 1536 UNION SELECT 1792
UNION SELECT 2048 UNION SELECT 2304 UNION SELECT 2560 UNION SELECT 2816
UNION SELECT 3072 UNION SELECT 3328 UNION SELECT 3584 UNION SELECT 3840
) N03
)
SELECT TOP 100 PERCENT
[number] = ( a.[number] + b.[number] ) + CASE WHEN @startNumber <= @endNumber THEN @startNumber ELSE @endNumber END
FROM
(
SELECT TOP 100 PERCENT
[number] = CAST([N01] + [N02] + [N03] AS INT)
FROM
powers
WHERE
[N01] + [N02] + [N03] < CAST(CEILING(SQRT(ABS(@startNumber - @endNumber) + 1 )) AS INT)
ORDER BY
1
) a
CROSS JOIN (
SELECT TOP 100 PERCENT
[number] = CAST(([N01] + [N02] + [N03]) * CAST(CEILING(SQRT(ABS(@startNumber - @endNumber) + 1 )) AS INT) AS INT)
FROM
powers
WHERE
[N01] + [N02] + [N03] < CAST(CEILING(SQRT(ABS(@startNumber - @endNumber) + 1 )) AS INT)
ORDER BY
1
) b
WHERE
a.[number] + b.[number] < ABS(@startNumber - @endNumber) + 1
AND (16777216 - ABS( @startNumber - @endNumber ) - 1 ) > 0
ORDER BY
1
)
GO


/*
Yes i need to solve X and Y
5x+4y<=10
3x-y<=15

For example i took above equation

5x+4y<=10
3x-y<=15
s1+s2-s3=0

for above problem we need to find X & Y
Edited by - WoodHouse on 09/01/2009 05:44:15
*/


IF OBJECT_ID('tempdb..#matrixX') IS NOT NULL DROP TABLE #matrixX
IF OBJECT_ID('tempdb..#matrixY') IS NOT NULL DROP TABLE #matrixY

CREATE TABLE #matrixX ([x] INT PRIMARY KEY)
CREATE TABLE #matrixY ([y] INT PRIMARY KEY)

-- populate matrices
INSERT #matrixX
SELECT
[number]
FROM
dbo.F_TABLE_NUMBER_RANGE (0, 1000)

INSERT #matrixY SELECT [x] FROM #matrixX


-- Calculations
DECLARE @limit INT
DECLARE @floor INT


-- 5x + 4Y <= 10
SET @limit = 10
SET @floor = 0
SELECT
mx.[x]
, my.[y]
FROM
#matrixX mx
CROSS JOIN #matrixY my
WHERE
5 * mx.[x] + 4 * my.[y] BETWEEN @floor AND @limit

-- 3x-y<=15
SET @limit = 15
SET @floor = 0
SELECT
mx.[x]
, my.[y]
FROM
#matrixX mx
CROSS JOIN #matrixY my
WHERE
3 * mx.[x] - my.[y] BETWEEN @floor AND @limit



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-01 : 11:59:48
quote:
Linear programming is a method of finding optimal solutions using graphs of areas under a curve. It does include the use of inequalities.
http://en.wikipedia.org/wiki/Linear_programming
I'm a dummy, I'm thinking of linear algebra. Thanks.
Go to Top of Page
   

- Advertisement -