sql/PLSQL algorithm: is a rectangle filled with the other rectangles
HelloI have 2 tables: T1 and T2:
with T1 as
(select 2 FromPeriod, 4 ToPeriod, 10 FromSum, 12 ToSum from dual)
select * from t1;
with T2 as
(select 1 FromPeriod, 2 ToPeriod, 9 FromSum, 5 ToSum from dual
union all
select 1 FromPeriod, 3 ToPeriod, 9 FromSum, 4 ToSum from dual
union all
select 2 FromPeriod, 5 ToPeriod, 9 FromSum, 11 ToSum from dual
union all
select 2 FromPeriod, 5 ToPeriod, 11 FromSum, 12 ToSum from dual)
select * from t2;
FromPeriod, ToPeriod are positive whole number without decimal point.FromSum, ToSum are positive numbers can have the comma.
Table T1 contains unique in the columns 'FromPeriod-ToPeriod' points, that means that is there is a record where "FromPeriod-ToPeriod" = [2-4], then it is certainly not rendered as "FromPeriod-ToPeriod" = [1-4] keys wich [2-4] period, such a thing is not possible in table P1, it contains only unique periods that do not touch. Then the records with periods [2-4], [5-6] are ok in there.
But table T2 allows periods affecting somehow. You can see that T2 contains "FromPeriod-ToPeriod" = [1-2] and also [1-3] that touch each other.
We can look at the two tables T1 and T2 as rectangles where X - axis is the values of the axes and the "FromPeriod-ToPeriod" is [FromSum, ToSum].
I need sql/plsql algorithm that returns true if the rectangle of table T1 is discovered/filled with rectangles in table T2. If the rectangle in T1 is completely filled or even more filled than necessary, then algorithm should return true. If even a small neighborhood in rectangle T1 is not filled by rectangles in T2, then the algorithm must return false.
As see you in the sample data, T1 has a rectangle: [2-4; 10-12] T2 contains 4 mentions that fill/overdraw this area defined by T1. So for the moment the algorithm must return true.
I do not know how to write effective elsewhere such algorithm, can you help me?
--
At the moment I only came with such algorithm/query:
Test1: this test should return true:
--query: is rectangle [2-4;10-12] filled? -Yes.
with T2 as
(select 1 FromPeriod, 2 ToPeriod, 9 FromSum, 5 ToSum from dual
union all
select 1 FromPeriod, 3 ToPeriod, 9 FromSum, 4 ToSum from dual
union all
select 2 FromPeriod, 5 ToPeriod, 9 FromSum, 11 ToSum from dual
union all
select 2 FromPeriod, 5 ToPeriod, 11 FromSum, 12 ToSum from dual)
select * from t2
where (2 <= ToPeriod and 4 >= FromPeriod) -- x-axes overlapping
and (10 <= ToSum and 12 >= FromSum)--y-axes overlapping
;--2 rows
--
2 5 9 11
2 5 11 12
I takes as input the T1 table horizontal axes (2, [4]) and research data table T2 that affect this horizontal axes, also the value axes is compared. But how then? There are 2 files, but it can give 10 stores overlap in the periods and amounts. How to determine now that rectange T1 is filled?Test2: This case should return false:
--query: is rectangle [2-4;10-12] filled? -No.
with T2 as
(select 1 FromPeriod, 2 ToPeriod, 9 FromSum, 4 ToSum from dual
union all
select 1 FromPeriod, 3 ToPeriod, 9 FromSum, 4 ToSum from dual
union all
select 2 FromPeriod, 4 ToPeriod, 9 FromSum, 11 ToSum from dual
union all
select 2 FromPeriod, 5 ToPeriod, 13 FromSum, 13 ToSum from dual)
select * from t2
where (2 <= ToPeriod and 4 >= FromPeriod) -- x-axes overlapping
and (10 <= ToSum and 12 >= FromSum)--y-axes overlapping
;--1 row.
2 4 9 11
Charles,
I see 2 choices, but none is likely to evolve very well. The first can be with SQL - subdivision T1 into unit squares and see if everything not covered by T2:
with T1 as
(select 2 FromPeriod, 4 ToPeriod, 10.1 FromSum, 12 ToSum from dual)
, T1X as
(select (FromPeriod+level)-1 as Period from T1 connect by level <= (ToPeriod-FromPeriod)+1)
, T1Y as
(select (FromSum+level*.01)-.01 as Summ from T1 connect by level <= (ToSum-FromSum+.01)/.01)
, T1XY as (select Period,Summ from T1X,T1Y)
,T2 as
(select 1 FromPeriod, 2 ToPeriod, 9.99 FromSum, 10.1 ToSum from dual--satisfies sub-region [(2,2);(10.1,10.1)]
union all
select 1 FromPeriod, 2 ToPeriod, 9.99 FromSum, 10.11 ToSum from dual--now satisfied sub-regions: [(2,2);(10.1,10.11)
union all
select 2 FromPeriod, 2 ToPeriod, 10 FromSum, 12.01 ToSum from dual--now satisfied sub-regions: [(2,2);(10.1,12)
union all
select 3 FromPeriod, 4 ToPeriod, 10 FromSum, 11.99 ToSum from dual--now satisfied sub-regions: [(2,2);(10.1,12)],[(3,4);(10,11.99)]
union all
select 4 FromPeriod, 4 ToPeriod, 10 FromSum, 13 ToSum from dual--now satisfied sub-regions: all filled, return true
)
select Period,Summ from T1XY
where not exists (
select 1
from T2
where T2.FromPeriod<=T1XY.Period
and T2.ToPeriod>=T1XY.Period
and T2.FromSum<=T1XY.Summ
and T2.ToSum>=T1XY.Summ
)
;
The second option is more inspiring you described, using a recursive algorithm to subdivide the T1 into small rectangles for each rectangle in T2. For example:
X(1)={[a,b;c,d]}
Y={[e,f;g,h];[i,j;k,l]}
X(2)={[a,e;c,g];[e,f;c,g];[f,b;c,g];[a,e;g,h];[f,b;g,h];[a,e;h,d];[e,f;h,d];[f,b;h,d]}
or
X(2)={[a,b;c,g];[a,b;h,d];[a,e;c,d];[f,b;c,d]} -- this gives some overlap, but fewer rectangles and the algorithm still works.
You would have to refine it to handle partial overlaps correctly, then drop areas that don't have a positive area. If
X(2) becomes empty then it is fully covered. It might be most efficient to sort T2 in order of descending area.
Kind regards
Bob
Tags: Database
Similar Questions
-
I have a request for a phone number in my HTML code in my database which is automatically filled with the correct sales phone number when sending emails. I create HTML code in dreamweaver and then put the code in my e-mail program. I need to make the phone number in the clickable query. I know the code to do it well not in a query. What is the code?
As far as I saw, most of the smartphones will automatically recognize it these days, as long as the number is written in a format of regular phone number. This format also allows to make images or text other than a telephone number in a tap to call the link.
Looking at what you have presented I guess it would be something along the lines of...
When the location of the link and the link text would be the same variable.
I've never worked with Intelliclick so above is a wild guess. They would be those who need to ask themselves if there is a way to fill in the address of a link like that.
-
Keyboard shortcut for fill with the color layer are opposed on my PS CS6 OSX install help?
Hi all
I'm kinda a noob and following a tutorial... and found something strange and I wonder if you could help me understand what is happening.
I have Photoshop CS6 extended on a macbook pro (late 2011).
I am running OSX v 10.7.5
I'm the long and the instructor has added a new layer. I did it.
He then filled the white layer which is its background color (it has foreground black, white background). I have same evidence / background colors.
Now I thought on mac to fill with the foreground color, you hit Apple + Delete and to fill it with the background, press Option + delete
It's the exact OPPOSITE for me. I hit Apple + DELETE (or even BACKSPACE) and filled it with my background color, which is white
If I hit Option + DELETE (or RET.), filled it with my foreground color.
I tried searching in the area of keyboard shortcuts change... but I do not see these settings anywhere.
I have an external keyboard plugged into my mac. It is a 3rd party one, but seems otherwise never function normally.
Keyboard here is: http://pckeyboard.com/page/UKBD/UB40P4A
Any suggestions why my shortcut keyboard for a fill with the color layer could be reversed?
Thanks in advance,
CC
Looks like it doesn't work as expected
keyboard shortcuts in Photoshop to paintng:
https://helpx.Adobe.com/Photoshop/using/default-keyboard-shortcuts.html#keys_for_painting
-
Pencil of Apple works with the other iPads, or iPad pro?
Pencil DDoes Apple works with the other iPads, or iPad pro?
It works with the Pro
-
all my data records on the local disk c, how to share the data with the other drive, local drive d.
Hi Jasonbichard,
1. what type of drive is D? Is - this another partition on the same disk?
2 Windows operating system you are using?
You can change the location of the disk to save the data in the d: instead of C: and check if it helps.
a. navigate to the location (username) C:\Users\.
b. right click on the folder that you want to change the location, and then select Properties.
c. click on the location tab and change the location to D: drive.d. click on apply and Ok.
-
How can I share 'My images' with the other user accounts on my computer?
How can I share 'My images' with the other user accounts on my computer?
where are the 'experts' on these forums adverstised? I can't get an answer to a simple question. Does anyone know how to do this?
Here we are, ok, I'm not an expert, but try this:
Right click on 'My images' > share > specific people... > select that you want to share this folder with.
...
After that, try to connect by using a different account. If you will not be able to open C:\Users\"FirstUser"\Pictures, you try to extend the network in the left pane of Windows Explorer > expand ComputerName > expand users > expand "FirstUser" > photos
-
When I click with the left button of the mouse on the unique tool, open the window with the other instruments
Mohito Hi, this morning, I solved the problem by trying to support. I realized that the problem was in mice, because the click rate is at its highest level, and then click the instruments was like if he did 2. I will now set the minimum speed of the clicks.
Thank you
-
my up to date iMac can't read installing lightroom 5 dvd I received for Christmas, the dvd player works fine with the other dvd, is it possible to download the program with the serial number of the dvd?
No need to worry about the disk version. He would just install an update anyway once it has been installed. Download from the link provided below and use the serial number, you need to activate.
-
My Android screen is filled with the Oracle Logo
Hello, I had two problems to solve
First: I am new to use jdeveloper 12 c to develop Mobile.after ADF oracle Jdeveloper 12 c 64-bit of downloading. I deal with my system of window currently I am going through an oracle tutorial. When I try to test some of the samples in the tutorial, after deployment, the screen of my android emulator will be filled with oracle logo.what is the problem? I need help
Second: I'm going through this demo on this site:
http://docs.Oracle.com/CD/E53569_01/tutorials/tut_jdev_maf_app/tut_jdev_maf_app.html .
I followed the procedure also exactly as it is.but I reviece this error on my 12 c Jdeveloper,error:
[17: 57:57] application signing...
[17: 57:57] run command line: ["C:\Oracle\Middleware\Oracle_Home\oracle_common\jdk\bin\jarsigner" - keystore, "C:\Program Files\Java\jdk1.7.0_11\bin\Omile.keystore", - storepass, - keypass, madu123, madu123 - digestalg, SHA1 - sigalg MD5withRSA, "C:\JDeveloper\mywork\Employees\deploy\Omile\Employees.apk", Omile]
[17: 57:57] jarsigner: certificate chain could not be found for: Omile. Omile must refer to a valid key KeyStore entry containing a private key certificates chain and corresponding public key.
[17: 57:57] command-line execution failed (return code: 1).
[17: 57:57] run command line: "C:\Oracle\Middleware\Oracle_Home\oracle_common\jdk\bin\jarsigner" - keystore "C:\Program Files\Java\jdk1.7.0_11\bin\Omile.keystore" - storepass madu123 - keypass madu123 - digestalg SHA1 - sigalg MD5withRSA "C:\JDeveloper\mywork\Employees\deploy\Omile\Employees.apk' Omile
[17: 57:57] undeployment.
[17: 57:57] - incomplete deployment.
[17: 57:57] deployment failed due to one or more errors returned by "C:\Oracle\Middleware\Oracle_Home\oracle_common\jdk\bin\jarsigner". What follows is a summary of the returned error:
Command-line execution failed (return code: 1).
Thanks for your help
To the first question, you can check in point 3 in the following blog:
-
Fill with the previous 'not null' value ' Null' known values
Hi all
I have the following requirement to fill in missing values (null values) with the "Not null" values known previously available.
Source of the example:
Emp_Id Start_Dt LOC Comm Grade A101
01/01/2013
NJ 4000 B A101
15/03/2013
CA 4800 A101
15/05/2013
3500 C A101
25/07/2013
2500 A101
20/12/2013
NY 5800 A A101
14/02/2013
5000 A101
20/05/2014
DC 6000 A A101
03/06/2014
3600 C A102
24/05/2013
THE 5000 A A102
15/12/2013 4300 Expected results values in columns LOC and grades:
Emp_Id Start_Dt LOC Comm Grade A101 01/01/2013
NJ 4000 B A101 15/03/2013
CA 4800 B A101 15/05/2013
CA 3500 C A101 25/07/2013
CA 2500 C A101 20/12/2013
NY 5800 A A101 14/02/2013
NY 5000 A A101 20/05/2014
DC 6000 A A101 03/06/2014
DC 3600 C A102 24/05/2013
THE 5000 A A102 15/12/2013
THE 4300 A Any suggestions would be helpful.
Kind regards
Arun
Also, I think that this is a case of analytics. Last_value is perhaps the most appropriate function for the given task:
Select emp_id
start_dt
last_value(loc ignore nulls) over (partition by emp_id arrested by start_dt) loc
comm
last_value(grade ignore nulls) about category (partition by emp_id arrested by start_dt)
t
-
Passes instead of filling with the form in the Adobe capture
Hello! I was wondering if its settings that makes it possible to use the race instead of fill when I m a draw with the shape tool?
Hi Marte,
At the moment there is no way to customize the form capture settings. There, however, we often get a request, so I will definitely pass your along to the team.
Sue.
-
Object drawn with a pencil will not fill with the paint bucket tool
I draw an object using the pencil tool in Flash CS5. Since I use several traces I connect them all by clicking on Edit, combine objects then Union combining the traits in a single object. But when I try to fill it with the color that it doesn't work. Even if I make sure there is no gap. A few small areas that are closed in the fill of the object with the color, but do not know why the rest of the object refuses to be filled with color.
I fiddled around and switch between the object drawing Mode and drawing Mode, but that doesn't work anymore. Usually when I use the Brush tool I have no problem filling the object with colors. But for some reason, I can't when I use the pencil tool! Help, please!
OK, think about it. If you select your character and in the properties to ask him to be 3000 wide, then zoom in to just behind his ears, you'll see a gap. There is another gap directly in front of the ears.
The thing filling gaps that Chris mentioned does not immediately work, because your lines are still in odd drawing object, the union did you yet left the tiny holes. You can exit this mode by a Break Apart and select all. Areas with gaps fill again right away, but the small fill openings feature will work. The option size of gap is in the tools downwards when the paint bucket is selected.
I'm going to insert an image, which shows the great super version, where you can see two gaps, and you can see how the right box is filled, even if there is a gap.
-
Paint Bucket tool is not filling with the selected color version instead faded to
I use photoshop for a long time and never had this problem with the bucket of pain tool. It's very frustrating. I want to just use it as usual, when I select a color and filled color faded version instead.
Worse comes to worse, right-click on its ' Options Bar icon and Reset it.
-
Require the field be filled when the other field values change
I tried to search on something I have to do but couldn't come up with a combination of words to find many.
I have a situation where, when some field on a form, the values change, I need a comment filled field. So if changing values of designated field and the comment field is NOT filled in, I'd like some sort of message indicating that the comment field must be filled in when this field is changed. Preferably, this would happen when the "Update" button is pushed on the form. And this should occur before the data is sent.
This seems to be between validation and dynamic Action. I don't know how to create what I need. Any help would be greatly appreciated! I hope I described the scenario quite well.
Thank you!
JohnCreate an item hidden on the form, create a dynamic action to fill this article on the change of your required items. create a validation on the comments that will be triggered ONLY if the hidden item is filled through the action of the element changed...
Thank you
Tony Miller
Dallas, TX -
Fill in the other fields of drop-down Menus
I'm trying to create a PDF file in which when an item is selected in a drop-down list, another field is given a specific value.
Exact situation: I have created a photography print order form and there is a drop down menu to select the size of the print on the agenda (example: 4 x 6, 5 x 7, etc..) I want to set so that when a person chooses a certain size, say that 4 x 6, the "Unit price" field is automatically filled in with the price for 4 x 6.
Is it possible to do so. I have decent programming skills, so I am open to any beginner or expert suggestions.
Thank you!
Chris
Set the value to export for each option in the drop down for the price, then
apply this value in the fields where you want to display the price (for
example, you can type name of the drop-down field of simple calculation).
Maybe you are looking for
-
PDM file as a .wav file
Hello I want to do a triggered acquisition of dynamic power spectrum and save it to a TDMS file. (XP pro, Labview 8.5, 5600 PXI and PXI-5620) And then, when I read it, I'll have the same dynamic power spectrum. My problem is that my "reading signal"
-
What should I do to get it working again?
-
Pop photo gallery - up continues to ask for a CD I've ever had?
Why I get a pop up saying that I am using Photo Gallery, when I'm not and then ask for a CD that I've ever had? It became a big nuisance! How can I get rid of this pop up? E-mail address is removed from the privacy *.
-
Wireless Zero Configuration of the difficulties
I recently had a new motherboard installed in my laptop - since then I am unable to connect to my wireless network automatically. Whenever I want to, so I have to go through the following procedure: go to administration tools; then services; then wi
-
RUNNING WINDOWS XPUSING MICROSOFT OUTLOOK